Skip to content
Advertisement

$_POST command doesnt recognise multiple-choice image checkbox value

My Goal: when a user clicks on “submit”, I want to get all the selected values (aka “attraction types”) (when a picture is clicked, it should work like a checkbox). The CSS works properly, but when i reach the php file it ignores my selection and says “No Atrtype”, acting like no value was chosen.

I am new to php (and coding in general) and have tried to re-order the divs, use “isset” in php and change the variable names (and a lot more), yet it was to no avail. I would appreciate some help here.

most classes have to do with css attributes , so please ignore css for this question’s sake.

php:

JavaScript

html:

JavaScript

Advertisement

Answer

There are numerous issues here:

Your PHP is treating the $atrtype1 as if it’s a single value, it’s not, its an array of values. Try print_r($_POST['atrtype']) to see what the data actually is and adjust your code accordingly. You can’t echo out an array.

You have a typo:

JavaScript

These are two different variables!

Also, stop using == and improve your coding style by using === full type-casting qualifiers

Fixed:

JavaScript

Your processing logic is a mess of arrays and strings, you really need to take a clean sheet of paper and judge what you’re doing from the start, again. I can’t advise much on this without understanding your full intentions and logic flow.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement