Jump to content

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


AdRock
Go to solution Solved by tryingtolearn,

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"

 

Link to comment
Share on other sites

  • Solution

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>
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.