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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:25:12+00:00 2026-06-10T06:25:12+00:00

I’m having a strange issue with my form in CakePHP. I have a series

  • 0

I’m having a strange issue with my form in CakePHP. I have a series of questions that start with a check box. If the check box is selected, I want to make two other input fields required. Otherwise, if unchecked, they are optional. I wrote a custom function for validating the input fields. Here is one of them:

public function rn_number () {
 if ($this->data['Education']['rn_box'] == 1) {
    if($this->data['Education']['rn_number'] == '')
        return false
}

return true;
}

public $validate = array(
     'rn_number' => array(
            'rn_number'=>array(
                'rule' => 'rn_number'
                ),
            ),
);

The validation works fine. For the above rule, it checks if the checkbox with the id ‘cna_box’ has a value of 1, or is checked, then check if the input with id ‘cna_number’ is empty. If so, return false. It always required the data to be submitted if the check box is checked. My issue is that it only sometimes indicates there are errors when the required input fields like ‘cna_number’ are blank. On the first submit, it will always indicate that those fields are required. But if you submit the form again, it will not indicate that those fields are required, and it won’t display an error message – making it confusing for the user.

I noted the check boxes had a hidden input. Afer submitting the checkbox, and returning to the pages with errors, the hidden input would have a value of 0 and the checkbox would have a value of 1. Do you think this has anything to do with the problem?

Updated:

Here is the code from my view that generates the form fields in question:

echo $this->Form->inputs(array(
    'legend'=>'Certifications',
    'rn_box'=>array(
        'type'=>'checkbox',
        'label'=>'RN',
        ),
    'rn_number'=>array(
        'label'=>'RN Number:',
        'value' => $results['Education']['rn_number']
        ),
    'rn_exp_date' => array(
        'label' => 'Expiration Date:',
        'dateFormat' => 'MDY',
        'monthNames' => FALSE,
        'minYear' => date('Y'),
        'maxYear' => date('Y') + 20,
        'empty' => TRUE,
        'after' => '<span class="small">(MM/DD/YYYY)</span>',
        'class' => 'input-mini',
        'selected'=>strtotime($results['Education']['rn_exp_date'])
        ),
));

And the controller code:

public function pagethree() { 

        /** 
         ** If user has completed this form, 
         ** grab data for editing 
         **/
        $this->set('results', $this->Education->find('first', array( 
            'conditions' => array('Education.user_id' => $this->Auth->user('id')) 
        ))); 


        if ($this->request->is('post')){   
            $this->request->data['User']['id'] = $this->Auth->user('id'); 

            /** 
             ** Find if there is any data 
             ** in this user in the Basics 
             ** table. 
             **/
            $existingRecordId = $this->Education->find('first', array( 
                'conditions' => array('Education.user_id' => $this->Auth->user('id')), 
                'fields' => array('Education.id') 
            )); 

            /** 
             ** If data exists, return row 
             ** id (PK). Set this value to 
             ** id key, so saveAll() updates 
             ** existing row. 
             **/

            if(sizeof($existingRecordId)>0) 
                $this->request->data['Education']['id'] = $existingRecordId['Education']['id']; 

            if ($this->User->saveAll($this->request->data)) { 
                $this->redirect(array('action'=>'pagefour')); 
            } else { 
                $this->Session->setFlash('Your data have not been saved'); 
            } 
        } 
    } 
  • 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-10T06:25:14+00:00Added an answer on June 10, 2026 at 6:25 am

    well, there you have it. using value and selected are never a good idea. especially if you want to persist the form after submitting and if it invalidates.

    you should either use default or do it from the controller:
    http://www.dereuromark.de/2010/06/23/working-with-forms/
    Chapter “default values”

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.