我终于设法让我的插件工作了。但是,在提交后,整个页面将与我的输出一起重新加载到表单上方。如何避免页面完全重新加载,并且在提交表单后不显示表单?
<?php
function installer(){
include(\'installer.php\');
}
register_activation_hook( __file__, \'installer\' ); //executes installer php when installing plugin to create new database
add_action(\'admin_menu\',\'result_menu\'); //wordpress admin menu creation
function result_menu()
{
add_menu_page(\'Result\',\'Result\',\'administrator\',\'xenon-result\');
add_submenu_page( \'xenon-result\', \'Manage Marks\', \' Manage Marks\', \'administrator\', \'Manage-Xenon-Marks\', \'Xenon_Marks\' );
}
function Xenon_Marks() //function to add marks addition form in admin view
{
include(\'new/result-add-marks.php\');
}
function html_form_code()
{
echo \'<form action="" method="post">\';
echo \'<fieldset>\';
echo \'<legend>Student Information</legend>\';
echo \'Roll Number: <input type="number" min="170001" max="171000" name="rollNumber"><br>\';
echo \'<input type="submit">\';
echo \'<input type ="reset">\';
echo \'</form>\';
}
function result_display(){
global $wpdb;
$student_id = $_POST[\'rollNumber\'];
$query = "SELECT * FROM `wp_xenonresult` WHERE `student_id` = $student_id";
$result = $wpdb->get_row($query);
echo $result->student_name;
}
if(isset($_POST[\'submit\']))
{
result_display();
}
function display_shortcode() {
ob_start();
result_display();
html_form_code();
return ob_get_clean();
}
add_shortcode( \'xenon_result_display\', \'display_shortcode\' );
// Enable shortcodes in text widgets
add_filter(\'widget_text\',\'do_shortcode\');