WordPress 表单操作 - functions.php 文件 [英] WordPress Form Action - functions.php file
问题描述
我通过进入 WordPress 后端创建了表单,然后进入页面,创建新页面,然后在该页面上创建了 html 表单.
表单代码在下面给出.
现在我希望当我提交表单时,它会在functions.php文件中发布数据.就像我在functions.php文件中做了这样的动作.
function do_payment() {echo "";打印_r($_POST);echo "</pre>";出口;}add_action('admin_post_make_payment', 'do_payment');
现在,任何人都可以帮助如何做到这一点,它在上面的例子中给出了错误.
谢谢
您只需这样做.
它会在functions.php文件中执行你给定的操作.
第二种方式.假设您有一个在页面下方给出的表单.
您只需在您的functions.php文件中编写以下代码.
if($_REQUEST['make_payment'] == 'make_payment') {echo "";打印_r($_POST);echo "</pre>";}
谢谢
I have created on form by going into WordPress back end, then go into page, create new page, and on that page I have created on html form.
form code is giving in below.
<form action="http://example.com/wp-admin/admin-post_make_payment.php" method="post">
<input type="text" name="payment" class="form-control"/>
<input type="submit" name="Submit" class="form-control"/>
</form>
Now I want that when I submit form, then it will go and post data on functions.php file. Like I have make such type of action in functions.php file.
function do_payment() {
echo "<pre>"; print_r($_POST); echo "</pre>";
exit;
}
add_action('admin_post_make_payment', 'do_payment');
Now, can anyone help how to do that, it is giving error in above example.
Thanks
You just simply do that.
<form action="http://example.com/wp-admin/admin-post.php" method="post">
<input type="hidden" name="action" value="make_payment" class="form-control"/>
<input type="text" name="payment" class="form-control"/>
<input type="submit" name="Submit" class="form-control"/>
</form>
It will hit on your given action in functions.php file.
The Second way is that. Suppose you have a form which is given in below in the Page.
<form method="post">
<input type="text" name="payment" class="form-control"/>
<input type="submit" name="make_payment" class="form-control"/>
</form>
You Just write the below code in your functions.php file.
if($_REQUEST['make_payment'] == 'make_payment') {
echo "<pre>"; print_r($_POST); echo "</pre>";
}
Thanks
这篇关于WordPress 表单操作 - functions.php 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!