Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6863137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:44:45+00:00 2026-05-27T02:44:45+00:00

$crud->set_rules(‘user_password’, ‘Password’, ‘trim|required|matches[konfirmpass]’); $crud->set_rules(‘konfirmpass’, ‘Konfirmasi Password’, ‘trim|required’); $crud->callback_edit_field(‘user_password’,array($this,’_user_edit’)); $crud->callback_add_field(‘user_password’,array($this,’_user_edit’)); callback function: function _user_edit(){ return

  • 0
$crud->set_rules('user_password', 'Password', 'trim|required|matches[konfirmpass]');
$crud->set_rules('konfirmpass', 'Konfirmasi Password', 'trim|required');

$crud->callback_edit_field('user_password',array($this,'_user_edit'));
$crud->callback_add_field('user_password',array($this,'_user_edit'));

callback function:

function _user_edit(){
    return '<input type="password" name="user_password"/>  Confirmation password* : <input type="password" name="konfirmpass"/>';   
}

My question is how to update if only “password” not blank?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:44:45+00:00Added an answer on May 27, 2026 at 2:44 am

    I’ve installed CI 2.0.3 and GC 1.1.4 to test because at a glance your code looked fine. As it turns out, it is and your code works. I modified the out of the box employees_management method in the examples controller with GC. Added a user_password column to the database and added your code to the controller.

    The code both ensures that the password fields match and that they’re not empty when submit.

    • Empty results in "The Password field is required"
    • Mismatched results in "The Password field does not match the konfirmpass field."

    Perhaps if this isn’t working for you, you should post your entire method instead of just the rules and callbacks so we can see if there are any other problems.

    Working

    Edit

    To edit the field, only if the password has been edited you need to add

    $crud->callback_before_update( array( $this,'update_password' ) );
    
    function update_password( $post ) { 
    if( empty( $post['user_password'] ) ) {
        unset($post['user_password'], $post['konfirmpass']);
    }
    
    return $post;
    }
    

    This however may mean that you need to remove the validation for empty password depending on which order the callbacks run (if they’re before or after the form validation runs). If they run before the form validation, you’ll need to also need to run a call to callback_before_insert() and add your validation rules within the two callbacks. Insert obviously will need the required rule, and update won’t.

    Edit 2, Clarification of Edit 1

    Having looked into it, the validation runs before the callbacks, so you can’t set validation rules in the callback functions. To achieve this you’ll need to use a function called getState() which allows you to add logic based on the action being performed by the CRUD.

    In this case, we only want to make the password field required when we are adding a row, and not required when updating.

    So in addition to the above callback update_password(), you will need to wrap your form validation rules in a state check.

    if( $crud->getState() == 'insert_validation' ) {
        $crud->set_rules('user_password', 'Password', 'trim|required|matches[konfirmpass]');
        $crud->set_rules('konfirmpass', 'Konfirmasi Password', 'trim|required');
    }
    

    This will add the validation options if the CRUD is inserting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this route in bootstrap.php ... Route::set('crud', 'staff/<controller>(/<action>(/<id>))', array( 'controller' => '(activities|users|default-emails)', 'action' =>
I am making a CRUD application in jquery and i have this problem in
I have a Java program which does CRUD on a MySQL database. For this,
I have this code that: When you edit the UserProfile (with the corresponding CRUD
I'm learning spring hibernate zk stack, and doing my first crud following this tutorial
What frameworks are targeted specifically at building so-called CRUD Admin UIs (basically, a set
I am executing some crud's on mssql server 2008 database by connecting remotely. I
I have a simple Crud application where there is one filed called Category. During
When it comes to CRUD operations and your database (SQL Server '08), is it
I haved generated simple CRUD application from seam-gen using seam generate-ui command, but the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.