Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How to create a drop down selection menu


spooks

Recommended Posts

  • 5 months later...
  • Replies 75
  • Created
  • Last Reply
  • 2 months later...

Nice tut, been hungup for hours on this thing any help be greatly appreciated.

 

So, I cant seem to get this damn drop down menu to pass the values to the intended table field.

 

My store services only a select few zip codes locally. Because most people dont like reading I have a lot of signups for out of area customers who then get upset when they order because "my site let them order" and have to call and refund them.

 

So I figure, I'll build a table "zipcodes" populate it with "zipcodes_id, zipcodes_number, status" fields. Set all statuses to (1) for active and not set a key. I assume i can reassign the variables in create_account.php to make this task even as troubless as possible. Well, not so easy so thanks for this spook, very helpful and educational. I understand every scenario is different but I'm assuming this is a typical osC drop_down_menu so the steps should be relatively the same. This form is also part of the create_account.php so I'm assuming i deleted the form properties correctley.

 

So I build my array,

//postalcode drop-down
 $zipcodes_array = array();
 $zipcodes_array[0] = array('id' => '0', 'text' => 'Please Select');
  $zipcodes_query = tep_db_query("select zipcodes_id, zipcodes_number from " . TABLE_ZIPCODES . " where status= 1");

	while ($zipcodes_values = tep_db_fetch_array($zipcodes_query)) {
	$zipcodes_array[] = array('id' => $zipcodes_values['zipcodes_id'], 'text' => $zipcodes_values['zipcodes_number']);
	   }
?>
		 <tr>
			   <td class="main"><?php echo ENTRY_POST_CODE; ?></td>
			   <td class="main"><?php echo tep_draw_form('postcodes', tep_href_link('create_account.php', 'action=select'), 'get') .
tep_draw_pull_down_menu('zipcodes_numbers', $zipcodes_array, $selected_zip, 'onchange="select();" rel="nofollow"') . ' ' . (tep_not_null(ENTRY_POST_CODE_TEXT) ? '<span class="inputRequirement">' . ENTRY_POST_CODE_TEXT . '</span>': ''); ?></td>

The array renders ok, with this code, just as desired. But any selections that are made and submitted are not passed into any database tables or fields. What I'm trying to get is the "text" value inserted into the postcode field of address_book and not necessarily the zipcode_id

 

So I implement what I think is correct,

$selected_zip = tep_db_prepare_input($HTTP_POST_VARS['postcode']);
		$selected_zip = ($_GET['select_zipcodes'] > 0 ? $_GET['select_zipcodes'] : true);

Im translating this as the variable $selected_zip which i believe i have assigned in my array is going to be placed into the postcode field in the adress_book table after it $GET's the selected zipcodes either A. Id or B.Text value. Either one would be informitive at this point...

 

After implementation of this It will pass a value of 1 through to the postcode field despite which of my 32 options i picked, :unsure:

 

I have also changed,

 $customer_id = tep_db_insert_id();

  $sql_data_array = array('customers_id' => $customer_id,
						  'entry_firstname' => $firstname,
						  'entry_lastname' => $lastname,
						  'entry_street_address' => $street_address,
						  'entry_postcode' => $selected_zip,
						  'entry_city' => $city,
						  'entry_country_id' => $country);

 

It was throwing the Zipcode must contain * characters on submit, so I ignored that and the form submits, just dosnt pass along. I've learned so much playing with this menu, but I'm tapped out if anyone can offer some assistance or direction please do.

Link to comment
Share on other sites

I see a number of issues, but to answer your last, yes the pull down must be part of a form & the form MUST be closed (with </form>)

 

You seem to be confusing $_POST & $_GET

 

If the form method is GET then only $_GET vars are set, there will be no $_POST vars

 

If the form method is POST then $_POST vars will be set but some $_GET vars can also be set via the uri used in the form link, i.e. you have

