Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to display POST data from form, with WordPress backend?

I have a standard HTML form on a WordPress post that the visitor will fill out. It consists of mostly checkboxes. What I would like, is after the form is submitted, a page is then presented to the user showing what they checked. For example, if the visitor checked off Checkbox A, B, and E, (but not C and D) then upon submission they would see the following:

You submitted:
Checkbox Value A
Checkbox Value B
Checkbox Value E

Obviously I can do this with just PHP, but my client would like to be able to modify the form options. Therefore I will need an easy to use backend.

Is there a plugin or user friendly way that this can be created? Or is my best bet to start building it myself?

like image 986
Ryan Avatar asked Dec 07 '22 14:12

Ryan


2 Answers

the easiest way would be:

<pre>
<?php var_dump($_POST);?>
</pre>

but you can style it like:

<?php
    foreach($_POST as $key=>$post_data){
        echo "You posted:" . $key . " = " . $post_data . "<br>";
    }
?>

Note that this might give errors if the $post_data type can't be displayed as a string, like an array in the POST data. This can be extended to:

<?php
    foreach($_POST as $key=>$post_data){
        if(is_array($post_data)){
            echo "You posted:" . $key . " = " . print_r($post_data, true) . "<br>";
        } else {
            echo "You posted:" . $key . " = " . $post_data . "<br>";
        }
    }
?>   
like image 77
Taha Paksu Avatar answered Dec 10 '22 13:12

Taha Paksu


You can do something in jQuery.

$.post(
    "post.php",
    {checkbox : 1, checkbox2 : 0, checkbox3 : 0}, // this is the body of the post request
    function(data) {
       alert('page content: ' + data); // look up values in checkboxes and display them
    }
);

Im not sure what kind of data wordpress needs, it might also need some session id to be sent if you need the user to be logged in.

like image 30
Joelmob Avatar answered Dec 10 '22 11:12

Joelmob