简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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