• Resolved dinesh2018wp

    (@dinesh2018wp)


    I need to get form’s fields data of submitted/current form on form submission

    I trying with these hooks
    forminator_form_after_handle_submit/forminator_form_after_save_entry

    trying this

    add_action( ‘forminator_form_after_save_entry’, ‘function_Name’ );
    function function_Name( $form_id, $response ) {
      // code here
    }

    but when submitting form get this issue

    An error occurred while processing the form. Please try again

    log error

    PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function function_Name(), 1 passed in D:\xampp\htdocs\sos_wp\wp-includes\class-wp-hook.php on line 312 and exactly 2 expected in D:\xampp\htdocs\sos_wp\wp-content\themes\sos-theme\functions.php:86

    can someone help with this
    Thanks
    Dinesh

    • This topic was modified 2 years, 9 months ago by dinesh2018wp.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @dinesh2018wp ,

    Can you share your full code? It seems that it is missing one argument: $form_id or $response, hence the Too few arguments to function function_Name() error.

    kind regards,
    Kasia

    Thread Starter dinesh2018wp

    (@dinesh2018wp)

    @wpmudev-support2

    I am missing argument in add action, it shoud be like this

    add_action( 'forminator_form_after_save_entry', 'function_Name', 10, 2 );
    
    function function_Name($form_id, $response) {
    
        error_log(print_r($response['select_field'], true));
    
        $entry = Forminator_Form_Entry_Model::get_latest_entry_by_form_id( $form_id );
    
    error_log(print_r($entry, true));
    
    }

    $response doesn’t return the form fields

    log of $response

    Array
    (
        [message] => Thank you for contacting us, we will be in touch shortly.
        [success] => 1
        [form_id] => 19
        [behav] => behaviour-thankyou
        [fadeout] => true
        [fadeout_time] => 5000
        [select_field] => Array
            (
            )
    
    )

    to get form fields using this

    $entry = Forminator_Form_Entry_Model::get_latest_entry_by_form_id( $form_id );

    this return the fields of last submitted form but this may cause issue when 2 more form summitted at same time , will you please help with correct way to get summited form fields

    Thread Starter dinesh2018wp

    (@dinesh2018wp)

    I can get form feilds with $_POST

    is this correct way ?

    Plugin Support Dmytro – WPMU DEV Support

    (@wpmudevsupport16)

    Hello @dinesh2018wp,

    I hope you’re doing well today!

    Yes, you can find the field data in $_POST, and additional info (e.g. default options) by using get_post_meta().

    You can also use $form_id to apply your code to a particular form. Please test the following example (replace 111 with your form ID):

    add_action( 'forminator_form_after_save_entry', 'function_Name', 10, 2 );
    
    function function_Name( $form_id, $response ){
    	if( $form_id != 111 ){ // change this number to your form ID
    		return;
    	}
    
    	$form_meta = get_post_meta($form_id, 'forminator_form_meta', true);
    	if( $form_meta ){
    		if( isset( $form_meta['fields'] ) ){
    			error_log(print_r($form_meta['fields'], true));
    		}
    		
    		if( isset( $_POST ) ){
    		    error_log(print_r($_POST, true));
    		}
    	}
    	
    }

    Let us know if you have any questions.

    Best Regards,
    Dmytro

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @dinesh2018wp ,

    We haven’t heard from you for over 2 weeks now, so it looks problem was solved with the above code.

    Feel free to re-open this topic if needed.

    Kind regards
    Kasia

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Get form fields data on form submission’ is closed to new replies.