1

I have 10 or more input hidden in 10 or more pages with different values in Wordpress text editor and I want to get the value using $_POST in a custom page template.

How to do this? I tried to called the input hidden name in my custom page template but the value is not getting.

Text editor

<form method="POST">
    <input type="hidden" name="segment" value="test"/>
</form>

Custom page template

$segment = isset($_POST['segment']) ? $_POST['segment'] : '';
1
  • Note: the <input> tag does not use and does not need a closing slash in HTML and never has.
    – Rob
    Sep 8, 2019 at 21:12

1 Answer 1

0

If you're not specifying a page, then you would access the $_POST data on the same page as your form.

print_r( $_POST );

if ( isset( $_POST[ 'firstname' ] ) )
{
    echo $_POST[ 'firstname' ] . ' ' . $_POST[ 'lastname' ];

    wp_die();

}
else 
{ 
    ?>

    <form method="POST">

        First name:<br>
        <input type="text" name="firstname" value="Mickey"><br>

        Last name:<br>
        <input type="text" name="lastname" value="Mouse"><br><br>

        <input type="submit" value="Submit">

    </form>

    <?php 

    wp_die();
}

If you want to access $_POST data on another page, you would probably need to specify that in the action attribute.

<form method="POST" action="your_page_name_here.php">
    <input type="hidden" name="segment" value="test">
    <input type="submit" value="Submit">
</form>
1
  • $_POST is wrote in the custom page template while the html input hidden tag wrote in the text editor. Do you mean I should call the custom page template php in the text editor?
    – User014019
    Nov 2, 2016 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.