User Registration and Form Validation Using CodeIgniter

Submitted by: 
Language: 
Visitors have accessed this post 38905 times.

By using CodeIgniter framework, you’ll learn how easy it is to create a registration form with validation using the form_validation library that is built-in with CodeIgniter.

This example demonstrates how to validate every control in your form. One example is the validation of email address. All you have to do is simply specify this argument: valid_email. CodeIgniter will simply look for that function and validate the email for you.

Here’s the example of the form validate in this code sample.

  1. //validate form input
  2. $this->form_validation->set_rules('guest_title', 'Title', 'required|xss_clean');
  3. $this->form_validation->set_rules('first_name', 'First Name', 'required|xss_clean');
  4. $this->form_validation->set_rules('last_name', 'Last Name', 'required|xss_clean');
  5. $this->form_validation->set_rules('birth_date_year', 'Year', 'xss_clean');
  6. $this->form_validation->set_rules('birth_date__nc_month', 'Month', 'xss_clean');
  7. $this->form_validation->set_rules('birth_date__nc_day', 'Day', 'xss_clean');
  8. $this->form_validation->set_rules('company', 'Company', 'xss_clean');
  9. $this->form_validation->set_rules('url', 'Website', 'xss_clean');
  10. $this->form_validation->set_rules('address', 'Address', 'required|xss_clean');
  11. $this->form_validation->set_rules('address_2', 'Address 2', 'xss_clean');
  12. $this->form_validation->set_rules('city', 'City', 'required|xss_clean');
  13. $this->form_validation->set_rules('state', 'State/Province', 'xss_clean');
  14. $this->form_validation->set_rules('country', 'Country', 'required|xss_clean');
  15. $this->form_validation->set_rules('zipcode', 'Zip/Postal code', 'required|xss_clean');
  16. $this->form_validation->set_rules('phone', 'Phone', 'required|xss_clean');
  17. $this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
  18. $this->form_validation->set_rules('username', 'Username', 'required|xss_clean');
  19.  
  20. $this->form_validation->set_rules('password', 'Password', 'required|matches[password_confirm]');
  21. $this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required');

To configure CodeIgniter,please refer to Getting Started With CodeIgniter.


Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

wana have droptsown for all the countries on the world

how to gerata thi sll

hello, thanks before but i have a question how to make it only has single notification,
so notice display step by step not list

Regards

Simple and really helpful

how to Validate Photo field

nice code

gajanan

Hi!

Whenever I run the code it redirect me to register.

Thanks!

dein code hat nur ein grossses loch >>> $config['csrf_protection'] = FALSE; <<
$config['csrf_protection'] = TRUE; <<< sollte es sein ..

your code only has a big hole >>> $config['csrf_protection'] = FALSE; <<
$config['csrf_protection'] = TRUE; <<<it should be .. and I'm also looking for how to do it right

this is used in the latest version of codeigniter sir? version 2.1.3?

when i run the code it redirect me to register , why please?

I also have that problem before. You have to see this:
http://stackoverflow.com/questions/16389485/codeigniters-form-action-is-...

The problem with troubleshooting is that trouble shoots back.

Really help full, Thanks a lot.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.