0
Default option value in a form
I have a form with some options values, after the user choose one, I want the next time he visits the site, his last choose be pre selected, what's the best way to do it? I have the last value in a PHP cookie but I don't know how to use it in the html code :/
4 Antworten
+ 1
Thanks for your time Ipang, I'll check ✅
0
What element are you using? I think you will need to also populate the options using PHP. During population of options to choose, you check whether one of the options matches the last value in cookie. If match found, you set that option selected.
How to make an option get selected will depend on which element in use.
0
This is the part of the code
https://code.sololearn.com/WwJl778BsSez/?ref=app
0
Here's an example that runs in Code Playground. I had to hardcode the $last_option here because Code Playground doesn't allow form submission, and I'm not sure whether cookies were allowed either.
https://code.sololearn.com/wE0DtrF3ZDKV/?ref=app