Jump to content

radio button value 0 in $_POST shows "on" in var_dump


AdRock

Recommended Posts

Whenever I try and post a form with radio buttons like this

<input type="radio" name"whatever" value="0">

and I do a

var_dump($_POST)

it always shows 

array(11) {["whatever"]=> string(2) "on" }

but this works and will display 1 in the var_dump

<input type="radio" name"whatever" value="1">

Why is this. I need the value set to 0 because that's the value going into the database. I don't really want to do a str_replace just to replace "on" with "0"

 

might just be a typo but do you have a = sign for name in the real code?

 

 

<input type="radio" name"whatever" value="0">

 

just a thought because this works

    <?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {	
        var_dump($_POST);	
    }
    ?>
    <form action="index.php" method="POST">
        <input type="radio" name="whatever" value="0">
        <input type="radio" name="whatever" value="1">
        <input type="radio" name="whatever" value="2">
        <input type="submit" name="submitted" value="Search" />
    </form>

but this doesnt

    <?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {	
        var_dump($_POST);	
    }
    ?>
    <form action="index.php" method="POST">
        <input type="radio" name"whatever" value="0">
        <input type="radio" name="whatever" value="1">
        <input type="radio" name="whatever" value="2">
        <input type="submit" value="Search" />
    </form>

Yes. That was a typo and I've narrowed it down to a form class I use that generated form elements.

Actually writing the html markup does work but my form class seems to drop the zero value.

I might have to set the form values to yes/no and then convert that to a 0/1 before it goes into database.

 

Anyway thanks for your help. At least it helped my identify the problem

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.