[eluser]ThatsJustMe[/eluser]
Hello,
So basically, I'm validating a registration form, and if there are any errors, I'm returning them back to controller, so they are displayed in View.
Here are my code -
Model -
Code:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Registration_validate extends CI_Model {
function __construct() {
parent::__construct();
}
function checkData($name, $email, $password, $passwordRepeat, $username, $code, $message) {
global $error;
if($name == '' || $email == '' || $password == '' || $passwordRepeat == '' || $username == '' || $code == '') {
$error.= "All fields must be filled!";
}
else {
if(strlen($name) <= 2) {
$error.= "Tavs ievadītais vārds ir par īsu! <br />";
}
}
if($error) {
return $error;
header("Location: ../registration");
}
}
}
?>
Controller -
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Code:
class Registration extends CI_Controller {
public function index()
{
global $error;
echo $error;
$data['error'] = $error;
$this->load->helper('url');
$this->load->view('includes/header');
$this->load->view('registration', $data);
$this->load->view('includes/footer');
}
public function registrate() {
if(isset($_POST['registrate'])) {
$this->load->model('registration_validate');
$this->registration_validate->checkData($_POST['name'], $_POST['email'], $_POST['password'], $_POST['password-repeat'], $_POST['uname'], $_POST['code'], $_POST['message']);
}
else {
header("Location: ../registration");
}
}
} ?>
View -
Code:
<p><?php echo $error; ?></p>
Hope you will be able to help
!