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 8 replies - 16 through 23 (of 23 total)

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

 *  Thread Starter [puzz](https://wordpress.org/support/users/puzz/)
 * (@puzz)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/page/2/#post-8613176)
 * Ah, and there is another (and slightly better) solution. This will start `ob_start()`
   only when it detects that the current `$post` has your shortcode:
 *     ```
       add_action('template_redirect', 'vscf_check_shortcode');
       function vscf_check_shortcode() {
           global $post;
           if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'contact') ) {
               ob_start();                                                                                                                                                                                             }
       }
       ```
   
 * …and now `wp_redirect()` will work.
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/page/2/#post-8616805)
 * Hi,
 * This sounds great, did not came up with this quite easy solution myself.
 * Don’t think I should use action [template_redirect](https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect)
   because the actual redirect is being done elsewhere.
 * So using [init](https://codex.wordpress.org/Plugin_API/Action_Reference/init)
   would be better imo. But indeed, the clean way is to only start OB when a contact
   page is being displayed. So something like this (not tested yet):
 *     ```
       function do_output_buffer() {
       	global $post;
       	if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'contact') ) {
       		ob_start();
       	}
       }
       add_action( 'init', 'do_output_buffer');
       ```
   
 * Nice! Almost there.
 * Guido
    -  This reply was modified 9 years, 5 months ago by [Guido](https://wordpress.org/support/users/guido07111975/).
      Reason: code snippet
 *  Thread Starter [puzz](https://wordpress.org/support/users/puzz/)
 * (@puzz)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/page/2/#post-8616872)
 * The `template_redirect` isn’t related to any http redirects:
 * > This action hook executes just before WordPress determines which template page
   > to load.
 * I decided to use it (instead of `init`) because at that point I’m sure that the
   global `$post` variable is fully loaded. But if it works with `init` it’s fine,
   too.
    -  This reply was modified 9 years, 5 months ago by [puzz](https://wordpress.org/support/users/puzz/).
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/page/2/#post-8617135)
 * Hi,
 * There might be a problem in case contactform is located in a widget and $post
   is not active. So I will take another look at has_shortcode function. To be continued.
 * But thank you very much!
 * Guido
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/page/2/#post-8619005)
 * Hi,
 * It didn’t work with init, guess it’s running too late.
 * So I’m now using template_redirect as you suggested. Added an extra check for
   widget:
 *     ```
       function vscf_check_shortcode() {
       	global $post;
       	if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'contact') ) {
       		ob_start();
       	} else if( class_exists('vscf_widget') ) {
       		ob_start();
       	} 
       }
       add_action('template_redirect', 'vscf_check_shortcode');
       ```
   
 * I guess this is the proper way 🙂
 * Guido
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/page/2/#post-8619262)
 * > I guess this is the proper way
 * Nope:
 *     ```
       if( class_exists('vscf_widget') )
       ```
   
 * Is always “true” if plugin is activated.
 * I’m getting tired. But will try again.
 * Guido
 *  Thread Starter [puzz](https://wordpress.org/support/users/puzz/)
 * (@puzz)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/page/2/#post-8619407)
 * Hey, look, if this is only for me, don’t worry. I’m not using widgets and I’ll
   just change the code with `template_redirect`. You can then fix this without 
   any time pressure when (if) you find the time.
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/submit-query-param/page/2/#post-8628904)
 * Hi,
 * I posted [this message](https://wordpress.org/support/topic/determine-if-shortcode-is-present-or-active)
   on the hacks forum (which is closed now) and people advice me not to use output
   buffering because this might cause a conflict with other theme’s or plugins. 
   So I will not using this.
 * A redirect feature is a nice addition, so I will try to find another solution.
 * Thanks again for your help.
 * Guido

Viewing 8 replies - 16 through 23 (of 23 total)

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

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