Passing variable from one template to another
-
I am trying to pass data from one wordpress template form to another. To make it simple, I have created two templates (and associated them with WP pages as a standard page) as follows:
<?php /* Template Name: Form test */ get_header(); ?> <form action="/form-result/" method="post"> <input type="text" name="name" size="20" /> <input type="submit" value="Go" /> </form> <a href="/form-result/">Result page</a> <a href="/form-result/?name=Elodie">Result page</a> <?php get_footer(); ?>
and
<?php /* Template Name: Form result */ get_header(); $name = $_REQUEST['name']; ?> And the name is <?=$name?> <?php get_footer(); ?>
When I click on the text link Result page I get to the
/form-result/
page, however, if I submit the form, I get a page not found sort of error. After verifying, I found that the problem is coming from trying to pass the variable from one page to another.Pusing further, I found that
<a href="/form-result/?name=Elodie">Result page</a>
get an error page whereas<a href="/form-result/">Result page</a>
takes me properly to the next page.Probably I am missing something small.
Any help here ?
- The topic ‘Passing variable from one template to another’ is closed to new replies.