Hi and thank you for your time. I´ve been trying to create a wordpress plugin for a project that i'm working on. it consist in a search form for cars make/model/year. The issue i'm having is with the XML data query to populate the option on the make and model selects. This is my code so far:
EDIT: I got the data from the XML, just updated my code now what im missing is the conditional argument which is not working. I arked it in the code
<?php
/*
Plugin Name: Busqueda Rapida
Plugin URI:
Description: Plugin de busqueda rapida
Version: 1.0
Author:
Author URI:
*/
define( 'CD_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'CD_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
function html_form_code() {
$path = CD_PLUGIN_PATH . 'marcamodelo.xml';
$doc = simplexml_load_file($path);
echo '<div class="buswrap"> ';
echo '<form id="buscaForm" method="POST" action="">';
echo '<fieldset>';
echo '<select id="marca" name="marca" class="select">';
foreach($doc->marca as $marca)
{
$selected = '';
if ($marca['name'] == **WHAT GOES HERE?** ) { // This is the conditional statement that doesn't work
$selected = ' selected ';
}
echo "<option value='".$marca['name']."' $selected>".$marca['name']."</option>";
}
echo '</select>';
echo '<select id="modelo" name="modelo" class="select">';
// Code to get model goes here
echo '</select>';
echo '<select id="year" name="year" class="select">';
for($i = 1950; $i < date("Y")+2; $i++){
echo '<option value="'.$i.'">'.$i.'</option>';
}
echo '</select>';
echo '</fieldset>';
echo '<input type="submit" value="Buscar" id="search-bt" class="button">';
echo '</form>';
echo '</div>';
}
function generate_url() {
if(isset($_POST['marca'], $_POST['modelo'], $_POST['year'])) {
// gather all the values
$marca = urlencode($_POST['marca']);
$modelo = urlencode($_POST['modelo']);
$year = $_POST['year'];
// make a header redirect
header("Location: http://www.exampledomain.com/$marca/$modelo/$year");
exit;
}
}
function garaje_busqueda_rapida_shortcode() {
ob_start();
generate_url();
html_form_code();
return ob_get_clean();
}
add_shortcode( 'buscador-garaje', 'garaje_busqueda_rapida_shortcode' );
?>
What am i missing here? Can anyone point me to the right direction please? thanks a lot in advance!