How to change URL after submitting the form successfully?
-
I have a form on my website that I want to set up as a goal on my Google Analytics account. In order to do so, I need to specify the URL the user gets after submitting the form successfully..
Well, it so happens that the form on my website does not change URL after submitting the form, the user gets the success message under the same URL.
What could I do to get a different URL after user submitted the form?
Find the code below:
<?php /* Template Name: Survey */ ?> <?php if(isset($_POST['submitted'])) { if(trim($_POST['contactName']) === '') { $nameError = 'Please enter your name.'; $hasError = true; } else { $name = trim($_POST['contactName']); } if(trim($_POST['email']) === '') { $emailError = 'Please enter your email address.'; $hasError = true; } else if (!preg_match("/^:alnum:[a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) { $emailError = 'You entered an invalid email address.'; $hasError = true; } else { $email = trim($_POST['email']); } if(trim($_POST['endereco']) === '') { $enderecoError = 'Please enter a message.'; $hasError = true; } else { if(function_exists('stripslashes')) { $endereco = stripslashes(trim($_POST['endereco'])); } else { $endereco = trim($_POST['endereco']); } } if(trim($_POST['servicos']) === '') { $servicosError = 'Please enter a message.'; $hasError = true; } else { if(function_exists('stripslashes')) { $servicos = stripslashes(trim($_POST['servicos'])); } else { $servicos = trim($_POST['servicos']); } } if(trim($_POST['comments']) === '') { $commentError = 'Please enter a message.'; $hasError = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['comments'])); } else { $comments = trim($_POST['comments']); } } if(!isset($hasError)) { $emailTo = get_option('tz_email'); if (!isset($emailTo) || ($emailTo == '') ){ $emailTo = get_option('admin_email'); } $subject = '[PESQUISA SERVICEIRO] DE '.$name; $body = "Name: $name \n\nEmail: $email \n\nEndereco: $endereco \n\nServicos: $servicos \n\nComments: $comments"; $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; wp_mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> <?php get_header(); ?> <div id="wrapper"> <div id="main"> <div id="content_page"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div <?php post_class() ?> id="post-<?php the_ID(); ?>"> <h2><?php the_title(); ?></h2> <div class="entry"> <?php if(isset($emailSent) && $emailSent == true) {?> <div class="successmsg"> <p>Obrigado, sua solicitação foi enviada com sucesso!</p> <?php } else { ?> <?php the_content(); ?> <?php if(isset($hasError) || isset($captchaError)) { ?> <p class="error">Ooops!, aconteceu algo de errado...<p> <?php } ?> <form action="<?php the_permalink(); ?>" id="contact" method="post"> <ul class="contact"> <li> <label for="contactName"><strong>Seu Nome:</strong></label> <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="required requiredField" /> <?php if($nameError != '') { ?> <span class="error">Por favor coloque seu nome</span> <?php } ?> </li> <li> <label for="email"><strong>Seu Email:</strong></label> <input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="required requiredField email" /> <?php if($emailError != '') { ?> <span class="error">Por favor coloque seu email</span> <?php } ?> </li> <li> <label for="commentsText"><strong>Seu Endereço ou local onde procura o serviço:</strong></label> <textarea name="endereco" id="enderecoText" rows="10" cols="30" class="required requiredField"><?php if(isset($_POST['endereco'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['endereco']); } else { echo $_POST['endereco']; } } ?></textarea> <?php if($enderecoError != '') { ?> <br/><span class="error">Por favor coloque especifique alguma região para localizarmos as melhores opções</span><br/> <?php } ?> </li> <li> <label for="commentsText"><strong>Liste os serviços que está procurando:</strong></label> <textarea name="servicos" id="servicosText" rows="10" cols="30" class="required requiredField"><?php if(isset($_POST['servicos'])) { if(function_exists('servicos')) { echo stripslashes($_POST['servicos']); } else { echo $_POST['servicos']; } } ?></textarea> <?php if($servicosError != '') { ?> <br/><span class="error">Por favor indique quais serviços você está interessado</span><br/> <?php } ?> </li> <li> <label for="commentsText"><strong>Caso tenha preferências, liste alguns estabelecimentos:</strong></label> <textarea name="comments" id="commentsText" rows="10" cols="30" class="required requiredField"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea> <?php if($commentError != '') { ?> <br/><span class="error">Caso não tenha preferências, determine a distância que está disposto a aceitar uma cotação. Ex. 20km</span><br/> <?php } ?> </li> <li> <input type="submit"></input> </li> </ul> <input type="hidden" name="submitted" id="submitted" value="true" /> </form> <?php } ?> </div><!-- .entry-content --> </div><!-- .post --> <?php endwhile; endif; ?> </div><!-- #content --> </div><!-- #container --> <?php get_sidebar(); ?> <?php get_footer(); ?>
Thanks in advance for any insights
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘How to change URL after submitting the form successfully?’ is closed to new replies.