简体   繁体   中英

Wordpress contact form 7 redirect user to specific page based on entry in dropdown

I'm trying to make a contact form that sends the user to a new 'hidden' page based on his entry in the drop down.

My contact form looks like this:

I'm interested in:
[select subject id:subject "Construction" "Professional Services" "Financial Services" "Wholesale" "IT & Telecom" "Industry" "Transport & Logistics"]

Leave your e-mail address to unlock more information about your preferred subject:
[email* your-email]

[submit "Send"]

What I want the form to do is when a user selects 'Construction', enters his e-mail address and submits the form, he will be directed to 'www.example.com/construction/', and the same for the other options in the drop down, all with their own url.

Thanks in advance!

You can have different value redirecting to different URLs after successful submission.

Example:

<script>
jQuery(document).ready(function($){
    $(".wpcf7").on( 'mailsent.wpcf7', function(){
        var redirect_to = $(this).find('#subject').val();  // Enter your drop-down id
        if( typeof(redirect_to)!=='undefined' && redirect_to!='' ){
            window.location.href= redirect_to;
        }
    });
});
</script>

This code logic below should get you close. You may have to take it apart a little and refactor, but that'll help you understand it better anyways. Here is the live demo . G'luck!

  <form onSubmit="return checkAnswer();">
  <input id="answer" type="text" maxlength="55" class="box" autofocus />
  <input type="submit" class="submit" value="SUBMIT" />
  </form>
  <script>
  function checkAnswer(){
      var response = document.getElementById('answer').value;
      if (response == "correctanswer")
          location = 'http://www.correcturl.com';
      else
          location = 'http://www.wrongurl.com';
      return false;
  }
  </script>

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