Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Dynamic Drop Down List into Hard coded one

Status
Not open for further replies.

leeboycymru

Programmer
Jan 23, 2007
185
GB
I am workign in zen ecommerce and I am having difficulty getting some help in the forums there, fo my problem.

I have a drop down list that is filled dynamically with countries. Basically in this one part all I need is 13 countries which i have a list for.

Below is the code that ultimately displays the list:

Code:
<?php if ($current_page_base == checkout_shipping_address) { ?>
<label class="inputLabel" for="country"><?php echo ENTRY_COUNTRY; ?></label>
<?php echo zen_get_country_list_via('zone_country_id', $selected_country, 'id="country" ' . ($flag_show_pulldown_states == true ? 'onchange="update_zone(this.form);"' : '')) . (zen_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="alert">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?>
<?php
}
?>
It uses the function below to pull the countries in:

Code:
function zen_get_country_list($name, $selected = '', $parameters = '') {
    $countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));
    $countries = zen_get_countries();

    for ($i=0, $n=sizeof($countries); $i<$n; $i++) {
      $countries_array[] = array('id' => $countries[$i]['countries_id'], 'text' => $countries[$i]['countries_name']);
    }

    return zen_draw_pull_down_menu($name, $countries_array, $selected, $parameters);
  }

What I need to do is somehting liek this:

Code:
function zen_get_country_list_via($name, $selected = '', $parameters = '') { 
	?>
<select>
	<option>Please select a country</option>
	<option>UK</option>
</select>
<?
  }
?>

Which does work as it displays, but it doesnt have all the php with it to allow it to work, because when I choose a country and click submit, it doesnt recognise a country has been selected, and creates an error.
I know its big ask, but can anybode see how I can get this working by reading how the php is working, so I can get the drop down list working.

Thanks in advance

Lee
 
The best way to do this in my opinion is to simply cut and paste the generated HTML from the page. Go to the page as it is running now, and do a "View->Source" then look for the HTML that starts with "<SELECT>" and it filled with the country list in the format "<OPTION ID="1">UK</OPTION>". Cut and past that over the php that generates the drop down and remove the countries you don't need. The reason that the code isn't working as you have stated in your second example is because the drop down is sending an ID to the receiving page which is declared in the <option> tag, by copying and pasting the generated code you'll be using the right ID for each country.

-Geeeeeeeeeeeeeeeeeeeeeeee-
 
Absolutely top notch thinking, thanks for that, and worked a treat.

Nice one Geee, this forum is easily the best out there.

Ive been on that for days!

Lee
 
Not a problem at all.

-Geeeeeeeeeeeeeeeeeeeeeeee-
 
You could also edit the function zen_draw_pull_down_menu so it creates a proper drop down list.
Or better still, use it as the basis for your own function and use ZenCart's template over-ride system. This way won't break your site when you update the ZenCart core.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Hi Foamcow, thats pretty much what I was trying to do before I thought about going down this route, but failed. I did give it a go but just couldnt get my head around it, and as Im under time constraints i went for the option above to at least get it working, so as it is now, and they pleased with it, they wont know if i then change it to your suggestion, but i do need help with it thats for sure.

Thanks

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top