2

When a process changed required me to change a radio button field, to a checkbox to allow multiple selections, I made the following change to my html:

    <input type='checkbox' name='ptype[]' value='1'> Jail/not sentenced</br>
    <input type='checkbox' name='ptype[]' value='2'> Jail/Sentenced</br>
    <input type='checkbox' name='ptype[]' value='3'> State/DOC</br>
    <input type='checkbox' name='ptype[]' value='4'> ICE/US Marshall</br>
    <input type='checkbox' name='ptype[]' value='5'> 7x/wardens Agree</br>

When making ptype an array to handle multiple selections, I am finding my $_POST variable missing a key. If I try to revert ptype to a radio button and handle only one value, I don't get any error/warning.

I've checked Firebug, and when ptype[] is set, one of my $_POST variables is not relayed. I know the max post variable is not an issue, as I only have 52 post variables on my form.

I don't know if it's relevant, but this field is never coming through:

    <input type='radio' name='wc' value='1'> Yes
    <input type='radio' name='wc' value='0'> No

   Notice: Undefined index: wc in C:\inetpub\wwwroot\internal_tools\include\consults\consult_utilities.php on line 53 

Any help would be greatly appreciated.

EDIT: As requested, my form.

EDIT 2: Firebug POST variables

EDIT 3: Added line 53:

$data['workers_comp']           = $_POST['wc'];
etm124
  • 2,100
  • 4
  • 41
  • 77
  • can we see your PHP code? – John Dvorak Aug 16 '13 at 13:22
  • 3
    @Fred, no - second is a single radio, while first are multiple checkboxes – Alma Do Aug 16 '13 at 13:24
  • Added form. Why flag for close? – etm124 Aug 16 '13 at 13:27
  • Ok.. undefined. Check if you have this in your handler => `$wc=$_POST['wc'];` if that's not it, then show your full code. – Funk Forty Niner Aug 16 '13 at 13:28
  • And the code on line 53 is? Need to see the PHP code – Hanky Panky Aug 16 '13 at 13:30
  • BTW: It's `
    ` or `
    `, but not ``
    – huysentruitw Aug 16 '13 at 13:31
  • 1
    I see you're running the javascript function `validateFrm(this)` before posting the form. Maybe you have an error there that breaks if the name contains `[]`? – huysentruitw Aug 16 '13 at 13:35
  • The problem you're describing is explained here: [Does only post data if it's checked?](http://stackoverflow.com/questions/11424037/does-input-type-checkbox-only-post-data-if-its-checked) – AD7six Aug 16 '13 at 13:35
  • @etm124 We need to see your full PHP handler code, not your form. We know what's in it. You're passing a double variable and could be getting lost somewhere. It's obviously an array and trying to pull stuff from somewhere. This is too vague for me, you guys take over. This is a `localized` issue. – Funk Forty Niner Aug 16 '13 at 13:37
  • @Fred it has nothing to do with the data handler. The form is not passing the key to the POST variable. – etm124 Aug 16 '13 at 13:40
  • @WouterHuysentruit you are correct with the `validateFrm` function. It was causing an issue. This question is too localized and will be closed. – etm124 Aug 16 '13 at 13:41

1 Answers1

1

Probably you didn't select an option for the wc radiobutton and therefore the variable is not submitted.

You should change your PHP code to:

$wc = isset($_POST["wc"]) ? $_POST["ws"] : "0";

Or, as I already suggested in comment, you have a problem in the javascript method validateFrm which you call upon submitting the form.

huysentruitw
  • 27,376
  • 9
  • 90
  • 133