0

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

3
  • I have echoed out the variable $amount after the form gets submitted and its coming back with the right data, just need to know how to put that variable into the form. Commented Nov 4, 2011 at 20:24
  • 1
    9 question and 0 accepts? Really? It's that little green tick icon - and people will be a lot more willing to help you if you use it more often... Commented Nov 4, 2011 at 20:34
  • You also have to end your line with a semicolon: $amount = $_POST['amount']; Commented Nov 4, 2011 at 20:37

1 Answer 1

3

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']);
Sign up to request clarification or add additional context in comments.

5 Comments

Also make sure to use htmlspecialchars so bad input doesn't end up breaking the HTML, or allowing XSS or something.
I'd recommend htmlentities($_POST['amount']) rather than just $_POST['amount'] -- keeps chars like quotes, ampersands etc from screwing with the HTML.
I 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.
this is what is already in the value number_format(htmlentities($invoiceArray[0]["remainingbalance"]),2, ".", "")
can't I do $invoiceArray[0]["remainingbalance"] = $amount

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.