PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Run php code upon sumbission?

  1. jn19
    Member

    I need to know how to call a php file when the user clicks submit on a form. In this case the form is simply an email address field. I want to add the email address to a database automatically. I have the php code to do this, but I don't know how to get the submit button to call it.

    Posted 13 years ago on Friday April 8, 2011 | Permalink
  2. You can't call a PHP file the way you are probably thinking you'd like to do it. You have to use a Gravity Forms API hook to then execute your custom PHP and do whatever you want with the form data. This custom PHP would go in your themes functions.php file.

    You would use the gform_post_submission hook which has access to the entry object containing the form data. You'd use this hook to execute your custom PHP to do whatever you want to do with the data.

    Here is a forum posts that discusses this:

    http://www.gravityhelp.com/forums/topic/sms-api-gateway-need-help-to-get-gform-to-integrate#post-18087

    The gform_post_submission hook is also documented in the Documentation in the Developer Docs area.

    Posted 13 years ago on Friday April 8, 2011 | Permalink
  3. Sbyrakis
    Member

    Hi Carl,

    I tried to implement the specific action, however it seems that it does not return the $entry object. As you see in the code below, I am iring the action (gform_post_submission) after the action (bp_artwork_submit_content) that actually submits the form.

    function bp_artwork_submit() {
    	global $bp; 
    
    	do_action( 'bp_artwork_submit' );
    	add_action( 'bp_template_title', 'bp_artwork_submit_title' );
    	add_action( 'bp_template_content', 'bp_artwork_submit_content' );
    	add_action('gform_post_submission', 'get_post_submit_info_to_activity', 10, 2);
    	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    	}

    The PHP code itself that should get the object is:

    function get_post_submit_info_to_activity($entry, $form){
        global $bp, $entry;
    	//getting post
    	$post_submit_info = array(
    		'action' => 'submitted an artwork',
    		'type' => 'artwork_submission',
    		'user_id' => $bp->loggedin_user->id,
    		);
    	bp_artwork_record_activity($post_submit_info);
    	}

    The problem is that I can not get any values out of the $entry array. Can this be related to the redirection after posting the form?

    Posted 13 years ago on Sunday April 10, 2011 | Permalink
  4. Sbyrakis
    Member

    Hi, I fixed it, removed from the get_post_submit_info_to_activity function the global reference for $entry

    Posted 13 years ago on Monday April 11, 2011 | Permalink