-
Video : Codeigniter 4 downloading and installing in Hindi
-
Video : Codeigniter 4 installing composer in Hindi
-
Video : Codeigniter 4 folder structure or App structure in Hindi
-
Video : Codeignter 4 desing patters for software in Hindi
-
Video : Codeignter 4 spark in Hindi
-
Video : Codeignter 4 model view controller (MVC) in Hindi
-
Video : Codeignter 4 how URL works in Hindi
-
Video : Codeigniter 4 remove the public folder and Index.php from url in Hindi
-
Video : Codeignter 4 how to create the controllers in Hindi
-
Video : How to create a view in Codeigniter 4 in Hindi
-
Video : How to create the model and pass the values from the controller to model in Hindi
-
Video : Codeigniter 4 Introduction to Codeigniter in Hindi
-
Video : Codeigniter 4 what are builtin helpers and what are custom helpers in Hindi
-
Video : Codeignter 4 form helper in Hindi
-
Video : Codeignter 4 URL helper in Hindi
-
Video : Downloading the latest version of Codeigniter 4 in Hindi
-
Video : Inflector helpers in Codeigniter 4 in Hindi
-
Video : Number helper in Codeigniter 4 in Hindi
-
Video : String helper in Codeigniter 4 in Hindi
-
Video : XML helper in Codeigniter 4 in Hindi
-
Video : HTML helper in Codeigniter 4 in Hindi
-
Video : Date helper in Codeigniter 4 in Hindi
Validation forms in Codeigniter 4
Please Login and enroll in this course to view the lesson.
- How to validate the forms in Codeigniter 4?
- How can you create the HTML forms in Codeigniter 4?
In this section, you will learn how you can create the HTML forms and validate the that fields using Codeigniter 4.
This is your Method to create the HTML form in ci4.
public function register()
{
helper('form');
echo view('user/register');
}
This is HTML code/view
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Welcome in Register</title>
</head>
<body>
<div>
<?php
$myvalidation = ConfigServices::validation();
echo $myvalidation->listErrors();
?>
</div>
<?php echo form_open_multipart('libraries/newuser',['class'=>'muclass','id'=>'myId'])?>
<p>
<label>Your Name</label>
<?php echo form_input('name','',['class'=>'muclass','id'=>'name']); ?>
</p>
<p>
<label>Your Surname</label>
<?php echo form_input('surname','',['class'=>'muclass','id'=>'surname']); ?>
</p>
<p>
<label>Your City</label>
<?php echo form_input('city','',['class'=>'muclass','id'=>'city']); ?>
</p>
<?php echo form_submit('submit','Register Now'); ?>
<?php echo form_close(); ?>
</body>
</html>
In validation.php file use this code
public $newUser = [
'name'=>'required',
'surname'=>'required|min_length[2]|max_length[8]',
'city'=>'required',
];
Validate method
public function newuser()
{
$userTable = new ModUser();
//dd($userTable);
$request = ConfigServices::request();
$validation = ConfigServices::validation();
$randomName = '';
//dd($validation->getRuleGroup('newUser'));
if (!$this->validate($validation->getRuleGroup('newUser'))) {
$this->register();
}
else{
//echo 'fine';
$userData = [
'u_name'=>$request->getPost('name'),
'u_surname'=>$request->getPost('surname'),
'u_city'=>$request->getPost('city'),
];
var_dump($userData);
}
}