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 7803977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:45:42+00:00 2026-06-02T01:45:42+00:00

I am creating a User Model using Codeigniter and php-activerecord and the wiki says

  • 0

I am creating a User Model using Codeigniter and php-activerecord and the wiki says I can use ‘on’ => ‘create’ to have a validation only run when a new record is created, like this,

static $validates_presence_of = array(
    array('title', 'message' => 'cannot be blank on a book!', 'on' => 'create')
);

It also states that we have access to “save”, “update” and “delete”…

None of these are working for me though and I can figure out why, here is my code,

// Validations
static $validates_presence_of = array(
array('email', 'message' => 'Please enter a valid email address.'),
array('password', 'message' => 'Password must be provided.', 'on' => 'create')
);

I want to set it up like this so that when a user updates their profile, they can leave their password blank to keep their current one.

I would appreciate any help or guidance! Thanks!

  • 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-06-02T01:45:44+00:00Added an answer on June 2, 2026 at 1:45 am

    The reason for this is most likely because it’s not been implemented.

    Relevant classes are lib/Model.php and lib/Validations.php

    From a purely abstract standpoint, you would need to track the mode of operation between save and create. To do this, I created a public property (public $validation_mode) within lib/Model.php and set that property to ‘create’ or ‘save’ in private methods Model::insert() and Model::update() respectively. These values match the ‘on’ property you are trying to use.

    Then within lib/Validations.php, I modified the following methods:

    Validations::validates_presence_of()

    public function validates_presence_of($attrs)
    {
        $configuration = array_merge(self::$DEFAULT_VALIDATION_OPTIONS, array('message' => Errors::$DEFAULT_ERROR_MESSAGES['blank'], 'on' => 'save'));
    
        foreach ($attrs as $attr)
        {
            $options = array_merge($configuration, $attr);
            $this->record->add_on_blank($options[0], $options['message'], $options);
        }
    }
    

    Errors::add_on_blank()

    public function add_on_blank($attribute, $msg, $options = array())
    {
        if (!$msg)
            $msg = self::$DEFAULT_ERROR_MESSAGES['blank'];
    
        if (($value = $this->model->$attribute) === '' || $value === null)
                {
                        if(array_key_exists('on', $options))
                        {
                            if($options['on'] == $this->model->validation_mode)
                            {
                                $this->add($attribute, $msg);
                            }
                        } else {                            
                            $this->add($attribute, $msg);
                        }
                }
    }
    

    What this does basically is passes ALL the $options specified in your model (including the ‘on’ property) down to the Errors::add_on_blank() method where it now has enough information to differentiate between ‘on’ => ‘create’ and the default (‘on’ => ‘save’). Using the public $validation_mode property from the Model class ($this->model->validation_mode), we can determine what the current mode of operation is and whether or not we wish to continue adding the error message or skip it this time around.

    Obviously you would want to document any changes you make and test thoroughly. According to the documentation, all validation methods supposedly support this “common option” along side allow_null, allow_blank but again, if it’s not implemented, you will have to make it happen yourself by making these necessary changes.

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

Sidebar

Related Questions

I have a user control called HomePage.xaml . I'm creating a model instance (using
I extended the User model in Django by using Profiles. As you know, creating
I have a rails app that is using Devise, with a User model, no
I'm creating a Rails app, and I have a model called User . In
I am creating a website using asp.net mvc model. When you create an mvc
I'm currently creating a user interface using WPF and would like to display a
I am creating an user registration form using jsp,in which there is an option
I've created my own signup form and creating the user using the Membership class.
I have such view that handles user registration. After creating new user i want
Issue/Question : I'm using CodeIgniter to build an event calendar, and I have included

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.