Couple things to make this work.
This line:
add_action("gform_post_submission_1", "post_submission", 10, 2);
You need to change the "post_submission" there to the name of your function. You're hooking YOUR function to the "gform_post_submission" action. Since the name of your function is store_in_db2 the line above should look like this:
add_action("gform_post_submission_1", "store_in_db2", 10, 2);
Otherwise, your function will never run.
Also in that line: this hook will be run for form #1 only (that's the _1 added to the end of the hook name.) Be sure the ID of your form is 1. If not, change this number to match your form.
Finally, in the same line, you're saying that 2 arguments are accepted (that's what the 2 at the end is.) So, you should call your function with 2 arguments. This line:
function store_in_db2($entry){
Should look like this:
function store_in_db2($entry, $form){
After that, you will be able to get all the values from your form submission. You can determine the field id to use by looking at the source of a rendered page. For the name field, if you're using a name field, the ID might look like this:
<input type='text' name='input_1.3' id='input_12_1_3' value='' tabindex='1' />
<input type='text' name='input_1.6' id='input_12_1_6' value='' tabindex='2' />
In that case, the values you want are 1.3 and 1.6. Maybe it's not clear from this example that input_12_1_3 becomes 1.3, but if you dump the $entry array, you will see this:
[1.3] => Chris2
[1.6] => Hajer2
[2.1] => 1234 Maple
[2.3] => Berwyn
[2.4] => IL
[2.5] => 60402
[2.6] => United States
[3] => this is my awesome comment
That is part of a submission I made with this form:
http://gravity.chrishajer.com/testing-the-post/
If you look at the source of the page, you will see the input_12_1_3 and input_12_1_6 I referenced above, and how they correlate to the [1.3] and [1.6] in the $entry object.
In your MySQL query line, if your form were identical to mine, you would do this: [EDITED 9/2/2011]
[php]
$query = 'INSERT INTO affiliates (FirstName, LastName) VALUES (\''. $entry['1.3'] . '\', \'' . $entry['1.6'] . '\')';
mysql_query($query);
For me, that resulted in this query being generated:
INSERT INTO affiliates (FirstName, LastName) VALUES ('Chris2', 'Hajer2')
Replace the 1.3 and 1.6 with the id of the form fields from your form and you'll be good to go. Please post if you need more assistance, or if this works out for you. Thanks.
Posted 13 years ago on Tuesday August 2, 2011 |
Permalink