Hey Ya'll I have a question (sorry dont have code, but i'll try my best explaining) I have an input text field with a value in it....that value goes into a variable...
$amount = $_POST['amount']
So in this form if something is missing and the user gets an error message (something didn't match up or invalid information) I would like the variable $amount put back into the input text field...is this possible?
Sorry for lack of details, but I have no idea how to code this.
Thanks
1 Answer 1
Yes, you can do this:
<input type="text" size="25" value="<?php echo $amount; ?>" />
Be sure the user can't inject HTML back onto the page, as that could cause issues. Typecasting $amount
to an integer might be appropriate in this case. Two solutions could be:
$amount = (int) $_POST['amount'];
$amount = htmlentities($_POST['amount']);
-
3Also make sure to use htmlspecialchars so bad input doesn't end up breaking the HTML, or allowing XSS or something.drew010– drew0102011年11月04日 20:25:32 +00:00Commented Nov 4, 2011 at 20:25
-
2I'd recommend
htmlentities($_POST['amount'])
rather than just$_POST['amount']
-- keeps chars like quotes, ampersands etc from screwing with the HTML.cHao– cHao2011年11月04日 20:27:20 +00:00Commented Nov 4, 2011 at 20:27 -
2I often work in a bilingual environment so I'd just like to add that
htmlentities
needs you to mention the encoding as one of its parameters if you want it to work correctly.Gazillion– Gazillion2011年11月04日 20:31:10 +00:00Commented Nov 4, 2011 at 20:31 -
this is what is already in the value number_format(htmlentities($invoiceArray[0]["remainingbalance"]),2, ".", "")user979331– user9793312011年11月04日 20:32:26 +00:00Commented Nov 4, 2011 at 20:32
-
can't I do $invoiceArray[0]["remainingbalance"] = $amountuser979331– user9793312011年11月04日 20:33:03 +00:00Commented Nov 4, 2011 at 20:33
$amount = $_POST['amount'];