简体   繁体   English

是否可以在一种联系表单7中以一种形式具有两个具有不同重定向的提交按钮?

[英]Is It possible to have two submit buttons in one form with differents redirects in contact form 7?

Wordpress (Contact form 7) WordPress(联系表格7)

I have one submit button know, that has a redirect to a page: on_sent_ok: "location = ' http://xxxxxxxxxxx.com/xxxx/?page_id=1 ';" 我知道有一个提交按钮,可以重定向到页面:on_sent_ok:“位置=' http ://xxxxxxxxxxx.com/xxxx/?page_id=1';”

Know I wanna know if its possible to have one more submit button in the same form redirecting to another page? 知道我想知道是否有可能以相同的形式将一个提交按钮重定向到另一个页面吗?

Or Is It possible to do it without using on_sent_ok:? 还是可以不用on_sent_ok来做到这一点?

Yes, it is possible, you have to name your button and add a value to it. 是的,有可能,您必须命名按钮并为其添加一个值。 That will be sent with the form. 这将与表格一起发送。 On the server you can check what button was pressed by checking which button name (and value) is present in the request parameters. 在服务器上,您可以通过检查请求参数中存在哪个按钮名称(和值)来检查按下了哪个按钮。

For example: 例如:

HTML on the client: 客户端上的HTML:

<form action="auth.php" method="POST" enctype="application/x-www-form-urlencoded; charset=utf-8">
    <label for="email">Email address</label>
    <input type="text" name="email" />
    <br />
    <label for="password">Password - at least 5 characters</label>
    <input type="password" name="password">
    <br />
    <button name="subject" type="submit" value="register">Sign up</button>
    <button name="subject" type="submit" value="login">Sign in</button>
</form>

PHP on the server 服务器上的PHP

if ($_POST['subject'] == 'register') {
    //register user
    header('location: registered.php');
}
else if ($_POST['subject'] == 'login') {
    //login user
    header('location: profile.php');
}

note: 注意:
If you want to send the same form using completely different actions, then you have to use javascript onsubmit or a non-submit button with onclick to change the form action, or send the data with AJAX. 如果要使用完全不同的动作发送相同的表单,则必须使用javascript onsubmit或带有onclick的非提交按钮来更改表单动作,或使用AJAX发送数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM