If this is your first visit, check our documentation. To post, register or login.
Forums / Setting Up Your Zen Cart Products / Setting Up Categories, Products, Attributes / collect_info.php (copy of product_musiccollect_info.php) dynamic dropdownlist

collect_info.php (copy of product_musiccollect_info.php) dynamic dropdownlist

Started by spsen on 19 Jan 2010, 7:12 PM · Views: 2,002

Results 1 to 2 of 2
19 Jan 2010, 7:12 PM
#1
spsen avatar

spsen

New Zenner

Join Date:
Jan 2010
Posts:
2
Plugin Contributions:
0

Post #1 by spsen

Hello

I use zen 1.3.8
I made a new product type with dropdownlists in collect_info.php
All dropdowns are populated.

My problem is that i want that the second dropdown is populated with a 'where' from the first dropdownlist.
So the selected item from the first dropdownlist is a criteria for the second one.
code of first dropdownlist

<tr>
<td class="main"><?php echo constant("TEXT_PRODUCTS_CAR_BRAND"); ?></td>
<td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_pull_down_menu('car_brand_id', $car_brand_array, $pInfo->car_brand_id, 'onchange=""'); 
?>
</td>
</tr>

code for the second dropdown

$car_model = $db->Execute("select car_model_id, car_model from CAR_MODEL where car_brand_id = $car_brand_id order by car_model");
  while (!$car_model->EOF) {
	$car_model_array[] = array('id' => $car_model->fields[car_model_id], 'text' => $car_model->fields[car_model]);
	$car_model->MoveNext();}

<tr><td class="main"><?php echo constant("TEXT_PRODUCTS_CAR_MODEL"); ?></td>
<td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_pull_down_menu('car_model_id', $car_model_array, $pInfo->car_model_id); 
?></td>

When i use 'onchange="this.form.submit()"' i'm not staying on collect_info.php, but the page preview_info.php is loaded.
What do i have to fill in after onchange=.................?
can someone point me the right direction?
Thanks:smile:

1 Feb 2010, 9:05 PM
#2
spsen avatar

spsen

New Zenner

Join Date:
Jan 2010
Posts:
2
Plugin Contributions:
0

Post #2 by spsen

here's the code what works for me. Its probably not the most beautofull but it works.

//================dynamic dropdownlist for car_brand and car_model===============================
$page = $_GET['page'];
$product_type = $_GET['product_type'];
$cpath = $_GET['cPath'];
$pID = $_GET['pID'];
$action = "new_product";

$hrefNewCar = "product_car.php?product_type=" . $product_type . "&cPath=" . $cPath . "&action=" . $action;
list($hrefNC1, $hrefNC2, $hrefNC3, $hrefNC4) = split('[_]', $hrefNewCar);

$hrefChangeCar = "product_car.php?page=" . $page . "&product_type=" . $product_type . "&cPath=" . $cPath . "&pID=" . $pID . "&action=" . $action;
list($hrefCC1, $hrefCC2, $hrefCC3, $hrefCC4) = split('[_]', $hrefChangeCar);

echo <<<END
<table>
<tr>
<td class="main">
END;
echo TEXT_PRODUCTS_CAR_BRAND;
echo <<<END
</td>
<td class="main">
END;
echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ';

if (isset($page))
	{
		echo <<<END
		<select STYLE="width: 115px;font-size:80%;" onchange='document.location.href="$hrefCC1"+"_"+"$hrefCC2"+"_"+"$hrefCC3"+"_"+"$hrefCC4"+"&car_brand_id="+this.options[this.selectedIndex].value;'>
END;

	if (isset($_GET['car_brand_id']))  //Get car_brand_id for taking it into the car_brand dropdownlist as first select (href link from car_brand dropdownlist)
		{
			$car_brand_id = $_GET['car_brand_id'];
			
			echo "<option value=\"$car_brand_id\">$car_brand_array[$car_brand_id]</option>";
			
			$pInfo->car_brand_id = $car_brand_id;  //used by car_brand dropdown
			for ($i = 0; $i < sizeof($car_brand_array); ++$i) 
				{
					
					echo "<option value=\"$i\">$car_brand_array[$i]</option>";
				}
		} 
	else //Get car_brand_id for taking it into the car_brand dropdownlist as first select (from hidden_field preview_info)
		{
			$car_brand_id = $pInfo->car_brand_id;  //used by car_brand dropdown
		
			echo "<option value=\"$car_brand_id\">$car_brand_array[$car_brand_id]</option>";
		
			for ($i = 0; $i < sizeof($car_brand_array); ++$i) 
				{
				
					echo "<option value=\"$i\">$car_brand_array[$i]</option>";
				}
		}
	}
else
	{
		echo <<<END
		<select STYLE="width: 115px;font-size:80%;" onchange='document.location.href="$hrefNC1"+"_"+"$hrefNC2"+"_"+"$hrefNC3"+"_"+"$hrefNC4"+"&car_brand_id="+this.options[this.selectedIndex].value;'>
END;
	if (isset($pInfo->car_brand_id))  //Get car_brand_id for taking it into the car_brand dropdownlist as first select (from hidden_field preview_info)
		{
			$car_brand_id = $pInfo->car_brand_id;  //used by car_brand dropdown
			
			echo "<option value=\"$car_brand_id\">$car_brand_array[$car_brand_id]</option>";
		
			for ($i = 0; $i < sizeof($car_brand_array); ++$i) 
				{
				
					echo "<option value=\"$i\">$car_brand_array[$i]</option>";
				}
		}
	elseif (isset($_GET['car_brand_id']))  //Get car_brand_id for taking it into the car_brand dropdownlist as first select (href link from car_brand dropdownlist)
		{
			$car_brand_id = $_GET['car_brand_id'];
			
			echo "<option value=\"$car_brand_id\">$car_brand_array[$car_brand_id]</option>";
			
			$pInfo->car_brand_id = $car_brand_id;  //used by car_brand dropdown
			for ($i = 0; $i < sizeof($car_brand_array); ++$i) 
				{
				
					echo "<option value=\"$i\">$car_brand_array[$i]</option>";
				}
		} 
	
	else  //make car_brand dropdownlist for the first time without an id for the brand dropdownlist
		{
			$pInfo->car_brand_id = 0;  //car_brand_id is set, because there was no brand selection from collect_info
			for ($i = 0; $i < sizeof($car_brand_array); ++$i) 
				{
					echo "<option value=\"$i\">$car_brand_array[$i]</option>";
				}
		}
	}

echo zen_draw_hidden_field('car_brand_id', $pInfo->car_brand_id);//passthrough of car_brand_id from collect_info to preview_info and vica versa
echo <<<END
</select></td></tr>
END;

//if (isset($pInfo->car_brand_id))  //when car_brand_id is set, make a model array with the specific brand_id
if ($pInfo->car_brand_id == 0)  //when car_brand_id is set, make a model array with the specific brand_id
	{
		$car_model = $db->Execute("select car_model_id, car_model from CAR_MODEL where car_brand_id = 0 order by car_model");
		$car_model_array[] = array('id' => 0, 'text' => TEXT_NONE);
		
	}
else
	{
		$car_model = $db->Execute("select car_model_id, car_model from CAR_MODEL where car_brand_id = " . $pInfo->car_brand_id . " order by car_model");
		$car_model_array[] = array('id' => 0, 'text' => TEXT_NONE);
		while (!$car_model->EOF) 
			{
				$car_model_array[] = array('id' => $car_model->fields[car_model_id], 'text' => $car_model->fields[car_model]);
				$car_model->MoveNext();
			}
	}
//============== car_model dropdownlist==========================================================================
?>
		<tr>
			<td class="main">
				<?php echo constant("TEXT_PRODUCTS_CAR_MODEL"); ?>
			</td>
            <td class="main">
				<?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_pull_down_menu('car_model_id', $car_model_array, $pInfo->car_model_id);?>
			</td>
		</tr>		  
<?php
//==================================================================================================================
//================END dynamic dropdownlist for car_brand and car_model==============================================