1

I have a form through the jQuery Form Wizard, all the sections work fine and the last tab gives the user the chance to look over the inputs before submit.

On Submit I have put the below code to send the data to the database. My issue is that the POST data doesnt get to the database, a row is inserted, but it is a blank row.

I've tested the Insert and have manually input data so that when the Submit is clicked this is input into the db.

How can I get the data from the form into the database?

$('#form_myform1').find('.button-previous').hide();
        $('#form_myform1 .button-submit').click(function (e) {
            $.ajax({
                url:'includes/myforms/myforms_form1.php',
                data:$(this).serialize(),
                type:'POST',
                success:function(data){
                    console.log(data);
                    $(".alert-success").show().fadeOut(5000);
                },
                error:function(data){
                    $(".alert-danger'").show().fadeOut(5000);
                }
            });
        }).hide();

My PHP POST code (Yes I know it's not PDO ;-) I have other issue with PDO and my init.php file on from this location hence using mysql_ for now.)

<?php
require '../../assets/functions/core/cnn.php';

if(!empty($_POST['appraisename'])) {
    $appraisename = htmlspecialchars(trim($_POST["appraisename"]));
}

$form1sql = "INSERT INTO myforms_personaldetails (name)
            VALUES('".$appraisename."') ";
    mysql_query($form1sql) or die(mysql_error());
?>
4

2 回答 2

2

你的问题是那行读取data:$(this).serialize(),. 该this行中的指的是按钮,而不是表单...

将该行更改为:

data:$("#form_myform1").serialize(),- 这应该可以正常工作。

但是,在您的情况下,这似乎仍然返回空白。

所以,既然你只使用一位数据,无论如何 - 只需明确设置数据:

data : { apprasename : $("#idOfYourInputBox").val() }

根据为什么serialize()不起作用---我需要查看表单标记......

于 2014-11-14T19:47:31.777 回答
1

我现在工作的 Ajax 代码

$('#form_myform1').find('.button-previous').hide();
    $('#form_myform1 .button-submit').click(function (e) {
        $.ajax({
            url:'includes/myforms/myforms_form1.php',
            data:$('#submit_form').serialize(),
            //data : { appraiseid : $("#appraiseid").val() },
            type:'POST',
            success:function(data){
                console.log(data);
                $(".alert-success").show().fadeOut(5000);
            },
            error:function(data){
                $(".alert-danger'").show().fadeOut(5000);
            }
        });
    }).hide();
于 2014-11-15T22:40:37.283 回答