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.

gform_after_submission in backend and entry modification

  1. Dear all,

    I need to execute a PHP script once an entry is updated via the Wordpress backend and update a field in the current entry.

    First, I am trying to use the gform_after_submission hook but I needed to know if it was also executed when the entry is updated via Wordpress backend.

    Second, I would like to know what was an easy way to modify a field of an entry.

    Thanks!

    Posted 11 years ago on Tuesday October 30, 2012 | Permalink
  2. You should probably use the gform_after_update_entry hook to run your code after updating an entry: http://www.gravityhelp.com/documentation/page/Gform_after_update_entry

    I'm not clear on what you mean by easy way to modify a field of an entry. Do you mean edit the submitted value for one field in an entry, or do you mean modifying the field in a form?

    To edit an entry, there is a blue button on the right side of every entry which says "Edit". Is that what you're looking for?

    Posted 11 years ago on Wednesday October 31, 2012 | Permalink
  3. Hi Chris,

    Thanks for the hook! I'll try and get back to you.

    Sorry, I just realised I wasn't clear at all...
    Ok, let me tell you everything from the start as it could be a cool functionality for the plugin.
    - I added a status (eg Accepted, Refused) and a "last email sent" fields only viewable by the admins
    - when the admins change the status of the entry, it sends an email to the email field with the content corresponding to the status
    - it changes the "last email sent" field automatically with the date -> this is where I need an easy php way of changing the field content in the hook

    Thanks again Chris

    Cheers,

    Charles

    Posted 11 years ago on Tuesday November 6, 2012 | Permalink
  4. Charles, do you have any of this working now, or are you looking for a way to do all these things?

    Posted 11 years ago on Wednesday November 7, 2012 | Permalink
  5. I've added the field and the hook you gave me is the right one (THANKS).

    The only thing that I'd need is the way of easily accessing and modify the entry fields via some PHP functions (is there any?).

    Posted 11 years ago on Thursday November 8, 2012 | Permalink
  6. Can you explain more what you mean? Do you want to avoid editing the entry in the form builder and just write some code to update the entries in the database, or are you trying to do something different?

    Posted 11 years ago on Thursday November 8, 2012 | Permalink
  7. Ok, my the gform_after_update_entry hook is calling a function called update_entry.

    I need it to get the value of the "status" field of the entry so I can send the corresponding email to the "email" field.

    And change the "last email sent" field with the value "[status] [current date]".

    What I need is the correct getters and setters to retrieve and modifying the field values. Maybe through the RGFormsModel?

    Posted 11 years ago on Thursday November 8, 2012 | Permalink
  8. Sorry, need more coffee this morning.

    So, your administrator will edit the entry and change the status (is status a field in your form and entry, or are you using the "starred" function or something similar, in Gravity Forms?) Then you are using the gform_after_update_entry to run some code. The code needs to get the value which is stored in the status field, and also update the entry to add "[status] [current date]" in one of the fields in the entry?

    Is that all accurate?

    Posted 11 years ago on Thursday November 8, 2012 | Permalink
  9. Ha ha ha no worries. Me too!

    I created a STATUS field (dropdown).
    And a LAST EMAIL SENT field which is a text field that I wand to fill out automatically when an email is sent with something like "REFUSED sent the 2012-10-01"

    You forgot the email sent to the person who filled out the form.
    The email depends on the status that the admin has chosen.

    I can to all of that but I just need the correct functions e.g.

    get_field_value($form_id, $entry, $field_id)
    set_field_value($form_id, $entry, $field_id)

    Is there any in the API?

    Posted 11 years ago on Friday November 9, 2012 | Permalink
  10. Hi Chris,

    Any help?

    Posted 11 years ago on Tuesday November 13, 2012 | Permalink
  11. Hi Chris,

    Really need support on this one....

    Posted 11 years ago on Monday November 19, 2012 | Permalink
  12. Charles, please send me an email at chris@rocketgenius.com and include a link to this topic.

    Posted 11 years ago on Monday November 19, 2012 | Permalink
  13. Email sent!

    Posted 11 years ago on Tuesday November 20, 2012 | Permalink
  14. I tried this but no luck...

    http://pastie.org/5410767

    Should it work? Would it work with radio fields?
    Is there a set_field_value method?

    Posted 11 years ago on Wednesday November 21, 2012 | Permalink
  15. Woops:

    add_action("gform_after_update_entry", "update_entry", 10, 2);
    function update_entry($form, $entry_id){
    
    	$lead = RGFormsModel::get_lead($entry_id);
    	$value = RGFormsModel::get_field_value_long($lead, 1, $form, false);
    
    }
    Posted 11 years ago on Wednesday November 21, 2012 | Permalink
  16. Dear team,

    I still did not get any answer...
    I really need this support.
    I am trying to find a way but I am still stuck...

    Posted 11 years ago on Thursday November 22, 2012 | Permalink
  17. FINALLY FOUND A PARTIAL SOLUTION!!!

    To get the field value:

    add_action("gform_after_update_entry", "update_entry", 10, 2);
    function update_entry($form, $entry_id){
    
    	$lead = RGFormsModel::get_lead($entry_id);
    $field = RGFormsModel::get_field($form, [the field ID]);
    $brand = RGFormsModel::get_lead_field_value($lead, $field);
    
    }

    Now, looking for the next step: updating a field value!

    Posted 11 years ago on Thursday November 22, 2012 | Permalink
  18. You are going to have to resort to some "direct to database" calls I think. I've used this before:

    [php]
    $wpdb->update("{$wpdb->prefix}rg_lead_detail", array(
    	'value' => $your_value,
    	'field_number' => $field_number,
    	'lead_id' => $entry['id'],
    	'form_id' => $entry['form_id']
    ));
    Posted 11 years ago on Friday November 23, 2012 | Permalink
  19. Thank you friendo!
    Works like a charm.

    Here's my code if anyone need it:

    add_action("gform_after_update_entry", "update_entry", 10, 2);
    function update_entry($form, $entry_id){
    	$lead = RGFormsModel::get_lead($entry_id);
    
    	$company_field = RGFormsModel::get_field($form, [your company field ID]);
    	$company = RGFormsModel::get_lead_field_value($lead, $company_field);
    
    	$status_field = RGFormsModel::get_field($form, [your status field ID]);
    	$status = RGFormsModel::get_lead_field_value($lead, $status_field);
    
    	$contact_email_field = RGFormsModel::get_field($form, [your contact email field ID]);
    	$contact_email = RGFormsModel::get_lead_field_value($lead, $contact_email_field);
    
    	$send_email_field = RGFormsModel::get_field($form, [your send email field ID]);
    	$send_email = RGFormsModel::get_lead_field_value($lead, $send_email_field);
    
    	// Send a notification email to the admin
    	$to = blog_info( "admin_email" );
    
    	$headers = 'From: [Your Company Name] <'.$to.'>' . "\r\n";
    
    	$subject = "The status of entry ".$company." has changed.";
    
    	$message = "The status of brand ".$company." has changed to ".$status."\n\n";
    
    	if ( $send_email == "Yes" )
    		$message .= "An email was sent.";
    	else
    		$message .= "No email was sent.";
    
    	wp_mail($to, $subject, $message, $headers);
    	// End of amdin notification email
    
    	// Send an email to the client that filled the form
    	$headers = 'From: [Your Company Name] <'.$to.'>' . "\r\n";
    
    	$today = date("F j, Y, g:i a");
    	$last_sent_text = '';
    
    	// Check if the admin wants to send an email and send the corresponding email
    	if ( $send_email == "Yes" && $status == [the status] ) {
    		$subject = [Email subject];
    
    		$message = [Email content];
    
    		wp_mail($contact_email, $subject, $message, $headers);
    
    		$last_sent_text = $status." the ".$today;
    	}
    	else if ( $send_email == "Yes" && $status == [other status] ) {
    		[other email]
    		...
    	}
    
    	// If an email was sent, update the Last Sent Email and Send Email values
    	if ( $send_email == "Yes" )
    	{
    		global $wpdb;
    
    		// Update Last Sent Mail field
    		if ( !$wpdb->update(
    				$wpdb->prefix."rg_lead_detail",
    				array('value' => $last_sent_text),
    				array('field_number' => [your last sent email field ID],
    					'lead_id' => $entry_id,
    					'form_id' => $form['id']
    				)
    				)
    			)
    		{
    			// If update returns false, create the field
    			$wpdb->insert(
    				$wpdb->prefix."rg_lead_detail",
    				array('value' => $last_sent_text,
    					'field_number' => [your lest sent email field ID],
    					'lead_id' => $entry_id,
    					'form_id' => $form['id']
    				)
    			);
    		}
    
    		// Update Send Email field to "No" (to make sure that emails are not sent by mistake)
    		$wpdb->update(
    			$wpdb->prefix."rg_lead_detail",
    			array('value' => "No"),
    			array('field_number' => [your send email field ID],
    				'lead_id' => $entry_id,
    				'form_id' => $form['id']
    			)
    		);
    	}
    }
    Posted 11 years ago on Friday November 23, 2012 | Permalink
  20. David Peralty

    Glad to hear it.

    Posted 11 years ago on Friday November 23, 2012 | Permalink

This topic has been resolved and has been closed to new replies.