Jump to content

html form, "multiple", retrieving values, PLEASE HELP =D


vns

Recommended Posts

hi,

 

(first time on a PHP board...be nice! =D)

 

i have a form, which picks form values from a DB,

generating the form with the multiple values from the DB works fine!

 

my problem is how to extract these values from the form, so that i can use them on the next page.

does the html form retun as an array...or what?!

 

cheers, for any help!

 

					<dd><select name="StudentSelected" id="StudentSelected">
				<?php
					mysql_select_db("calendar", $con);
					$result = mysql_query("SELECT * FROM Person
						WHERE PersonType='Student'");

					echo "<option value='000'>PLEASE SELECT ONE</option>";
					while($row = mysql_fetch_array($result, MYSQL_BOTH))
					{
						$emails = $row['PersonEmailAddress'];
						$names = $row['LastName'].", ".$row['FirstName'];
						echo $email.
						echo "<option value=".$emails.">".$names."</option>";
					}//while
					mysql_free_result($result);
				?>
				</select></dd>

 

(form passes to another php page, using POST)

 

 

have tried this to just print out the returning values, as an array, but it only seems to return them as one at a time...

		print_r($_POST['StaffSelected']);


	foreach ($_POST['StaffSelected'] as $value){
		print "$value<br>";

 

 

THANKS FOR THE HELP GUYS!

$_POST only gets one value (from the selected option) in a <select> element.

If you need to send ALL options to the next page through $_POST you have to create another element (probably hidden?) with all the data, but I don't see the reason why if you can just recreate the options... or maybe you can't?

for your select box try this:

 

name="StudentSelected[]" //note the square brackets

 

then access your POST array.

 

PERFECT... 8)

(how do i add rep on this forum?)

 

 

new problem now...

but now that has brought up a jquery problem, i am doing a check that 3-5 people exactly have been selected...

it does not seem to like the square brackets []

 

					var numSelected = countSelectedValues("#StaffSelected[]");
				if(numSelected <3)
				{
					alert("You onle selected: "+numSelected+" staff members, please select between 3-5.");
					event.preventDefault();
				}
				else if(numSelected >5)
				{
					alert("You onle selected: "+numSelected+" staff members, please select between 3-5.");
					event.preventDefault();
				}

(tries to validate this form now...)

 

					<dd><select name="StaffSelected[]" id="StaffSelected[]" multiple="yes">
				<?php
					mysql_select_db("calendar", $con);
					$result = mysql_query("SELECT * FROM Person
						WHERE PersonType='Staff'");

					while($row = mysql_fetch_array($result, MYSQL_BOTH))
					{
						$emails = $row['PersonEmailAddress'];
						$names = $row['LastName'].", ".$row['FirstName'];
						echo "<option value='".$emails."'>".$names."</option>";
					}//while

					mysql_free_result($result);
				?>
				</select></dd>

I could be wrong but since it's an array of selected items now you can use the array count function that is built into javascript.

 

thanks for all the help guys,

 

simple fix

 

name="StaffSelected[]" id="StaffSelected"

 

jquery uses id, html forms seem to use name...always wondered what was the point of both, for once it helped! silly html.

 

SOLVED  :D

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.