Page 1 of 1

$_POST[] issue for select multiple

Posted: Wed Mar 07, 2018 5:12 pm
by delorme
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

Re: $_POST[] issue for select multiple

Posted: Wed Mar 07, 2018 7:35 pm
by FourthWorld
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.

Re: $_POST[] issue for select multiple

Posted: Wed Mar 07, 2018 10:44 pm
by bangkok

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

Posted: Thu Aug 16, 2018 3:12 pm
by delorme
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:

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>
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