在提交表格时,我应该使用哪个操作钩子来截取表格? 时间:2015-12-17 作者:Moha the almighty camel 我在wordpress页面上有一个表单POST 方法我需要在提交后,但在将表单发送到action属性中的URL之前,向表单添加一个额外字段。我在考虑用肌动蛋白钩,不确定哪一个对这种情况最好?或者首先它是不是正确的工具?非常感谢。Edit表单数据将发送到电子银行服务。银行需要一个额外的字段,该字段是连接在一起的所有变量的哈希值。银行在收到提交时会执行相同的操作,并与额外字段进行比较,以确保数据完整性。 3 个回复 最合适的回答,由SO网友:N00b 整理而成 我不完全确定定制表单是否有这样的操作挂钩(其他人可能知道),但如果表单正常提交,没有ajax,肯定还有其他方式。如果你有任何问题,请告诉我。//This applies if you want it to happen only if form is submited and page refreshed //It doesn\'t work if user comes back later - there\'s no extra field later on $form_submitted = false; //If submit is pressed if( isset( $_POST[\'submit\'] ) ) { //There should also be a nonce check here $form_submitted = true; } //All your form html here //Check if form is submitted if ( $form_submitted ) { //Show your extra fields } /*If you want it to be a bit more "permanent" 1. update_usermeta() to save the bool that user has submitted the form - logged-in users only 2. Use cookies which might not work properly in browser "stealth mode" and is gone if user deletes browser history with cookies 3. Use sessions which destroys itselves if user closes the browser */ SO网友:C C 表单提交都是客户端的,WordPress中不会有一个钩子来处理这个问题。最好是使用jQuery捕获#元素。submit()操作,然后用所需的任何数据填充表单上的隐藏字段。请注意,您必须在jQuery中使用preventDefault()操作,以阻止实际表单提交的发生。做您需要做的事情,然后让jQuery最终提交表单。文档位于此处:https://api.jquery.com/submit/他们在该页面上显示的示例几乎正是您想要做的。然而,这确实不是一种典型/常见的情况(除了输入验证)。在表单发布回接收方之后,您真的应该在服务器端进行数据操作。php代码。。。 SO网友:s_ha_dum 实现“服务器端”的唯一方法是将表单发布到服务器上的脚本中,然后从那里向银行发出请求。You would need to post to admin-ajax.php. 这里有许多Q/A解释如何做到这一点such as this one I wrote.我不知道的是PCI Standards 这样做的影响,我不会因为这个原因开始编写代码。 文章导航