vns Posted March 3, 2010 Share Posted March 3, 2010 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! Link to comment https://forums.phpfreaks.com/topic/194002-html-form-multiple-retrieving-values-please-help-d/ Share on other sites More sharing options...
Dennis1986 Posted March 3, 2010 Share Posted March 3, 2010 $_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? Link to comment https://forums.phpfreaks.com/topic/194002-html-form-multiple-retrieving-values-please-help-d/#findComment-1020896 Share on other sites More sharing options...
jtgraphic Posted March 3, 2010 Share Posted March 3, 2010 for your select box try this: name="StudentSelected[]" //note the square brackets then access your POST array. Link to comment https://forums.phpfreaks.com/topic/194002-html-form-multiple-retrieving-values-please-help-d/#findComment-1020897 Share on other sites More sharing options...
aeroswat Posted March 3, 2010 Share Posted March 3, 2010 nvm misread the question Link to comment https://forums.phpfreaks.com/topic/194002-html-form-multiple-retrieving-values-please-help-d/#findComment-1020898 Share on other sites More sharing options...
vns Posted March 3, 2010 Author Share Posted March 3, 2010 for your select box try this: name="StudentSelected[]" //note the square brackets then access your POST array. PERFECT... (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> Link to comment https://forums.phpfreaks.com/topic/194002-html-form-multiple-retrieving-values-please-help-d/#findComment-1020911 Share on other sites More sharing options...
jtgraphic Posted March 3, 2010 Share Posted March 3, 2010 Unfortunately I kind of suck at javascript :-/ Link to comment https://forums.phpfreaks.com/topic/194002-html-form-multiple-retrieving-values-please-help-d/#findComment-1020914 Share on other sites More sharing options...
aeroswat Posted March 3, 2010 Share Posted March 3, 2010 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. Link to comment https://forums.phpfreaks.com/topic/194002-html-form-multiple-retrieving-values-please-help-d/#findComment-1020916 Share on other sites More sharing options...
vns Posted March 3, 2010 Author Share Posted March 3, 2010 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 Link to comment https://forums.phpfreaks.com/topic/194002-html-form-multiple-retrieving-values-please-help-d/#findComment-1020927 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.