user1851359
user1851359

Reputation: 139

Send back value from controller when submit form codeigniter

here is a question that I am not able to find a way to do it. At the home view, I have a php section that will echo out if users input is just signed in when they submit form. But when I am doing this, it will give out a undefined error, because that controller is not yet executed. This is my home view.

<?php include('header.php'); ?> 
<?php echo $sign_in_results;?>
<?php include('forms/forms.php'); ?>
<?php include('footer.php'); ?>

This is my sign in controller, will get execute when submit pressed, the modal will return true or false.

 function form_sign_in_controller(){
    $this->load->model("form_sign_in"); 
    $database_insert_results = $this->form_sign_in->check_user_detail_with_db();
    $data['sign_in_results']= $database_insert_results;
    $template = $this->load->View('main_view', $data);
 }

I tried to use if(isset()).. The error is gone, but that section does not echo out anything. Any idea? Thanks

Upvotes: 0

Views: 514

Answers (1)

cartalot
cartalot

Reputation: 3158

  • validate the data that comes from your sign in form. Never pass data from a form directly into a database query.

  • validating the data will tell you if the form has correct values. if it does not, then show the form again.

  • form data is validated - query your database

  • there are 3 possible results - you got a match OR you did not get a match OR there was an error. Check for these 3 different conditions, and then show the appropriate view.

Upvotes: 0

Related Questions