WordPress insert Gravity Form data into new table

2020-06-28 03:54发布

I have a WordPress site that I am using a gravity form. I would like to take one of the gravity forms I am using and insert the data into another table. (Besides the gravity form table). I am using the Gravity Form after submission hook to grab the values of my specific form (3) and run a SQL statement. Here is a link explaining about the hook: http://www.gravityhelp.com/documentation/page/Gform_after_submission

However, nothing gets inserted into the new table (users). I can't even tell if the script is running. Both the "default" gravity form table and my new users table are in the same database. Here's what my PHP looks like:

add_action("gform_after_submission_3", "input_fields", 10, 2);
function input_fields($entry, $form){


                    $entry["1"] = '$name';
                    $entry["2"] = '$email';
                    $entry["3"] = '$purchase_date';
                    $entry["4"] = '$order_number';

   $SQL = "INSERT INTO users ( userID, email, name, purchase_date, order_number) VALUES ( '', '$email' , '$name', '$purchase_date', '$order_number')";
   }

I'm grabbing the values using the Gravity Form entry object. More info about that here: http://www.gravityhelp.com/documentation/page/Entry_Object

The form writes to the default table alright but not to my new "users" table. Any suggestions? Let me know if I need to give more info. Thanks for any help!

2条回答
干净又极端
2楼-- · 2020-06-28 04:35

You have created the query but you are not executing it.

add_action("gform_after_submission_3", "input_fields", 10, 2);
function input_fields($entry, $form){
    global $wpdb;


                    $entry["1"] = '$name';
                    $entry["2"] = '$email';
                    $entry["3"] = '$purchase_date';
                    $entry["4"] = '$order_number';

   $SQL = "INSERT INTO users ( userID, email, name, purchase_date, order_number) VALUES ( '', '$email' , '$name', '$purchase_date', '$order_number')";
   $wpdb->query($SQL);
   }

Also I assume that you have already created the users table.

查看更多
可以哭但决不认输i
3楼-- · 2020-06-28 04:49

Try this following code...

add_action('gform_after_submission_3', 'input_fields', 10, 2);
function input_fields($entry, $form){
global $wpdb;
               $name = $entry['1'];
               $email = $entry['2'];
               $purchase_date =  $entry['3'];
               $order_number = $entry['4'];

  $SQL = "INSERT INTO users ( userID, email, name, purchase_date, order_number) VALUES ( '', '$email' , '$name', '$purchase_date', '$order_number')";
  $wpdb->query($SQL);
 }

Thank you....

查看更多
登录 后发表回答