Input gravity forms entries in a database locally stores (created with python)

2024/9/22 7:32:53

I hope you are all doing alright.

Is it possible to connect a gform entry to a database created with Python and stored in my PC with a little variation of the following code?

add_action("gform_after_submission_1", "input_fields", 10, 2);
function input_fields($entry, $form)
{$password = "password";$username = "username";$servername = "localhost";$dbname = "db";$fname = $entry["12.3"];$lname = $entry["14.6"];$email = $entry["4"];$address1 = $entry["5.1"];$address2 = $entry["15.2"];$city = $entry["16.3"];$state = $entry["18.4"];$zip = $entry["17.5"];$bbd = $entry["7"];$upc = $entry["6"];$subject = $entry["10"];$question = $entry["2"];$con=mysqli_connect($servername, $username, $password, $dbname);
mysqli_query($con,"INSERT INTO wp_contacts (id, name, last_name, 
state, city, address, address_2, bbd, subscribe, upc, email, subject, 
comments, phone, user_ip, answer, answered_by, zipcode, category_id, 
active, contact_captcha, answered_date, dept, computer_name, created) 
VALUES ('', '$fname', '$lname', '$state', '$city', '$address1', 
'$address2', '$bbd', '', '$upc', '$email', '$subject', '$question', 
'', '', '', '', '$zip', '', '', '', '', '', '', '')");
}

I have tried creating a snippet with the following PHP code:

add_action("gform_after_submission_1", "input_fields", 10, 2);
function input_fields($entry, $form)
{
$dbname = "forms.db";
$fname = $entry["12.3"];
$lname = $entry["14.6"];$con=mysqli_connect($fileadres);
mysqli_query($con,"INSERT INTO vragenlijst (f_name, l_name,) 
VALUES ('$fname', '$lname');}

Any help will be much appreciated.

Answer

This should definitely be possible! I think the best option for you would be to implement a custom Feed. Feeds essentially allow you to pipe any data from a form entry to another location, in your case, the local DB you created in Python.

In order to facilitate this, you'd likely want to create a new GFFeedAddon class. This class provides methods to do all sorts of add-on related things, but specifically you'll want to look at overriding the process_feed() method (scroll down to the "Processing Feeds" section of the docs page I linked above).

Within this method, you'll have access to all of the values submitted, which you can access via $this->get_field_value(). Once you have the values you want to work with, it's just a matter of connecting to your local Python database using whatever method you want and storing the values you retrieved from the entry.

https://en.xdnf.cn/q/119615.html

Related Q&A

Cant get javascript generated html using python

Im trying to create a python script that automatically gets the content of a table on a webpage. I manage to have it to work on pure html page, but there is one website that gives me headache... The ht…

Python: Extract text from Word files in a url

Given the url containing a certain file, in this case a word document, read the contents of the document. I have seen several examples of how to extract text from local documents but not from a url. Wo…

Python3:Plot f(x,y), preferably using matplotlib

Is there a way, preferably using matplotlib, to plot a 2-variable function f(x,y) in python; Thank you, in advance.

Why does my cronjob not send the email from my script? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

How to delete unsaved tkinker label?

I made this program where I am putting labels on a grid without saving them in a variable. I do this because then I can for loop through a list of classes and get the data from each class in and add th…

Adjust every other row of a data frame

I would like to change every second row of my data frame.I have a df like this:Node | Feature | Indicator | Value | Class | Direction -------------------------------------------------------- 1 | …

Why is the list index out of range?

Im new at programing and Im trying to check a piece of code that keeps giving me this error: t[i] = t[i - 1] + dt IndexError: list index out of rangeThe code is the following: dt = 0.001t = [0] for i i…

Stopping a while loop mid-way - Python

What is the best way to stop a while loop in Python mid-way through the statement? Im aware of break but I thought using this would be bad practice.For example, in this code below, I only want the pro…

Click on element in dropdown with Selenium and Python

With Selenium and Chrome webdriver on MacOS need to click dropdown element. But always have an error that cant find. Have this html code on a page where it located:<select id="periodoExtrato&qu…

Send cv2 video stream for face recognition

Im struggling with a problem to send a cv2 videostream (webcam) to a server (which shall be used later for face recognition). I keep getting the following error for the server: Traceback (most recent c…