• Resolved twig

    (@stripytiger)


    Hi. I am wanting to use Forminator to collect some data. I am collecting name, email and a membership number.

    When the user presses submit, I would like to catch the data entered, check the membership is valid, and if not cancel the submission. Is there a filter to do this? I have looked and cannot see anything.

    Many thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter twig

    (@stripytiger)

    I have looked at the forminator_custom_form_submit_before_set_fields action, and if I could cancel the submit at this point if the membership number is invalid, that would be great. Thank you

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @stripytiger

    I hope you are doing good today.

    I pinged our Formiantor Team to review your query. We will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @stripytiger ,

    I’m sorry for the delay on our end. Our developer suggested using forminator_custom_form_submit_errors. With it, you can check submitted fields there and return a custom error message if fields data are not valid.

    Let us know if that helps.

    kind regards,
    Kasia

    Thread Starter twig

    (@stripytiger)

    Hi. Many thanks for this. I have tried it but it does not work as required – it may be me doing something wrong.

    I have added an action in my plugin class like this

    add_filter("forminator_custom_form_submit_errors", array($this,"ForminatorPreSubmit"),10,3);

    Then I have this.

     function ForminatorPreSubmit($submit_errors, $form_id, $field_data_array)
        {
            /** Do form_id check and any validation code here **/
    
            $submit_errors[] = "Stripy Tiger has detected an error";                    
            return $submit_errors;
        }

    This does stop the form submission, but the error displayed is

    Error: Your form is not valid, please fix the errors!

    And the form is then locked – so no changes can be made.

    Many thanks for helping me.

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @stripytiger,

    You can try something like this:

    add_action( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ){
    	
    		$submit_errors[]['custom_error'] = __('A new custom error.');
    	
    	return $submit_errors;
    }, 10, 3 );

    You can also check the following snippet as an example too:
    https://gist.github.com/patrickfreitasdev/12e75dd199799532875b319871904bf1

    Kind Regards,
    Nithin

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Validation on Submit’ is closed to new replies.