0

I have a custom Checkbox its made in a Div

<div class="zs" name="toggle" state="on" id="zs"></div>

The checkbox has toggle on/off and the state attribute changes on click to on/off.

The div is placed in a for submittion but I dont know how to get $_POST['toggle'] from php to receive the attribute "state"

4
  • 1
    Adding a name attribute doesn't make a div a form element... You'll have to either build the POST with javascript (in which case we want to see that code), or use a plain old checkbox (remember you can have a big label for that checkbox, so formatting-wise there are a lot of options). Commented Jun 18, 2012 at 21:58
  • I wanted to avoid using Ajax request to build the POST. Is there another way? Commented Jun 18, 2012 at 22:01
  • 1
    Not if you abuse a div for this. Really, a label with a for attribute and a hidden <input type="checkbox"> seems the way to go here if you don't want to manually build the post. Or update an <input type="hidden"> somewhere. Commented Jun 18, 2012 at 22:03
  • Div is not a valid form element so you cannot POST information in its attributes anywhere, even if the div is surrounded by FORM tags. Commented Jun 18, 2012 at 22:05

1 Answer 1

1

The browser is only going to send through input and select tags with the form submission, not div. It sounds like you might want to store your value in a hidden input, IE:

<input type='hidden' name='toggle' value='on' />

Then add to whatever javascript you're already using to set the value appropriately.

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

Comments

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.