duanjiwu0324 2014-02-12 11:05
浏览 1049

如何在HTML <input>中保留输入值

How can i possibly preserve the value of the <input> field if submitted wrong? I have a form that will be submitted to a php page. The PHP page will then check if that is correct or not.

Ex. if the user input google the PHP page says it is wrong. I want google sent back to the input field.

  • 写回答

4条回答 默认 最新

  • dongtuji0992 2014-02-12 11:07
    关注

    You can access the value using the $_POST or $_GET super-global. Depending upon the form submit method, you can do:

    <input type="text" value="<?= (isset($_POST['field'])) ? strip_tags($_POST['field']) : '' ?>" name="field" />
    

    If your method="get", you'll need:

    <input type="text" value="<?= (isset($_GET['field'])) ? strip_tags($_GET['field']) : '' ?>" name="field" />
    
    评论

报告相同问题?