Codeigniter is one of the best MVC frameworks in PHP, creating a project in Codeigniter framework is simple, when compared to other frameworks called Yii framework and laravel framework.
If we plan to create a project, the first thing we need to create Codeigniter user registration form, in every project when it moves to development stage, first thing we create registration page to get leads.
We all know Codeigniter is MVC Framework which stands for Model, Veiw and controller. So now you understand what files we need, let’s jump into the Codeigniter user registration form.
First we need to create view for registration page , which display in frontend. Let’s create view as registration.php under view folder. If you have good knowledge in HTML and CSS you can design your view using bootstrap, which looks beautiful and mobile friendly. Now I am sharing registration.php file which I created for this demo.
Now in the above code we simple created html form using Div’s, and also we added php tags , here
Which is php opening and closing braces in between we can write our php code, here you find two major php code i.e.
1) set_value(); which helps you to set value to the field
2) form_error(); which show form error, when value is missing or wrong typo.
Now let’s move to controller file , let’s create controller name as user.php and create function as below.
Don’t understand above code? Ok then let’s debug each and every line, after creating the function, first you need to load required libraries for your validations and email.
• For better validation, Codeigniter have inbuilt library for validation and also provide some decent features to restrict cross site scripting.
• You can see syntax for validation as
Now your validation filed looks as below.
If your inputs are wrong it will move to your view registration.php and again you need to enter the valid values. Now if the values you entered are all valid your data will move to model function which looks like below.
And once your data moved to model function insertuserrecord(), the insert code looks like below.
After inserting data to database, we simply return $insertStatus; variable to controller again. Now let’s move to controller again and write code for email notification after successful user registration, let’s check how code looks in controller.
In this code we simply calling inbuilt email library from Codeigniter core files and initialize email , for every email , we have From, To ,CC , SUBJECT, BODY .
In the same format we have functions in the email library, just we need to pass the parameters to send email notifications to registered user.