Workaround for validation and checking if the form has been actually posted

前端 未结 2 1254
忘了有多久
忘了有多久 2021-01-26 04:10

Here is my typical form

        $errors = array();

        if ($this->request->post(\'submit\')) { // <----- I don\'t like this line
            $post          


        
相关标签:
2条回答
  • 2021-01-26 04:38
    if ($post = $this->request->post())
    {
        $post = Validation::factory($post);
        ...
    }
    
    0 讨论(0)
  • 2021-01-26 04:39

    This is how I'd do it, except for the condition:

    if (Request::POST === $this->request->method())
    

    would be more suitable. There is no way to "skip" the POST check without having consequences (like the errors in your case).

    We had a discussion on this topic, 5.3 will probably add more features. Something like:

    $this->post(function(){
        // do POST-specific stuff 
    })
    ->get(function(){
        // do GET-specific stuff
    });
    
    0 讨论(0)
提交回复
热议问题