Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2010
    Posts
    2
    Plugin Contributions
    0

    Default collect_info.php (copy of product_music\collect_info.php) dynamic dropdownlist

    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
    Code:
    <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') . '&nbsp;' . zen_draw_pull_down_menu('car_brand_id', $car_brand_array, $pInfo->car_brand_id, 'onchange=""'); 
    ?>
    </td>
    </tr>
    code for the second dropdown
    Code:
    $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') . '&nbsp;' . 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

  2. #2
    Join Date
    Jan 2010
    Posts
    2
    Plugin Contributions
    0

    Default Re: collect_info.php (copy of product_music\collect_info.php) dynamic dropdownlist

    here's the code what works for me. Its probably not the most beautofull but it works.
    Code:
    //================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') . '&nbsp;';
    
    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') . '&nbsp;' . 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==============================================

 

 

Similar Threads

  1. v150 collect_info.php
    By tenerifetom in forum Upgrading to 1.5.x
    Replies: 14
    Last Post: 5 Jan 2013, 06:52 PM
  2. [Done v1.3.9] Missing </tr> in collect_info.php
    By torvista in forum Bug Reports
    Replies: 1
    Last Post: 10 Jul 2010, 03:16 PM
  3. problem with collect_info.php
    By dirtyweekender in forum General Questions
    Replies: 0
    Last Post: 5 Mar 2008, 10:53 PM
  4. product_music/collect_info.php $pInfo
    By David Bo in forum Setting Up Categories, Products, Attributes
    Replies: 8
    Last Post: 12 Apr 2007, 06:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg