Title: Submit query param
Last modified: December 23, 2016

---

# Submit query param

 *  [puzz](https://wordpress.org/support/users/puzz/)
 * (@puzz)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/)
 * Hi,
 * First of all thanks for this great plugin! It works like a charm.
 * The problem I’m having is the following. I want to set up a goal on google analytics
   when a users submits my contact form. Now, to do so I need a different url on
   the resulting page (so, then a http POST is sent). Unfortunately there is no 
   way (AFAIK) to check the http method.
 * So, I was thinking to add a new parameter. If set, it will just append that parameter
   to the post url. Something like this:
 *     ```
       diff --git a/vscf-form.php b/vscf-form.php
       index b2537ca..0345fbf 100644
       --- a/vscf-form.php
       +++ b/vscf-form.php
       @@ -26,7 +26,8 @@ function vscf_shortcode($vscf_atts) {
                       "error_email" => __('Please enter a valid email', 'very-simple-contact-form'),
                       "message_error" => __('Please fill the required fields', 'very-simple-contact-form'),
                       "message_success" => __('Thank you! You will receive a response as soon as possible.', 'very-simple-contact-form'),
       -               "hide_subject" => ''
       +               "hide_subject" => '',
       +               "submit_query_param" => ''
               ), $vscf_atts);
   
               // Set variables
       @@ -148,8 +149,14 @@ function vscf_shortcode($vscf_atts) {
                       $hide = true;
               }
   
       +    $url = $_SERVER['REQUEST_URI'];
       +    $submit_query_param = @$vscf_atts['submit_query_param'];
       +    if ($submit_query_param) {
       +        $url .= (strpos($url, '?') > 0 ? '&' : '?') . $submit_query_param;
       +    }
       +
               // Contact form
       -       $email_form = '<form class="vscf" id="vscf" method="post">
       +       $email_form = '<form action="' . $url . '" class="vscf" id="vscf" method="post">
                       <p><label for="vscf_name">'.esc_attr($vscf_atts['label_name']).': <span class="'.(isset($error_class['form_name']) ? "error" : "hide").'" >'.esc_attr($vscf_atts['error_name']).'</span></label></p>
                       <p><input type="text" name="vscf_name" id="vscf_name" '.(isset($error_class['form_name']) ? ' class="error"' : '').' maxlength="50" value="'.esc_attr($form_data['form_name']).'" /></p>
   
       @@ -182,4 +189,4 @@ function vscf_shortcode($vscf_atts) {
        }
        add_shortcode('contact', 'vscf_shortcode');
   
       -?>
       \ No newline at end of file
       +?>
       ```
   
 * This is just an idea. It still only for one form (there is also the widget form).
   And it has a problem, it will trigger the goal even if the form validation fails.
 * Maybe a better idea would be to setup a specific page, and have a `redirect_on_successfull_submit`.
   Then the plugin will redirect there.
 * What do you think?

Viewing 15 replies - 1 through 15 (of 23 total)

1 [2](https://wordpress.org/support/topic/submit-query-param/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/submit-query-param/page/2/?output_format=md)

 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8585153)
 * Hi,
 * What I can try(!) to do is to add a page ID attribute, so when user adds this
   attribute (+ page ID) it will redirect to this page after submitting the form..
   Is that what you want?
 * Guido
 *  Thread Starter [puzz](https://wordpress.org/support/users/puzz/)
 * (@puzz)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8585306)
 * Yes, that would be perfect!
 * Now, I’m not much of an wordpress developer (more into Java/Golang), but I think
   the normal `location()` redirect can’t be done from a plugin when part of the
   page is already sent. At least I think it is. But maybe even a `<javascript>document.
   location=...</javascript>` will be enough?
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8585724)
 * Meanwhile you can create your own (hardcoded) redirect very easily.
 * Open files vscf-form and vscf-widget-form, look for and remove this:
 *     ```
       return $info;
       ```
   
 * Add this instead:
 *     ```
       header('Location: http://www.example.com/');
       ```
   
 * Done!
 * Guido
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8587890)
 * Hi again,
 * Please ignore previous reply because it doesn’t work properly. You will get the
   famous “headers already sent” message. Detailed explanation [here](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php).
 * Will work on it.
 * Guido
 *  Thread Starter [puzz](https://wordpress.org/support/users/puzz/)
 * (@puzz)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8587936)
 * Hey, yes, that’s exactly what I was thinking.
 * Anyway, if you need any help just let me know.
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8588024)
 * I don’t have much knowledge about “headers already sent” but I now know it’s 
   never gonna work on this location in my file. Besides this there’s a session 
   holding captcha data and I did not fully destroy it before calling the header.
   Guess this is bad for the header as well. Any help appreciated but I strongly
   prefer a solution with php.
 * Guido
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8588514)
 * Hi again,
 * I think using the js window.location function is the most easy solution.. I need
   to add the PHP variable, but js is not my thing.
 * My php header, which I’m not gonna use:
 *     ```
       header('Location: '.home_url('/?page_id='.$vscf_atts['page_id'].'').'');
       ```
   
 * Maybe you can help me with that part?
 * Guido
 *  Thread Starter [puzz](https://wordpress.org/support/users/puzz/)
 * (@puzz)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8588564)
 * I’m not on my dev machine now, but I’ll try to experiment with it tomorrow.
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8588755)
 * Hi,
 * Normally I could use a function called [wp_localize_script](https://codex.wordpress.org/Function_Reference/wp_localize_script)
   to add a php variable (in my case page id) to the js window.location. But, because
   wp_localize_script is running outside the shortcode file I’m not able to get 
   the variable. See for an example [this](http://wordpress.stackexchange.com/questions/97280/get-shortcode-attributes-outside-shortcode-function)
   topic.
 * Will work on it..
 * Guido
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8590811)
 * Hi,
 * Found a solution: echo the javascript:
 *     ```
       $page = home_url('/?page_id='.$vscf_atts['page_id'].''); 
       echo '<script type="text/javascript">'; 
       echo 'window.location="'.$page.'";'; 
       echo '</script>';
       ```
   
 * Have added 2 extra shortcode attributes to set a redirect:
    redirect = not set
   or set on “true” page_id = page ID to redirect to
 * It doesn’t redirect very quickly on my local install, when clicking submit. But
   did not test it on live server yet.
 * What are your thoughts about this solution?
 * Guido
 *  Thread Starter [puzz](https://wordpress.org/support/users/puzz/)
 * (@puzz)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8592743)
 * Yeah, that should work. The redirect is slow because it needs to load the page,
   with header redirect it would be almost instant, I suppose. But, I don’t mind
   if it’s slow, the only important thing for me is to have this one specified url
   requested (sooner or later).
 * BTW, the cleanest way to do the redirect properly is probably to register a hook
   like:
 * `add_action('init', 'your_function');`
 * This is done before WP starts the output, and you are still in time to send a
   header there. But I think that would need a bigger refactoring of the code. In
   the meantime, the javascript redirect is definitely enough for me.
 * PS. Just sent a “Thank you” donation. Not huge, but I think it should be enough
   for a pizza and a beer (maybe even two) in Netherlands 🙂
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8593205)
 * Hi [@puzz](https://wordpress.org/support/users/puzz/)
 * First, thank you very much for your generous donation 🙂 I really appreciate 
   it.
 * Because the contact form is wrapped in a shortcode it’s kind of difficult to 
   get a value outside the shortcode. The redirect action hook should be in the 
   functions file of my plugin (vscf.php), so that means I have to get the page 
   ID value from the shortcode file.. So I’m having the same problem as using wp_localize_script(
   see a previous reply). I guess there must be a solution somehow, but I’m not 
   a hardcore programmer.
 * Guido
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8611200)
 * Hi again,
 * You know, if I’m NOT able to find a proper solution within several days I will
   refund 50% of your donation.
 * The redirect with inline js works, but isn’t the proper way.
 * Guido
 *  Thread Starter [puzz](https://wordpress.org/support/users/puzz/)
 * (@puzz)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8612865)
 * I caught a bad flu last week and haven’t had the time to experiment with it. 
   If nothing works, I’ll just have to live with it.
 * And, don’t worry about my donation. That was for your efforts (and nobody can
   deny that you work hard, I appreciate that!). If you ever come to Croatia, ping
   me I owe you a beer for your efforts!
    -  This reply was modified 9 years, 5 months ago by [puzz](https://wordpress.org/support/users/puzz/).
 *  Thread Starter [puzz](https://wordpress.org/support/users/puzz/)
 * (@puzz)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/#post-8613072)
 * Hey, here I am again, I think this should work:
 *     ```
       add_action('init', 'do_output_buffer');
       function do_output_buffer() {
           ob_start();
       }
       ```
   
 * …it makes sure no content is sent before you. The content is kept in memory and
   WordPress makes sure to flush all the `ob_` cache later.
 * And now `wp_redirect()` ([https://developer.wordpress.org/reference/functions/wp_redirect/](https://developer.wordpress.org/reference/functions/wp_redirect/))
   can be used from any place in your plugin.
 * I’m still reading if that is OK to do from a wp plugin, but it works.
    -  This reply was modified 9 years, 5 months ago by [puzz](https://wordpress.org/support/users/puzz/).
    -  This reply was modified 9 years, 5 months ago by [puzz](https://wordpress.org/support/users/puzz/).

Viewing 15 replies - 1 through 15 (of 23 total)

1 [2](https://wordpress.org/support/topic/submit-query-param/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/submit-query-param/page/2/?output_format=md)

The topic ‘Submit query param’ is closed to new replies.

 * ![](https://ps.w.org/very-simple-contact-form/assets/icon-256x256.png?rev=1415751)
 * [VS Contact Form](https://wordpress.org/plugins/very-simple-contact-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/very-simple-contact-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/very-simple-contact-form/)
 * [Active Topics](https://wordpress.org/support/plugin/very-simple-contact-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/very-simple-contact-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/very-simple-contact-form/reviews/)

 * 23 replies
 * 2 participants
 * Last reply from: [Guido](https://wordpress.org/support/users/guido07111975/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/page/2/#post-8628904)
 * Status: not resolved