0

I have a simple form , all I want is to submit the form to same page. I have tried reading other answers including

  • action="" - wordpress says Oops! That page can’t be found.
  • action="#" - wordpress says Oops! That page can’t be found.
  • action="<?php echo($_SERVER["PHP_SELF"]);?>" - redirects to /index.php page
  • removing action tag - wordpress says Oops! That page can’t be found.

But nothing works. What I should do now ?
This is my code

    <?php
    /*
    Plugin Name: Contact Form
    Plugin URI: http://wpgeeks.net/
    Version: 1.0
    Author: Adam
    Description: A simple contact form for testing
    */

    /*Security Note: Consider blocking direct access to your plugin PHP files by adding the following line at the top of each of them, or be sure to refrain from executing sensitive standalone PHP code before calling any WordPress functions.*/
    defined( 'ABSPATH' ) or die( 'No script kiddies please!' );



    //add_action( 'plugins_loaded', 'functionShowForm' );
function functionShowForm($atts){

    $waq_values = shortcode_atts(array(

        'color'=>'white'
    ),esc_html($atts));
    ?>

<form style="color:<?php echo $waq_values['color'];?>;" method="post" action=" ">
Name:   <input type="text" name="waq_name" placeholder="First Name">
Email:  <input type="email" name="waq_email" placeholder="[email protected]">
Password:<input type="password" name="waq_password">
<input type="submit" name="waq_submit" value="Submit">
</form>
<?php
}//function ends here

function process_wpse_194468(){
if ($_SERVER['REQUEST_METHOD']=="POST" and isset($_POST["waq_submit"])){
    $to = sanitize_email($_POST["waq_email"]);
    $subject = esc_html($_POST["waq_name"]);
    $message = $_POST["waq_password"];
    echo "Email " .$to;
    wp_mail( $to, $subject, $message );
}
}
//short code
add_shortcode('showform','functionShowForm');
add_action('init','process_wpse_194468');

?>

1 Answer 1

5

name is a WordPress query var, by submitting a form with that var set, you are changing the main query. All form elements should always be prefixed with something unique to prevent clashes like this.

1
  • wao , awesome answer , thank you so much man.It Worked perfectly and now only one problem that mail is not being sent any thoughts there ? Jul 14, 2015 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.