submit the form to same page

时间:2015-07-14 作者:Chaudhry Waqas

我有一个简单的表单,我只想将表单提交到同一页。我试过阅读其他答案,包括action="" - wordpress说Oops! That page can’t be found.

  • action="#" - wordpress说Oops! That page can’t be found.
  • action="<?php echo($_SERVER["PHP_SELF"]);?>" - 重定向到/index.php 第页removing action tag - wordpress说Oops! That page can’t be found.

        <?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 个回复
    最合适的回答,由SO网友:Milo 整理而成

    name 是WordPress查询变量,通过提交带有该变量集的表单,可以更改主查询。所有表单元素的前缀都应该是唯一的,以防止像这样的冲突。

    结束