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

  • Home
  • SEARCH
  • 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 6689607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:32:21+00:00 2026-05-26T05:32:21+00:00

I wrote a custom validation method inside my Submission model that basically allows a

  • 0

I wrote a custom validation method inside my Submission model that basically allows a blank input field, but once someone enters something in it, it’ll validate the data entered.

The validation inside my Submission Model looks like this (All other validation rules are working except for ‘description’):

    var $validate = array(
    'title' => array(
        'title' => array(
            'rule' => 'notEmpty',
            'required' => true,
            'allowEmpty' => false,
            'message' => 'Please enter a title'
        ),
        'minLength' => array(
            'rule' => array('minLength', 5),
            'message' => 'Please make your title longer'
        ),
        'maxLength' => array(
            'rule' => array('maxLength', 300),
            'message' => 'Your title needs to be shorter'
        ),
    ),
    'description' => array(
        'checkDescription' => array(
            'rule' => array('validateDescription'),
            'message' => 'Description must be greater than 5 characters'
        ),
    ),
    'source' => array(
        'source' => array(
            'rule' => 'notEmpty',
            'required' => true,
            'allowEmpty' => false,
            'message' => 'Enter a valid source URL'
        ),
        'website' => array(
            'rule' => 'url',
            'message' => 'Please enter a valid source URL'
        ),
    )
);

My method which is also in my Submission model (below the above code) is:

    public function validateDescription($data) {
    if(empty($data['Submission']['description']))
        return true;

    if((strlen($data['Submission']['description'])) <= 5)
        return false;
}

I’m not sure why this isn’t working at all. In my view, I’ve got this to display the error:

    if ($form->isFieldError('Submission.description'))
    echo ($form->error('Submission.description', null, array('class' => 'error')));

The only reason I’m trying to do this, is because using the normal validation with required => false and allowEmpty => true along with a minLength and maxLength validation rule weren’t behaving how I intended.

Any help would be greatly appreciated! 🙂

  • 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-26T05:32:21+00:00Added an answer on May 26, 2026 at 5:32 am

    The $data variable passed into the validation method only contains array($fieldname => $value). You’re also not returning true for strings over length of 5. Your method should look like this:

    public function validateDescription(array $data) {
        $value = current($data);
        return !$value || strlen($value) > 5;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Authlogic. I've got an Entry model and there is a validation method
to custom validate an input i wrote a script: function cardNumberCheck(value, element) { var
I'm trying to write my own Custom Validation attribute but I'm having some problems.
I wrote simple custom validation on javascript based on this doc . I want
I wrote a custom wysiwyg extension. I noticed that when it is generated it
I want to write a custom view engine that returns custom text (like coma
I'm trying to write a custom WPF ValidationRule to enforce that a certain property
I'm trying to write a custom function that will let me retrieve a cell
I would like to write a plug-in that will allow a custom written CRM
I'm trying to write a custom method to validate a date. The date however

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.