$_POST[] issue for select multiple

Are you using LiveCode to create server scripts or CGIs?

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
delorme
Posts: 3
Joined: Thu Oct 05, 2017 11:08 am
Contact:

$_POST[] issue for select multiple

Post by delorme » Wed Mar 07, 2018 5:12 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5895
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: $_POST[] issue for select multiple

Post by FourthWorld » Wed Mar 07, 2018 7:35 pm

delorme wrote:
Wed Mar 07, 2018 5:12 pm
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?
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
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 785
Joined: Fri Aug 15, 2008 7:15 am

Re: $_POST[] issue for select multiple

Post by bangkok » Wed Mar 07, 2018 10:44 pm

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>

Post Reply

Return to “CGIs and the Server”