tep_href_link('create_account.php', 'action=select'

 

the action=select is part of the uri so is a $_GET var

 

Next problem, you have named your select field zipcodes_numbers but you trying to retrieve the data by referring to select_zipcodes

 

you must be consistent or things will not work

 

Some other points:

 

you've named your form postcodes that's fine as long as no other form with that name exists on the page, you do not need to refer to the form name at all when retrieving data.

 

your using $HTTP_POST_VARS which is depreciated always use $_POST and again be consistent, it is possible that $HTTP_POST_VARS & $_POST contain different data

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

Thanks for taking the time to help spooks. It's much appreciated, I'm still pretty green to the concepts involved with PHP & $GET & $POST methods. The concept and rules involved with php seem to be above my grasp. I foudn it easier to go ahead and implement your hard coded method, wich seems to accomplish my job relatively easily considering i only have 32 zip codes to worry about. I figure it will be just as easy to update the hard coded zipcodes, as it would be to add a new row into the database.

 

You mentioned use $POST instead of $HTTP_POST_VARS, through out all my readings I have never stumbled across this recommendation ... It seems my entire site uses this syntax, would you recommend a site wide find & replace of all $HTTP_POST_VARS to $POST???

Link to comment
Share on other sites

@@breakbred101

 

Yes I am surprised to see that even in 2.3.x the depreciated vars appear even though they have long been so (since php 4.1) http://www.abdn.ac.uk/local/php/doc/reserved.variables.post.html

 

osC get around this issue with compatibility.php which references $HTTP_POST_VARS to $_POST and so on.

 

My advise, whenever you come to edit a page make it a practice to replace all the depreciated vars, it saves work with issues that may arise as php upgrades

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

  • 2 weeks later...

How about if I want to change a drop down menu into a list with scroll bar, is it possible? What call function can I use?

Find this post helpful? Click the 'Like this' button. :)

Link to comment
Share on other sites

@@al3ks

 

You would not need any function, just create a series of links on separate lines within a limited height div and adjust your css

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

  • 1 month later...

Hi Sam, first thanks for all your contributions and support. I have tried to implement the pull down in admin/banner_manager.php, like so:

 

	  <tr>
	    <td class="main" valign="top"><?php echo TEXT_BANNERS_IMAGE; ?> </td>
	    <td class="main"><?php echo tep_draw_file_field('banners_image') . TEXT_BANNERS_IMAGE_LOCAL . DIR_FS_CATALOG_IMAGES . tep_draw_input_field('banners_image_local', (isset($bInfo->banners_image) ? $bInfo->banners_image : ''),'size="24" maxlength="32"'); ?></td>
	  </tr>
	  <tr>
<?php
//Thus
 $banner_images_array = array();
 $banner_images_array[0] = array('id' => '0', 'text' => 'Please Select');
 $banner_images_query = tep_db_query("select banners_id, banners_image from " . TABLE_BANNERS . " order by banners_group");
 while ($banner_images_values = tep_db_fetch_array($banner_images_query)) {
    $banner_images_array[] = array('id' => $banner_images_values['banners_id'], 'text' => $banner_images_values['banners_image']);
 }
?>
<td colspan="2">
<?php tep_draw_pull_down_menu('select_image', $banner_images_array, $selected_image);
//Finally you must process the data at the receiving page, IE
$selected_image = ($_GET['select_image'] > 0 ? $_GET['select_image'] : false);
echo 'Did not work';
?>
</td>
	  </tr>

 

With the purpose to remove the need to type in the image name. That is replace this line:

 

	    <td class="main"><?php echo tep_draw_file_field('banners_image') . TEXT_BANNERS_IMAGE_LOCAL . DIR_FS_CATALOG_IMAGES . tep_draw_input_field('banners_image_local', (isset($bInfo->banners_image) ? $bInfo->banners_image : ''),'size="24" maxlength="32"'); ?></td>

 

No succes so far. What am I doing wrong?

 

Sara

Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...

$HTTP_POST_VARS is deprecated, but there is compatibility code in osCommerce to make it function. You can change it to $_POST if you want, but it shouldn't make any difference.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

ok thanks, so that means it cannot be that which is causing this code not to work then.

 

im getting stuck on this code, i do not understand why the page URL is not being passed through the form??

 

tep_href_link(basename($PHP_SELF)

 

if i view the HTML source of this form, i can clearly see the full URL for the "action" option. But when the dropdown is selected, it just goes to the index.php page without the cpath after it. what could be preventing the cpath not to go through?

 

// Show Drop down menu in split_page_link :
// (You can move this part where ever you inside $display_links_string ) here it's a the very begining.
 $display_links_string .= tep_draw_form('prod_per_page', tep_href_link(basename($PHP_SELF), $parameters), 'get'). tep_draw_pull_down_menu('ppp', $ppp_list, $products_per_search_page, 'class="smallText" onchange="this.form.submit()"') ;
 $ignore = array('page', 'ppp');
 if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) {
   reset($HTTP_GET_VARS);
   while (list($key, $value) = each($HTTP_GET_VARS)) {
  if ( (strlen($value) > 0) && ($key != tep_session_name()) && (!in_array($key, $ignore)) ) {
    $display_links_string .= tep_draw_hidden_field($key, $value);
  }
   }
 }
    $display_links_string .= tep_hide_session_id() . '</form>';

  }

Link to comment
Share on other sites

this code is in split_page_results.php

 

i used this plugin here

 

http://addons.oscommerce.com/info/7219

 

the form is actually showing the cpath, but when it submits, it doesn't pass it through.

 

unless there is something to do with wamp settings?

 

so like my page is this URL: http://localhost/testsite/index.php?cPath=3&sort=0d&page=2

 

if i select the dropdown which allows you to select how many products to view, say i choose 20, then the form automatically submits.

 

and I should b getting this URL here: http://localhost/testsite/index.php?cPath=3&sort=0d&page=2&ppp=20

 

but at the moment i only get this: http://localhost/testsite/index.php?&ppp=20

 

 

It doesn't seem to want to submit the entire URL path.

 

It should work, because I got an example from someone else and they said it was working on theirs.

 

I can't see what could be wrong with it.

 

Unless the actual form isn't constructed correctly?

Link to comment
Share on other sites

Maybe where it says

 

$parameters

 

It is supposed to say

 

tep_get_all_get_params()

 

Just a guess though :) Maybe it needs both of those? I'm not sure what the $parameters variable contains...

 

// display split-page-number-links
   function display_links($max_page_links, $parameters = '') {
  global $PHP_SELF, $prod_per_page, $request_type;
  $display_links_string = '<ul>';
  $class = 'class="navresults"';
  if (tep_not_null($parameters) && (substr($parameters, -1) != '&')) $parameters .= '&';
/* Customer Selected listing size */
// if your MAX_DISPLAY_SEARCH_RESULTS = 10
// Drop down menu will be :
// 10
// 20
// 30
// 40
// 50
 $ppp_list = array();
 for ($i = 1; $i <= 5; $i += 1) {
   $ppp = intval($i * MAX_DISPLAY_SEARCH_RESULTS);
   $ppp_list[] = array('id' => $ppp, 'text' => $ppp);
 }
// Show Drop down menu in split_page_link
// (You can move this part where ever you inside $display_links_string ) here it's a the very begining.
 $display_links_string .= '<div style="float: left; display:inline;">'. tep_draw_form('prod_per_page', tep_href_link(basename($PHP_SELF), $parameters), 'get'). TEXT_PPP .':'. tep_draw_pull_down_menu('ppp', $ppp_list, $products_per_search_page, 'class="smallText" onchange="this.form.submit()"');
  $ignore = array('page', 'ppp');
 if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) {
   reset($HTTP_GET_VARS);
   while (list($key, $value) = each($HTTP_GET_VARS)) {
  if ( (strlen($value) > 0) && ($key != tep_session_name()) && (!in_array($key, $ignore)) ) {
    $display_links_string .= tep_draw_hidden_field($key, $value);
  }
   }
 }
    $display_links_string .= tep_hide_session_id() . '</form>';

 

this is the code.

 

still can't workout why this form is not passing the full url of the current page in the form.

 

