Re: Numbers, Numbers everywhere! Need some Dollar help.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/2/07, Dan Shirah <mrsquash2@xxxxxxxxx> wrote:
> Greetins all,
>
> In my form I have an area where the user enters in the payment amount:
>
> <input type="Text" value="" size="20" maxlength="16" name="payment_amount">
>
> This is all fine and dandy and works as generically as it can. BUT, the
> problem is that I need to make sure the user didn't fat finger any of the
> numbers.  For instance, in my generic text field the user types 600 in the
> payment amount and clicks submit.
>
> This works and the user is charged $600.  But, come to find out the user
> meant to enter 6.00 not 600. Can I add a check using PHP to force the user
> to put in the dollar AND cents? This way if a number such as 600 is entered
> and the user hits save, the check will notice there isn't a .00 on the end
> and prompt the user for more information.
>
> Could I incorporate something like:
>
> if ($payment_amount != number_format($payment_amount, 2)) {
>   error here
> }
>
> Or, do you think I would be better off using two text areas?  One for the
> dollar value and one for the cents?
>
> Or, do you think I would be better off trying to find some kind of
> javascript function that would check the value upon submit?
>
> Any help is appreciated.
>
> Dan
>

    "woot woot"

    That's all really a matter of preference, Dan.  You could even
just check to ensure that there's a period in there, and if not, emit
an error message that the user is required to enter the full amount in
dollars and cents.

<?
if(!strstr($_POST['amount'],".") {
    $err[] = "Please enter the full amount in dollars and cents.";
}

if(!$err) {
    // Process and continue.
    exit;
}

for($i=0;$i<count($err);$i++) {
    echo "<B><FONT COLOR=\"#FF0000\">".$err[$i]."</FONT></B><BR />\n";
}
?>
<FORM METHOD="POST" ACTION="<?=$_SERVER['PHP_SELF'];?>">
....




-- 
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux