Hi from France
My livecode server code is:
<!DOCTYPE html><html><?lc
put "hello" & $_POST["cars"]
?></html>
When I post from a multiple select input with several options selected in the following html page:
<!DOCTYPE html><html><body>
<form method="post" action="mylivecodeserver">
<select name="cars" multiple >
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</select>
<input type="submit">
</form></body></html>
I only get (by $_post) the LAST selected option value.
I tried name="cars[]" for getting an array as cited in some php forums, but a "is not an array" empty value is returned.
What is wrong with not getting ALL selected values?
Thanks for your kind help
Regards from Jean-Marc
$_POST[] issue for select multiple
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 9838
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: $_POST[] issue for select multiple
Without seeing the code you're using to get the array keys it will not be possible to provide ways to improve it.
If you're using "cars[]", that may be the issue; try simply "cars" instead. But that's only a guess, since I haven't seen the actual code that's failing.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: $_POST[] issue for select multiple
Code: Select all
<!DOCTYPE html><html><?lc
put "Il y a "&the number of elements of $_POST["cars"]&" reponses<BR>"
repeat for each element tItem in $_POST["cars"]
put tItem&"<BR>"
end repeat
?></html>
Et voilà !
Et il faut mettre :
<select name="cars[]" multiple >
Last but not least :
The array is passed as $_POST["cars"][1] (for the first select)
then
$_POST["cars"][2]
etc.
So you could do as well :
Code: Select all
<!DOCTYPE html><html><?lc
put the number of elements of $_POST["cars"] into tNumber
put "Il y a "&tNumber&" reponses<BR>"
repeat with i = 1 to tNumber
put $_POST["cars"][i]&"<BR>"
end repeat
?></html>
Re: $_POST[] issue for select multiple
Hi after some time!
Thank you for replies
I am sorry that none of those replies works.
If I edit a LC server script with:
Executing the script returns the form on 1st time, the form + false (is not an array) on submiting on second time.
Changing name "cars[]" for "cars" in select is neither a solution that allows to get the multiple values. (only returns the last one)
Any other idea?
Regards
jean-marc
Thank you for replies
I am sorry that none of those replies works.
If I edit a LC server script with:
Code: Select all
<!DOCTYPE html>
<html>
<body>
<form method='post' action='myserver .lc'>
<select name='cars[]' multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</select>
<button type='submit'>Send</button>
</form>
<?lc
put $_POST["cars"] is an array
?>
</body>
</html>
Changing name "cars[]" for "cars" in select is neither a solution that allows to get the multiple values. (only returns the last one)
Any other idea?
Regards
jean-marc