I would like to diplay the output(Mickey) in a wordpress page, instead of php page

The following code is in a wordpress page.

<form action="action_page.php" method="post">
    Name:<br>
    <input type="text" name="name" value="Mickey">
    <input type="submit" value="Submit">
</form>  

action_page.php

Read More
<?php $name=$_POST['name']; echo $name;?>

I would like to diplay the output(Mickey) in a wordpress page, instead of php page. Please help me.

Related posts

Leave a Reply

1 comment

  1. You can achieve it via AJAX, see the codex

    Add this to functions.php

    add_action( 'wp_ajax_add_foobar', 'prefix_ajax_add_foobar' );
    add_action( 'wp_ajax_nopriv_add_foobar', 'prefix_ajax_add_foobar' );
    
    function prefix_ajax_add_foobar() {
        // Handle request then generate response using WP_Ajax_Response
    
        // In a real world scenario, apply all the validation, 
        // sanitization and black magic to POSTed variables before using them
    
        $name=$_POST['name']; 
        echo $name;
    }
    

    Now the following could go in footer.php inside of <script> tags or in a separate JS file.

    jQuery.post(
        ajaxurl, 
        {
            'action': 'add_foobar',
            'data':   jQuery("form").sanitize() 
        }, 
        function(response){
            alert('The server responded: ' + response);            
        }
    );
    

    All things being equal you should see an alert with the value that was posted.