0

我使用 ajax 和 php 创建了一个表单。从主页,用户可以编辑客户详细信息,或添加新客户。当用户单击编辑客户端按钮时,使用 ajax 加载表单,并使用 id 插入客户端详细信息,对于添加新客户端,不发送任何 id。我想知道的是,如何更改添加客户端的“提交”按钮和编辑客户端的“更新”按钮。两个阶段的表单标记相同,但这里是用于区分两者的 jquery:

添加:

$.ajax({
    dataType: "html",
    url: "ajax.php?action=client_form",
    beforeSend: function() {
        $('.error, .success, .notice').remove();
    },
    success: function(html) {
        $('#users-contain_t').html(html);
    }
});

对于编辑部分,我创建了一个函数,如下所示:

function editClient(client_id){

    $('#users-contain_t').load('ajax.php?action=client_form&client_id='+client_id);

};

编辑按钮的标记是:

<button class="editClient" type="button" onclick="editClient('.$client['client_id']. ')">Edit Client</button>

这将显示表单中的详细信息。我想知道的是,如何在同一个表单上加载两个不同的按钮,在编辑时,以及在添加新记录时,使用 php?

这两个按钮的标记类似于:

<button id="updateList" type="button" >Update</button>
<button id="addClient" type="button" >Submit</button>
4

2 回答 2

1

您可以在 form is none like style="display:none" 中设置默认显示样式用于更新列表

但是当您调用 editClient 函数时,您可以将 show() hide() 效果添加到两个按钮

喜欢

$('#updateList').show();
$('#addClient').hide();

像这样的默认形式

<button id="updateList" type="button" style="display:none;" >Update</button>
<button id="addClient" type="button" >Submit</button>
于 2013-04-11T12:49:33.343 回答
0

放置一个用于添加和更新的通用按钮,它可以在 php 上区分以下代码:如果您有一个关于客户详细信息(如电子邮件)的唯一列

if(isset($_POST['save']))
{
//get all client email in your table
//check if the email already exist
//if (yes) 
//update query exected
//else
//insert
}

“保存”是您的按钮名称,我希望这是您真正想要的!

于 2013-04-11T12:47:45.600 回答