TECHNICALSTUDY

The associate of technical study article for computer science students which could gain the knowledge about to technicals like Computer history, hard disk, printer,central processing unit etc. Technicalstudy also considered software engineering, operating system and some chunks of programming languages.

Email subscription

Enter your email address:

Delivered by FeedBurner

Saturday, April 23, 2022

CodeIgniter 4 Form Validation

Acontroller.php ----------------- validation( // ['Name' =>'required| min_length[4]', // 'Email'=>'required|valid_email', // 'Password' =>'required|min_length[5]', // 'Mobile' => 'required|numeric|max_lenght[10]', // 'Address' =>'required|max_lenght[10]' // ]); // $model = new Cimodel(); // if (!$input) { // echo view('registration', ['validation' => $this->validator ]); // }else{} public function store() { helper(['form','url']); $input = $this->validate( [ 'name' =>'required', 'email'=>'required|valid_email', 'pass1' =>'required|min_length[6]', 'mobile' => 'required|numeric|max_length[10]', 'address' =>'required', ]); $model = new Cimodel(); if(!$input) { echo 'Not Validate'; echo view('registration',['validation' => $this->validator]); }else{ $data=[ 'Name' => $this->request->getPost('name'), 'Email' => $this->request->getPost('email'), 'Password' => $this->request->getPost('pass1'), 'Mobile' => $this->request->getPost('mobile'), 'Address' => $this->request->getPost('address') ]; $model->save($data); if ($model) { echo "Inserted Successfully."; } else { echo "not insert"; } } } } ?> ------------------------------------------------------------------------------ View-registration.php Registration Form

Registration Form

getError('name')) {?>
getError('name'); ?>
getError('email')){?>
getError('email')?>
getError('pass1')){?>
getError('pass1')?>
getError('mobile')){?>
getError('mobile')?>
getError('address')){?>
getError('address')?>
----------------------------------------------------------------------------------------- Model--Cimodel.php --------------------------- SETUP ROUT-- $routes->get('/', 'Home::index'); $routes->get('/register','Acontroller::index'); $routes->Post('/SaveData','Acontroller::store');

No comments:

Post a Comment

Adbox