Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

CodeIgniter form validation

Featured Replies

Hello all,

 

I'm designing a web page using CodeIgniter that allows the user to update their personal details. The form consists of three textfileds, this includes 'Password' 'Re-Type password' and an 'Upload new image'. I've designed these forms in the past, just not using an MVC.

 

I'm using this line of code;

 
$this->form_validation->set_rules('password', 'Password', 'required|callback_compare_password');
 

As you can see I'm calling a function called 'compare_password' that checks if the field matches the retype field'. This works fine. However, I want the user to be allowed to either just change their password and/or change the image. If I change the password then it updates the DB fine and if I change bot the password and image it also updates the DB fine but if I only change the image then it displays the error message informing the user to enter their password.

 

This is fine but I want to display this error message only when the user enters their password. for example:

 
if(empty($this->input->post('password')))
{
 ........upload image 
}
else
{
 ..............do something else
 

the above line checks if the form field is empty and if so checks if the file is not empty then uploads new image and updates DB if both are not empty update both password and image and so on, there's only three permutations.

 

What I'm wondering does CodeIgniter have a function that checks if a field is empty and if so ignores it. I've Googled around but can't find anything on it. If it doesn't I'll just have to use my own function to do the job.

 

 

  • 3 weeks later...

i have use form validation following method on code igniter

<?php
class Form extends CI_Controller {
function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}

?>

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.