Reputation: 695
How would I post data from one page to another in wordpress.I have tried with the following form :
<form action="?page_id=25" method="POST">
but then wordpress says page not found when the form is submitted.I then changed permalinks to use %pagename% and still it didn't work,but when I use the url directly it loads the page perfectly.
Is there a different way to POST data in wordpress or is there something I should do so my pages will load?
EDIT
Full code used to submit form
<?php
echo '<form id="submitForm" method="POST" action="' . get_permalink(25) . '">';
echo '<input type="hidden" value="1" name="id">';
echo '<input type="hidden" value="Test" name="name">';
echo '<a href="javascript:document.getElementById(\'submitForm\').submit();">View</a>';
echo '</form>';
?>
The generated code is as follows :
<form id="submitForm" method="POST" action="http://localhost:8888/wp/?page_id=25">
<input type="hidden" value="1" name="id">
<input type="hidden" value="Test" name="name">
<a href="javascript:document.getElementById('submitForm').submit();">View</a>
</form>
Upvotes: 0
Views: 238
Reputation: 4621
use
<form action="<?php echo get_permalink(25); ?>" method="POST">
Edit:
Try Below Code , Wordpress has special meaning of name
variable hence change it
echo '<form id="submitForm" method="POST" action="' . get_permalink(25) . '">';
echo '<input type="hidden" value="1" name="id">';
echo '<input type="hidden" value="Test" name="Custom_name">'; // Change the name of the field
echo '<a href="javascript:document.getElementById(\'submitForm\').submit();">View</a>';
echo '</form>';
Upvotes: 1