$_POST[] issue for select multiple

Are you using LiveCode to create server scripts or CGIs?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

$_POST[] issue for select multiple

Post 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
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: $_POST[] issue for select multiple

Post 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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: $_POST[] issue for select multiple

Post 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>
delorme
Posts: 4
Joined: Thu Oct 05, 2017 11:08 am
Contact:

Re: $_POST[] issue for select multiple

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