Jump to content


PHP Multiple-Select Form Processing


1 reply to this topic

#1 tjs

    Young Padawan

  • Members
  • Pip
  • 29 posts
  • Gender:Male
  • Location:Chicago

Posted 16 June 2009 - 03:54 PM

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. ;)

If you could help me out, I would appreciate it.
Thanks!

#2 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 19 June 2009 - 09:21 PM

The HTML
<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
<?
		$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.

Edited by Lang, 19 June 2009 - 09:23 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users