if i view the html source of the current page, it clearly shows the full URL in the action path, yet it isn't being passed through the form.

 

completely stuck on this one.

 

the fact that several others have used this as it is, i seriously have no clue as to why its not working.

 

everything seems right.

Link to comment
Share on other sites

  • 3 months later...

I am new to Oscommerce so bare with me and this is my first post. I am trying to move a dropdown list from the content area of three categories to the header of the page. It would display a category in the header with a dropdown list of the manufacturers that when selected would display in the content area. Does anyone know how to move the code from the content area to the header? I am using a test site at http://www.juantristan.com/store/index.php?cPath=22 there you can see in the content area a dropdown menu that says Show All Manufacturers. That is what I am trying to move to the header. Thanks for any help.

Link to comment
Share on other sites

Hi

 

You can pretty much take a bit of code from somewhere else in the files and hack sorry - edit - it to do something else - if you grab the code for the manufacturers box (top right on you right column) then you can use what's in there to get your solution. Just edit a line or a section at a time until the display is what you want

 

This will give you a dropdown in the same width/style as the ones you already have

<?php ////////////////////////////////////////////////
 $manufacturers_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");

$content='<div style=" height:20px; width:190px; border:0px solid #cacaca; float:left; padding:3px; margin-bottom:5px; margin-right:2px;">';
$content.='<span style="font-weight:bold; text-transform:uppercase; margin-right:4px;">Your title</span>';
$content.='<select style="width:120px;">
		 <option>(select)</option>';

	 while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
	 $content .= '<option>'.$manufacturers['manufacturers_name'].'</option>';
}
	 $content.='</select></div>';


 echo $content;

///////////////////////////////////////////////////
?>

Link to comment
Share on other sites

Hi

 

You can pretty much take a bit of code from somewhere else in the files and hack sorry - edit - it to do something else - if you grab the code for the manufacturers box (top right on you right column) then you can use what's in there to get your solution. Just edit a line or a section at a time until the display is what you want

 

This will give you a dropdown in the same width/style as the ones you already have

<?php ////////////////////////////////////////////////
 $manufacturers_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");

$content='<div style=" height:20px; width:190px; border:0px solid #cacaca; float:left; padding:3px; margin-bottom:5px; margin-right:2px;">';
$content.='<span style="font-weight:bold; text-transform:uppercase; margin-right:4px;">Your title</span>';
$content.='<select style="width:120px;">
		 <option>(select)</option>';

	 while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
	 $content .= '<option>'.$manufacturers['manufacturers_name'].'</option>';
}
	 $content.='</select></div>';


 echo $content;

///////////////////////////////////////////////////
?>

 

the dropdown you mention can be found in the index.php file in the /catalog/ folder

Link to comment
Share on other sites

  • 1 month later...

I want to use this menu in the registration from so that customers are able to select which group they belong to to be able to get different discounts (at the moment the group can only be chosen by the administrator) How would I go about adding it to the registration form and edit the code so it relates to that?

Link to comment
Share on other sites

  • 3 weeks later...

As mentioned in my previous post, I would like to use this drop down as part of the registration form when joining the site. Is it possible to have so that the list displays the types of groups available and then where one group needs to have some information filled in, it won't let you complete the registration until you fill in the details required for that group?

Link to comment
Share on other sites

  • 2 weeks later...

Hello folks. Stuck here too on that pull_down_list thing :(

 

Here are the code pieces I have so far

 

$duration = tep_db_prepare_input($HTTP_POST_VARS['duration']);

$duration_array = array();
 $duration_array[] = array('id' => '0', 'text' => '12 Monate');
 $duration_array[] = array('id' => '1', 'text' => '24 Monate');
 $duration_array[] = array('id' => '2', 'text' => '36 Monate');


  <td class="fieldValue"><?php echo tep_draw_pull_down_menu('duration', $duration_array); ?></td>

 

The site shows an empty drop down :(

 

I suspect that the function tep_draw_pull_down_menu is build to handle database input instead of hardcoded values, that's about the only reason I can think of why this is not working. Or is there anything wrong in this code pieces?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...