Help - Search - Members - Calendar
Full Version: PHP Multiple-Select Form Processing
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
tjs
Hey all,

Here's my situation:

I have a form that has 2 select boxes with multiple options.

For the First dropdown, I have assigned IDs to each option (1,2,3,etc)
For the Second dropdown, I have also assigned IDs to each option (01,02,03,etc)

When a user chooses an option from both select boxes and hit submit, I need to the form to processes the information so it realizes that both a First_id and a Second_id are selected, combines the two together -- $First_id.$Second_id -- and redirect the user to another page.

I think that what I need to do is assign different names to the select boxes and then have 2 different variables with different values and then can concantenate the first id to the second id and then redirect to the new page.

Problem is, I'm not too sure how to do that. angrylooking.gif

If you could help me out, I would appreciate it.
Thanks!
Lang
The HTML
CODE
<form action="action.php">
<select name="first_id">
<!-- your options here -->
</select>
<select name="second_id">
<!-- your options here -->
</select>
<input type="submit" value="Go">
</form>


The PHP
CODE
<?
        $first_id = (is_numeric($_POST['first_id'])) ? $first_id : 1;
        $second_id = (is_numeric($_POST['second_id'])) ? $second_id : 1;
        $combined = $first_id .'.'.$second_id;
        echo $combined;
?>


The HTML is self explanatory. What happens in the PHP is it first checks for the first id. And if the result from the form is a numerical value it is assigned, else it is just set to 1. The same is done for the second id. Then the combined value is the concatenated with a period (.) in the middle.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.