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

非 Y 不嫁゛ 提交于 2019-12-13 04:47:11

问题


Wordpress (Contact form 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';"

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:?


回答1:


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:

<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

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.



来源:https://stackoverflow.com/questions/24031423/is-it-possible-to-have-two-submit-buttons-in-one-form-with-differents-redirects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!