WordPress.org

Ready to get started?Download WordPress

Forums

Ninja Forms
[resolved] Hooking does not seem to work? (12 posts)

  1. imlongcat
    Member
    Posted 1 year ago #

    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/

  2. Kevin Stover
    The WP Ninjas
    Plugin Author

    Posted 1 year ago #

    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.

  3. imlongcat
    Member
    Posted 1 year ago #

    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.

  4. Kevin Stover
    The WP Ninjas
    Plugin Author

    Posted 1 year ago #

    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.

  5. imlongcat
    Member
    Posted 1 year ago #

    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?

  6. Kevin Stover
    The WP Ninjas
    Plugin Author

    Posted 1 year ago #

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

  7. Kevin Stover
    The WP Ninjas
    Plugin Author

    Posted 1 year ago #

    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.

  8. imlongcat
    Member
    Posted 1 year ago #

    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 :/

  9. Kevin Stover
    The WP Ninjas
    Plugin Author

    Posted 1 year ago #

    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?

  10. imlongcat
    Member
    Posted 1 year ago #

    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).

  11. imlongcat
    Member
    Posted 1 year ago #

    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!

  12. James Laws
    The WP Ninjas
    Plugin Author

    Posted 1 year ago #

    That's awesome! Really glad to hear it.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic