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?
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>";
}
}
?>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With