Validation on frontend form

Support MB Frontend Submission Validation on frontend formResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #46115
    YasmineYasmine
    Participant

    Hello,

    I have added validation to my frontend form:

    add_filter( 'rwmb_frontend_validate', function( $validate, $config ) {
        if ('academic-research-summary' !== $config['id']) {
            return $validate;
        }
        if ( empty( $_POST['post_title'] ) ) {
            $validate = 'Title for your post is missing'; 
        }
    		  if ( empty( $_POST['academicpost_excerpt'] ) ) {
            $validate = 'Focus is missing'; 
        }
    ect... 
        return $validate;
    					
    }, 10, 2 );

    The messages respond to the missing fields and return. But the form loses all the information that was inputted. So when submit is clicked, you see the message but all the fields are now blank.

    #46120
    PeterPeter
    Moderator

    Hello,

    That is expected when using the PHP code to validate, the page will be reloaded and input value will be lost. If you want to validate a field without reloading the page, please use the JS validate https://docs.metabox.io/validation/

    #46187
    YasmineYasmine
    Participant

    Thanks - it now works

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.