Plugin form unable to process

时间:2017-02-13 作者:Himanshu

我正在使用短代码来处理我的HTML表单。但是,提交后不会显示任何结果。我不会走错方向。

<?php
function installer(){
    include(\'installer.php\');
}
register_activation_hook( __file__, \'installer\' ); //executes installer php when installing plugin to create new database

//result display form begins

function display_result_form_fields(){
    ob_start(); ?> 
        <form id="result_form" action="" method="POST">
            <fieldset>
                <p>
                    <label for="rollNumber"><?php _e(\'Roll Number\'); ?></label>
                    <input name="rollNumber" id="rollNumber" class="required" type="number"/>
                </p>
                <p>
                    <input type="submit" value="<?php _e(\'Submit\'); ?>"/>
                </p>
            </fieldset>
        </form>
    <?php
    return ob_get_clean();
}

function form_processing(){
if(isset($_POST[\'Submit\'])){
    global $wpdb;
    $student_id = $_POST[\'rollNumber\'];
    $query = "SELECT * FROM `wp_xenonresult` WHERE `student_id` = $student_id";
    $result = $wpdb->get_row($query);
    echo "Dear student, congratulations";}
}

//shortcode begins here
function result_form() {
            form_processing();
            $output = display_result_form_fields();
            return $output;
    }

add_shortcode(\'result_form\', \'result_form\'); //create shortcode
add_filter(\'widget_text\',\'do_shortcode\'); // Enable shortcodes in text widgets
?>

2 个回复
最合适的回答,由SO网友:AddWeb Solution Pvt Ltd 整理而成

你错过了name 的属性<input type="submit" value="<?php _e(\'Submit\'); ?>"/> HTML标记。

i、 e。

应该是这样的:<input type="submit" name="Submit" value="<?php _e(\'Submit\'); ?>"/>

否则,你必须改变内部条件function form_processing()

OLD:如果(isset($\\u POST[\'Submit\'])){

Replace with:if(isset($\\u POST[\'rollNumber\'])){

希望这对你有帮助。

SO网友:Himanshu

在@Bagpiper和@AddWeb Solution Pvt Ltd的帮助下,我终于解决了这个问题。

<?php

function installer(){
    include(\'installer.php\');
}
register_activation_hook( __file__, \'installer\' ); //executes installer php when installing plugin to create new database

//result display form begins

function display_result_form_fields(){
    ob_start(); ?> 
        <form id="result_form" action="" method="POST">
            <fieldset>
                <p>
                    <label for="rollNumber"><?php _e(\'Roll Number\'); ?></label>
                    <input name="rollNumber" id="rollNumber" class="required" type="number"/>
                </p>
                <p>
                    <input type="submit" name = "submit" value="Submit"/>
                </p>
            </fieldset>
        </form>
    <?php
    return ob_get_clean();
}

function form_processing(){
    global $wpdb;
    $student_id = $_POST[\'rollNumber\'];
    $query = "SELECT * FROM `wp_xenonresult` WHERE `student_id` = $student_id";
    $result = $wpdb->get_row($query);
    echo "Dear ".$result->", ";
    }


//shortcode begins here
function result_form() {
    ob_start(); 
    if(isset($_POST[\'submit\'])){
        form_processing();
        }
    else{
        $output = display_result_form_fields();
        return $output;
    }
    return ob_get_clean();
    }

add_shortcode(\'result_form\', \'result_form\'); //create shortcode
add_filter(\'widget_text\',\'do_shortcode\'); // Enable shortcodes in text widgets
?>

相关推荐

Shortcode is not working

通过阅读教程,我创建了一个简单的快捷代码:<?php /* Plugin Name: GT NoTranslate Shortcode Description: Shortcode to wrap a span with the \"notranslate\" span around text. Version: 0.1 BETA Author: Andrew Truckle Author URI: http://www.trucklesoft.co.