Support » Plugin: Ninja Forms - The Easy and Powerful Forms Builder » Hooking does not seem to work?

  • Resolved M

    (@imlongcat)


    Probably my own fault somehow, but if somebody could take 2 minutes and help me with this it would be awesome:

    I more or less copied an example for a hook into the functions.php of my theme.

    add_action( 'init', 'ninja_forms_register_example' );
    	function ninja_forms_register_example(){
    		add_action('ninja_forms_post_process', 'ninja_forms_example');
    	}
    
    	function ninja_forms_example(){
    		global $ninja_forms_processing;
    
    		//Add the text Hello World to the user value.
    		$user_value = "Hello World.";
    
    		//Update the user submitted value for the field with an ID of 11:
    		$ninja_forms_processing->update_field_value( 11, $user_value );
    		$ninja_forms_processing->update_field_value( 2, 1 );
    
    	}

    The add_action seems to work, i put an echo command into the ninja_forms_register_example and it shows up on the page. However the second part does not work. Field 11 is a text field, so it should work. Field 2 is a radio button with 5 choices, so value 1 should be valid as well?! I can also change ninja_forms_post_process for other hooks but it doesn’t change the outcome, sometimes the “Processing..” will just show up and nothing will happen further.

    What am i doing wrong?

    http://wordpress.org/extend/plugins/ninja-forms/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Kevin Stover

    (@kstover)

    Hey. If you want to modify field values, you’ll want to use the ninja_forms_pre_process hook. The ninja_forms_post_process hook fires after all the processing has been completed.

    M

    (@imlongcat)

    I just used this as an example and already tried ninja_forms_pre_process and the other ones as well. Not even an echo(“…”) will work in the ninja_forms_example.

    Plugin Author Kevin Stover

    (@kstover)

    The pre_process, process, and post_process hooks only fire when the form has been submitted. To fully test the echoing, you’ll need to disable ajax submissions, replace the echo in your code above, and submit your form. This will reload the page (because ajax will be turned off) and allow the processing hooks to fire.

    M

    (@imlongcat)

    Tried Ajax on and off already. I also have a submit button so the hooks should fire. Hm.. but in general the code is alright?

    Plugin Author Kevin Stover

    (@kstover)

    It looks ok. Are you sure that the hooks aren’t firing after you click the submit button?

    Plugin Author Kevin Stover

    (@kstover)

    The only thing I see is that the function is passed the $form_id as a variable. so your function would become ninja_forms_example( $form_id ). I don’t think that would cause what you’re seeing, though.

    M

    (@imlongcat)

    It looks ok. Are you sure that the hooks aren’t firing after you click the submit button?

    I don’t know how i would test this other than using an echo or changing form values?

    The only thing I see is that the function is passed the $form_id as a variable. so your function would become ninja_forms_example( $form_id ). I don’t think that would cause what you’re seeing, though

    Doesn’t change anything :/

    Plugin Author Kevin Stover

    (@kstover)

    I’ve tried your code snippet on my local host and can’t find any problems with it. It shouldn’t affect anything, but what version of Ninja Forms are you using?

    M

    (@imlongcat)

    Oh thanks for the effort, i forgot about looking here. I had the newest version of NinjaForms at the time i made this post but now updated to the current version. Will try again and come back with results.
    I also have the current WP version (in german, but i don’t think that matters).

    M

    (@imlongcat)

    It works now! I don’t know why, but i installed NinjaForms on a new wordpress locally and here it works without problems. Thank you so much for your help!

    Plugin Author James Laws

    (@jameslaws)

    That’s awesome! Really glad to hear it.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Hooking does not seem to work?’ is closed to new replies.