I'm using shortcode to process my HTML form. However, upon submit no result is being displayed. I'm not getting where I'm going wrong.
<?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
?>
form_processing()
is echoing the value and you are returning $output Why dont you tryfunction result_form() { ob_start(); form_processing(); $output = display_result_form_fields(); return ob_get_clean(); }