How can I set the value of a textbox through PHP?

前端 未结 3 1396
耶瑟儿~
耶瑟儿~ 2020-12-06 12:50

So I have this empty textboxes in a registrationg page. The user enters some data, hits continue and then there\'s a confirmation page. If the data is incorrect, the user hi

相关标签:
3条回答
  • 2020-12-06 13:33

    To set the value, you can just echo out the content inside the value attribute:

    <input type="text" name="firstname" value="<?php echo htmlentities($firstName); ?>" />
    <input type="text" name="lastname" value="<?php echo htmlentities($lastName); ?>" />
    
    0 讨论(0)
  • 2020-12-06 13:48

    Of course you will want to escape it but...

    <input type="text" value="<?php echo $firstName ?>" />
    

    or if the form is posted, it would be easier to do:

    <input type="text" name="firstName" value="<?php echo $_POST['firstName'] ?>" />
    

    fine... even though it was out of the scope of the question here is the escaped version:

    <input type="text" name="firstName" value="<?php echo htmlentities($_POST['firstName']) ?>" />
    
    0 讨论(0)
  • 2020-12-06 13:56

    smth like

    <input type="text" value="<?php echo $first_name;?>">
    

    Don't forget to escape with htmlentities() or smth similar. If you don't know why - google XSS.

    0 讨论(0)
提交回复
热议问题