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

asked Nov 4, 2011 at 20:23
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']);
answered Nov 4, 2011 at 20:24
5
  • 3
    Also make sure to use htmlspecialchars so bad input doesn't end up breaking the HTML, or allowing XSS or something. Commented Nov 4, 2011 at 20:25
  • 2
    I'd recommend htmlentities($_POST['amount']) rather than just $_POST['amount'] -- keeps chars like quotes, ampersands etc from screwing with the HTML. Commented Nov 4, 2011 at 20:27
  • 2
    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. Commented Nov 4, 2011 at 20:31
  • this is what is already in the value number_format(htmlentities($invoiceArray[0]["remainingbalance"]),2, ".", "") Commented Nov 4, 2011 at 20:32
  • can't I do $invoiceArray[0]["remainingbalance"] = $amount Commented Nov 4, 2011 at 20:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.