2

我正在尝试通过 AJAX 提交 wufoo 表单。我正在使用 jQuery $.post 来实现这一点,并从 php 脚本返回 500(内部服务器错误)。javascript代码是:

$('form#form20').submit(function(event){
    event.preventDefault();
    $.post('form_handler.php', $('form#form20').serialize(), function(response) {
        console.log(response);
    });
});

form_handler.php 文件中的 php 代码是:

<?php  
    if (count($_POST) > 0) {
        $fieldErrors = initAPI($root);
    }
    $wufoo_query_vals = array(
        'w_api_key' => 'xxxx-xxxx-xxxx-xxxx',
        'w_form' => 'connect-with-us',
        '1' => $_POST['Field1'],
        '2' => $_POST['Field2'],
        '3' => $_POST['Field3'],
        '4' => $_POST['Field4'],
        '5' => $_POST['Field5'],
        '11' => $_POST['Field11'],
        '14' => $_POST['Field14'],
        '13' => $_POST['Field13'],
        '8' => $_POST['Field8'],
        '9' => $_POST['Field9']
    );

    foreach($wufoo_query_vals as $key => $value) {
        $request .= $key.'='.urlencode($value).'&';
    }
    $request = substr($request, 0, -1);
    $ch = curl_init("http://defineyouredge.wufoo.com/api/insert/"); 
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    $response = curl_exec($ch);
    curl_close ($ch);

    echo $response;  
?>

出于显而易见的原因,我删除了 API 密钥,但我确实在实际代码中正确输入了它。另外,我还没有完成处理响应的功能。目前,只需将响应记录到控制台进行测试。

非常感谢您的支持!

4

0 回答 0