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?
- The topic ‘Submit query param’ is closed to new replies.