Keep value in form after submitting PHP

前端 未结 3 728
轻奢々
轻奢々 2021-01-25 04:44

I\'m calling these functions from a controller to get the form and the values from the form. My question is, how can I keep the values in the form after a submit fails? I\'ve tr

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-25 05:09

    Before your form, instantiate the object which will receive the $_POST data

    $userbox = new Userbox;
    

    Then process $_POST data, if there is any:

    if(isset($_POST['submit']) && $_POST['submit'] === 'userboxsubmit'){
      $userbox->process_post(); 
    }
    

    Then output the form:

    
    

提交回复
热议问题