global variable in form

I just created a WordPress plugin with a custom form
In my plugin (myplugin.php):

function form_search() {
if (isset($_POST[‘send-search’]) && isset($_POST[‘search-verif’])) {
if (wp_verify_nonce($_POST[‘search-verif’], ‘make-search’)) {

global $var_type;
$var_type = htmlspecialchars($_POST[‘type’]);

add_action( ‘template_redirect’, ‘form_search’ );

my 1st page:

<form action =”/page-result” method=”POST”>
wp_nonce_field(‘make-search’, ‘search-verif’);
<input type=”text” id=”my_search” name=”my_search” />
<input type=”submit” name=”send-search” value=”Send”>

My 2nd page:
in my page template (I use aftercontent fonction) I would like use this variable :

global $var_type;
echo $var_type; //for example

But $var_type is empty, any ideas?

Read more here:: global variable in form

Leave a Reply

Your email address will not be published. Required fields are marked *