I'm trying to build a contact form custom widget. So i would like to display a contact form with a WordPress widget and send a message.
No problem to display the form with my widget but when i click on the send button i can't retrieve my data. The isset($_POST['my_data']) doesn't work.
When I put my form code out of the widget in a simple php file, everything is ok, the isset($_POST['my_data']) work well.
I do the test with this simple snippet:
<?php
//$form_action = '';
$form_action = get_bloginfo('url').'#contactBox';
if (isset($_POST['send'])) {
echo "The isset 'send' work well
";
$name = (isset($_POST['name'])) ? $_POST['name'] : '';
echo "name = ".$name." ";
} else {
echo "There is something WRONG !!!";
}
// Display the form
echo '<form method="post" action="'.$form_action.'">'."\n";
echo ' <p>'."\n";
echo ' <label for="name">Name</label>'."\n";
echo ' <input type="text" name="name" value="'.$name.'" />'."\n";
echo ' </p>'."\n";
echo ' <div style="text-align:center;"><input class="submit" type="submit" name="send" value="Send" /></div>'."\n";
echo '</form>'."\n";
?>
Is it possible to implement a form with a WordPress custom widget ?
This is the complete code of my custom widget with the contact form: www.pixenjoy.com/documents/widget.zip
I add two echo messages in this code to test the retrieve of my data form (if(isset...) > line 145 "ok" line 190 "ko"