How to create a custom URL based on dropdown in Wordpress - form submission

前端 未结 1 1735
清歌不尽
清歌不尽 2021-01-25 04:38

I need to apend a certain word to the URL based on which option from a dropdown is selected, to create a custom confirmation screen URL. It doesn\'t matter which contact form I

相关标签:
1条回答
  • 2021-01-25 05:13

    A dropdown is a <select> element not an <input>.
    Of course this can be done I would recommend making a small plugin for this and adding the redirect to the init action something like this.

    <?php
    /*
    Plugin name: redirect on post
    Desciption: http://stackoverflow.com/questions/13686245/how-to-create-a-custom-url-based-on-dropdown-in-wordpress-form-submission
    */ 
    function redirect_on_submit() {
      // check if the post is set
      if (isset($_POST['dropdown_name']) && ! empty ($_POST['dropdown_name'])) {
        header( "Location: http://mysite.com/result/?" . $_POST['dropdown_name'] );
      }
    }
    add_action('init', redirect_on_submit);
    

    add this to a new file in the plugin folder and activate it in the plugin menu.

    0 讨论(0)
提交回复
热议问题