Controller
Create app/Controllers/Home.php and paste the controller code given below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | <?php namespace App\Controllers; use App\Controllers\BaseController; use App\Models\HomeModel; $this->session = \Config\Services::session(); class Home extends BaseController { public function __construct() { $db = db_connect(); $this->HomeModel = new HomeModel($db); $this->session = \Config\Services::session(); $this->request = \Config\Services::request(); $this->parser = service('renderer'); } public function index() { return view('welcome_message'); } public function register(){ if(!empty($_POST)){ // Form Validation--> $validation = \Config\Services::validation(); $validation->setRules([ 'name' => ['label' => 'Name', 'rules' => 'required|alpha_numeric'], 'phone' => ['label' => 'Phone/Mobile', 'rules' => 'required|greater_than[9]|numeric'], 'email' => ['label' => 'Email Address', 'rules' => 'required|valid_email'], 'organization' => ['label' => 'Organization', 'rules' => 'required|alpha_numeric'], 'designation' => ['label' => 'Designation', 'rules' => 'required'], 'useCase' => ['label' => 'Use Case', 'rules' => 'required'], 'hear_from' => ['label' => 'Hear From', 'rules' => 'required'], 'req' => ['label' => 'Requirement', 'rules' => 'required'] ]); // Form Validation Close--> if(!$validation->withRequest($this->request)->run()) { $datas['errors'] = $validation->listErrors(); echo view('includes/header'); echo view('register',$datas); echo view('includes/footer'); }else{ $register = $this->HomeModel->register(); if($register=="1"){ $datas['success'] = '<div class="alert alert-success" role="alert">Thankyou for your subscription!</div>'; echo view('includes/header'); echo view('register',$datas); echo view('includes/footer'); }else{ $datas['errors'] = '<div class="errors" role="alert"><ul><li>Sorry! Not Subscribed! Please try again.</li></ul></div>'; echo view('includes/header'); echo view('register',$datas); echo view('includes/footer'); } } }else{ echo view('includes/header'); echo view('register'); echo view('includes/footer'); } } } |