使用php从elementor webhook提取数据

使用php从elementor webhook提取数据,php,html,wordpress,webhooks,elementor,Php,Html,Wordpress,Webhooks,Elementor,我正在尝试将数据元素从提交表单中获取到MySql数据库。我已经通过本地方式连接到数据库。但是现在我想从网页的webhook获取数据,我无法检索数据。这是我的密码: <!doctype html> <html> <body> <?php //Data Base connection info: $servername = "localhost"; $username = "username";

我正在尝试将数据元素从提交表单中获取到MySql数据库。我已经通过本地方式连接到数据库。但是现在我想从网页的webhook获取数据,我无法检索数据。这是我的密码:

<!doctype html>
<html>
<body>


    <?php
        //Data Base connection info:
        $servername = "localhost";
        $username = "username"; 
        $password = "password";
        $dbName="dbName";

        ////////////////////////////Retrieved information from form ////////////////////////////////////////////
        $name=$email=$telephone=$message="";
                              ///////Data Obtained in the form:////////////
        if($_SERVER["REQUEST_METHOD"] == "POST") {
        $name=$_POST["No Label name"];
        $email=$_POST["No Label email"];
        $telephone=$_POST["No Label phone"];
        $message=$_POST["No Label message"];;


        //////////////////////////////////////////// DATA BASE CONNECTION ///////////////////////////////////////


        // Create connection with DB.

        $conn = mysqli_connect($servername, $username, $password, $dbName);
        //////////////////////////// Check connection ///////////////////////////////////
        if (!$conn) {
            die("Connection failed: " . mysqli_connect_error());
        }
        $sql="INSERT INTO TableName (Name, Email, Phone, Menssage ,Contacted) VALUES (?, ?, ?, ?,0)";
        $stmt=$conn->prepare($sql);
        $stmt->bind_param("ssss", $name, $email, $telephone, $message);
        $stmt->execute();
        mysqli_close($conn);
        }

    ?>
</body>
</html>

“无标签名称”的出现是因为我不想改变网页的外观。请求箱 向我显示了正在发送的阵列的标签

我也尝试过此解决方案,但不起作用:

<!doctype html>
<html>

<body>


    <?php
        //Data Base connection info:
        $servername = "localhost";// has to be changed to the actual host
        $username = "username"; 
        $password = "password";
        $dbName="dbName";//we need to add the data base name

        ////////////////////////////Retrieved information from form ////////////////////////////////////////////
        $name=$email=$telephone=$message="";
                              ///////Data Obtained in the form:////////////
        $Rawdata = file_get_contents("php://input");
        $data = json_decode($Rawdata, true); 
        $name=$data["No Label name"];
        $email=$data["No Label email"];
        $telephone=$data["No Label phone"];
        $message=$data["No Label message"];

        //////////////////////////////////////////// DATA BASE CONNECTION ///////////////////////////////////////


        // Create connection with DB.

        $conn = mysqli_connect($servername, $username, $password, $dbName);
        //////////////////////////// Check connection ///////////////////////////////////
        if (!$conn) {
            die("Connection failed: " . mysqli_connect_error());
        }
        $sql="INSERT INTO TableName (Name, Email, Phone, Menssage ,Contacted) VALUES (?, ?, ?, ?,0)";
        $stmt=$conn->prepare($sql);
        $stmt->bind_param("ssss", $name, $email, $telephone, $message);
        $stmt->execute();
        mysqli_close($conn);


    ?>
</body>
</html>

如果他们对代码或变量有任何疑问,请询问。 我还有一个问题,elementors webhooks是否以json或普通POST方法发送数据。
webhook表单中的字段通过一个名为Ajax\u Handler的类传递,该类在
wp content/plugins/elementor pro/modules/forms/classes/Ajax Handler.php
中定义

虽然我没有在这里多做探讨,但看看我的PHP服务器接收到了什么,它会发送两个POST参数,如果我在Webhook部分将Advanced Data选项切换为yes,至少会这样做:

参数“form”是一个数组,其中包含键“id”和“name”,这是webhook调用所源自的表单的属性。“id”通常是自动生成的,但可以在附加选项区域中设置,“name”是表单字段部分中的表单名称属性

参数“fields”是表单字段本身的数组。创建的每个表单字段都显示为另一个数组的键,该数组包含以下内容:

'id' => the form field ID you set in Elementor
'type' => the type of field (text, email etc.)
'title' => the label for the field
'value' => the actual value in the input element
'raw_value' => not sure how this differs from 'value'...
'required' => whether the field was marked as required.
例如,我有一个名为NewsSubscriber的表单,其中有两个字段“email”和“name”,还有一个隐藏字段“fn”,告诉服务器该做什么,因此我在PHP脚本中得到以下内容:

$_POST=>[
  'form' => [
    'id' => '5cbb571',
    'name' => 'NewsSubscriber'
  ],
  'fields' => [
    'email' => [
      'id' => 'email',
      'type' => 'email',
      'title' => 'Email Address',
      'value' => 'person@example.com',
      'raw_value' => 'person@example.com',
      'required' => '1'
    ],
    'name' => [
      'id' => 'name',
      'type' => 'text',
      'title' => 'Name',
      'value' => 'Bob Person',
      'raw_value' => 'Bob Person',
      'required' => '1'
    ],
    'fn' => [
      'id' => 'fn',
      'type' => 'hidden',
      'title' => 'Function',
      'value' => 'add',
      'raw_value' => 'add',
      'required' => '0'
    ]
  ]
]

因此(通过一些检查),我可以将函数提取为
$\u POST['fields']['fn']['value']
、来自
$\u POST['fields']['email']['value']
的电子邮件以及来自
$\u POST['fields']['name']['value']

webhook表单中的字段通过一个名为Ajax\u Handler的类传递,该类在
wp content/plugins/elementor pro/modules/forms/classes/Ajax Handler.php
中定义

虽然我没有在这里多做探讨,但看看我的PHP服务器接收到了什么,它会发送两个POST参数,如果我在Webhook部分将Advanced Data选项切换为yes,至少会这样做:

参数“form”是一个数组,其中包含键“id”和“name”,这是webhook调用所源自的表单的属性。“id”通常是自动生成的,但可以在附加选项区域中设置,“name”是表单字段部分中的表单名称属性

参数“fields”是表单字段本身的数组。创建的每个表单字段都显示为另一个数组的键,该数组包含以下内容:

'id' => the form field ID you set in Elementor
'type' => the type of field (text, email etc.)
'title' => the label for the field
'value' => the actual value in the input element
'raw_value' => not sure how this differs from 'value'...
'required' => whether the field was marked as required.
例如,我有一个名为NewsSubscriber的表单,其中有两个字段“email”和“name”,还有一个隐藏字段“fn”,告诉服务器该做什么,因此我在PHP脚本中得到以下内容:

$_POST=>[
  'form' => [
    'id' => '5cbb571',
    'name' => 'NewsSubscriber'
  ],
  'fields' => [
    'email' => [
      'id' => 'email',
      'type' => 'email',
      'title' => 'Email Address',
      'value' => 'person@example.com',
      'raw_value' => 'person@example.com',
      'required' => '1'
    ],
    'name' => [
      'id' => 'name',
      'type' => 'text',
      'title' => 'Name',
      'value' => 'Bob Person',
      'raw_value' => 'Bob Person',
      'required' => '1'
    ],
    'fn' => [
      'id' => 'fn',
      'type' => 'hidden',
      'title' => 'Function',
      'value' => 'add',
      'raw_value' => 'add',
      'required' => '0'
    ]
  ]
]

因此(通过一些检查),我可以将函数提取为
$\u POST['fields']['fn']['value']
,来自
$\u POST['fields']['email']['value']
的电子邮件和来自
$\u POST['fields']['name']['value']

绝对救生圈!:-)绝对救生员!:-)