Naresh Kumar Naresh Kumar - 7 months ago 14
HTML Question

form field with decimal value shows as empty in $_POST

I have a form field that looks like this:

<input type="hidden" name="last_amount_paid" value="<?php echo $amount; ?>">


$amount is set to 100.00 and shows up fine if I change the form field from hidden to text.

$_POST['last_amount_paid '] is empty when I try and retrieve the value after submit.

I ran var_dump($_POST); and it's showing up as a string and empty

["last_amount_paid"]=> string(0) ""


Any ideas?

Answer

So for me it works if I create a tiny script like this:

<?php
if(!empty($_POST["last_amount_paid"]))
{
    echo $_POST["last_amount_paid"];
} else
{
    $amount = 100.00;
    ?>
    <form method="POST" action="">
        <input type="hidden" name="last_amount_paid" value="<?=$amount; ?>" />
        <input type="submit" value="Submit" />
    </form>
    <?php
}
?>

You can see it work here. Happy Copy & Pasting. :D

Comments