Hey i am trying to retrive data from a basic form .. but when i am using $_POST['field name'] then it gives me nothing .
here is my basic code
form page is:
<?php
/**
Template Name: galaxy
*/
get_header(); ?>
<div id="main-content" class="main-content">
<form action="<?php echo site_url();?>?page_id=8" method="post">
<input type="text" name="name" /> <input type="submit" value="Send" />
</form>
</div><!-- #main-content -->
<?php
get_footer();
when i click submit it redirects to next page but display nothing with this code
<?php
/**
Template Name: get_value_galaxy
*/
$name=$_POST['name'];
echo $name;
print_r($_POST);
?>
Try using a different name for the variable. I know that Wordpress uses "name" as a public query var, and perhaps that's why it's not working. So rather than using name="name"
, try this:
Form:
<input type="text" name="unique_name" />
Post Page:
$name=$_POST['unique_name'];
echo $name;
See this list for all query vars: http://codex.wordpress.org/WordPress_Query_Vars#Query_variables