1

So my html is:

<form action="/product/additem" method="post" enctype="multipart/form-data">
    <input type="checkbox" name="item_active" id="item_active" value="Yes" />
    *** more input types but all of them are type file & text
</form>

Now in my PHP I do this:

var_dump($_POST['item_active']);

and this is what I get:

string(0) ""

NOTE: My javascript code that does the actual .submit

$('#button').on('click', function() {
   $('#new_item_container form').submit();
});

What is wrong with my checkbox I dont get it. I am using Firefox

7
  • Why are you using "multipart/form-data" for a simple (non-multipart) form? Commented May 23, 2014 at 20:56
  • well its not a simple form it does file upload as well, i just posted the form part and checkbox part. It also has the <input type="file"in it Commented May 23, 2014 at 20:57
  • 3
    The only apparent question is: Did you check the check-box ? Commented May 23, 2014 at 21:02
  • 2
    If he didn't check the checkbox, $_POST['item_active'] wouldn't be set at all. Commented May 23, 2014 at 21:03
  • 1
    Do you have multiple inputs with the name item_active? Commented May 23, 2014 at 21:03

1 Answer 1

4

Do you have any other <form> tags ahead or around this form? This is a shot in the dark, but I had this problem last week, and was pulling my hair out, until I found that the form I was looking at, was actually nested inside another form, and that changes the behavior. If the other form has the same named value, it can (in some cases, apparently) take precedence and prevent you from seeing the value that you think you are getting.

Sign up to request clarification or add additional context in comments.

3 Comments

Found the problem was similar to yours but this led me to a solution so thank you for that. Was nested forms problem.
If that answer helped, check it as the accepted answer.Glad it helped.
will do in 2 minutes :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.