Reputation: 2503
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?
Upvotes: 4
Views: 36337
Reputation: 15616
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>";
}
}
?>
Upvotes: 15
Reputation: 16301
If you wanna to show a json encoded list of the POST
array is simple as
<?php echo json_encode($_POST);?>
Upvotes: 2
Reputation: 1106
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.
Upvotes: 1