Well, I can see a few problems straight away:
* You're confusing the 'required' and 'allowEmpty' validation keys.
'required' means it must be present in the array, 'allowEmpty'
controls whether empty values are allowed. 'allowEmpty' is checked
before anything else, so an empty field without `'allowEmpty' =>
false` won't even make it to your validation routine.
* Your regular expressions are erroneous:
(In your first post)
'rule' => array('custom', '/[A-Z]{2}$/i'),
You've specified in the comments 'Must exist and be two capital
letters, eg CA', whereas your regexp says 'must end with 2 letters'. A
more correct one would be
'/^[A-Z]{2}$/'
* the 'comparaison' validation isn't type-specific. So your
`array('comparison', '>=', 1)` doesn't mean "must be a number not less
than one", it means "must not come after 1 when sorted
alphabetically". Try using a regular expression like '/^[1-9][0-9]*
$/' (which means first character must be 1..9, all the others must be
0..9).
Also, your form generation code looks incredibly verbose. You might
want to look into the FormHelper::inputs() method. I get a complicated
form layout with this code:
<div class="col">
<?php
$fields = array(
'legend' => 'Account Login Details',
'defaults' => array('before' => '<div class="label">', 'between' =>
'</div><div class="field">', 'after' => '</div>'),
'Customer.email' => array('size' => 30),
'Customer.password' => array('size' => 30),
'Customer.confirm_email' => array('size' => 30),
'Customer.confirm_password' => array('size' => 30, 'type' =>
'password'),
);
echo $form->inputs($fields);
?>
</div>
<div class="col">
<?php
$fields = array(
'legend' => 'Your Details',
'defaults' => array('before' => '<div class="label">', 'between' =>
'</div><div class="field">', 'after' => '</div>'),
'Customer.firstname' => array('size' => 30),
'Customer.surname' => array('size' => 30),
'Customer.tos' => array('div'=>true,
'type'=>'checkbox', 'class' => 'checkbox', 'label' => 'I agree to the
' . $html->link('Terms of Service', '/pages/terms', array('target' =>
'_blank')))
);
echo $form->inputs($fields);
?>
<?php echo $form->submit('submit-button.png', array('alt' =>
'Submit')); ?>
</div>
(Note that the confirm_email, confirm_password and tos do not
correspond to fields in the schema, but they do have validation
entries).
Anyway, hope this helps
grigri
On Apr 24, 10:12 pm, Jee <[EMAIL PROTECTED]> wrote:
> Why won't the validation messages for 'state' and 'agreed_to_terms'
> show up on the form below when an error is made?
> The validations and the action are below the form code.
>
> I could have written this stupid thing ten times over in the time I
> have been fighting with cakephp over this.
>
> Thanks for any help!
> Jee
>
> The Form:
> =======================================================================================
> echo "<fieldset><legend>Agency Details</legend>";
> echo "<p class='required'>Items marked like this are required.</p>";
>
> echo $form->label('name', 'Name', array('class' => 'required'));
> echo $form->input('name', array('tabindex' => $tabvar++, 'label' =>
> false, 'div' => false));
>
> echo $form->label('address', 'Address', array('class' =>
> 'required'));
> echo $form->input('address', array('tabindex' => $tabvar++, 'label'
> => false, 'div' => false));
>
> echo $form->label('address_continued', 'Address Continued', null);
> echo $form->input('address_continued', array('tabindex' => $tabvar+
> +, 'label' => false, 'div' => false));
>
> echo $form->label('city', 'City', array('class' => 'required'));
> echo $form->input('city', array('tabindex' => $tabvar++, 'label' =>
> false, 'div' => false));
>
> echo $form->label('state', 'State', array('class' => 'required'));
> echo $form->select('state', array('options' =>
> $geography->stateList(), 'tabindex' => $tabvar++, 'label' => false, 'div' =>
>
> false));
>
> echo $form->label('county', 'County', array('class' =>
> 'required'));
> echo $form->input('county', array('tabindex' => $tabvar++, 'label'
> => false, 'div' => false));
>
> echo $form->label('zip', 'Zip', array('class' => 'required'));
> echo $form->input('zip', array('tabindex' => $tabvar++, 'label' =>
> false, 'div' => false));
>
> echo $form->label('phone', 'Phone', array('class' => 'required'));
> echo $form->input('phone', array('tabindex' => $tabvar++, 'label'
> => false, 'div' => false));
>
> echo $form->label('secondary_phone', 'Secondary Phone', null);
> echo $form->input('secondary_phone', array('tabindex' => $tabvar++,
> 'label' => false, 'div' => false));
>
> echo $form->label('fax', 'Fax', null);
> echo $form->input('fax', array('tabindex' => $tabvar++, 'label' =>
> false, 'div' => false));
>
> echo $form->label('federal_taxid', 'Federal Tax ID', array('class'
> => 'required'));
> echo $form->input('federal_taxid', array('tabindex' => $tabvar++,
> 'label' => false, 'div' => false));
>
> echo "</fieldset><fieldset><legend>Primary Contact Details</
> legend>";
>
> echo $form->label('contact_name', 'Name', array('class' =>
> 'required', 'for' => 'MemberContactName'));
> echo $form->input('contact_name', array('name' => 'data[Member]
> [contact_name]', 'id' => 'MemberContactName', 'tabindex' => $tabvar++,
> 'label' => false, 'div' => false));
>
> echo $form->label('email', 'Email', array('class' => 'required',
> 'for' => 'MemberEmail'));
> echo $form->input('email', array('name' => 'data[Member][email]',
> 'id' => 'MemberEmail', 'tabindex' => $tabvar++, 'label' => false,
> 'div' => false));
>
> echo $form->label('referral_id', 'Referred by', array('class' =>
> 'required'));
> echo $form->input('referral_id', array('multiple' => true,
> 'tabindex' => $tabvar++, 'label' => false, 'div' => false));
>
> echo $form->checkbox('agreed_to_terms', array('label' => false,
> 'tabindex' => $tabvar++, 'div' => false));
> echo $form->label('agreed_to_terms', 'I Have Read And Agree To <a
> href=\'/pages/terms\' target=\'_new\'>All Terms and Conditions</a>',
> array('class' => 'required'));
>
> echo "</fieldset>";
>
> echo $form->end('Submit', array('tabindex' => $tabvar++, 'div' =>
> false));
> ========================================================================================
>
> The Validations:
> ==Agency
> Model========================================================================================
>
> var $validate = array(
> 'name' => array(
> 'between' => array(
> 'rule' => array('between', 2, 255),
> 'required' => true,
> 'message' => 'Required. Between 2 and 255 characters.'
> ),
> 'unique' => array(
> 'rule' => array('checkUnique', 'name'),
> 'required' => true,
> 'message' => 'Required. Must be unique.'
> )
> ),
> 'address' => array(
> 'between' => array(
> 'rule' => array('between', 2, 45),
> 'required' => true,
> 'message' => 'Required. Between 2 and 45 characters.'
> )
> ),
> 'city' => array(
> 'between' => array(
> 'rule' => array('between', 2, 45),
> 'required' => true,
> 'message' => 'Required. Between 2 and 45 characters.'
> )
> ),
> 'county' => array(
> 'between' => array(
> 'rule' => array('between', 2, 35),
> 'required' => true,
> 'message' => 'Required. Between 2 and 35 characters'
> )
> ),
> 'zip' => array(
> 'zip_required' => array(
> 'rule' => array('postal', null, 'us'),
> 'required' => true,
> 'message' => 'Valid US Postal Code required.'
> )
> ),
> 'phone' => array(
> 'phone_required' => array(
> 'rule' => array('phone', null, 'us'),
> 'required' => true,
> 'message' => 'Valid US phone number required.'
> )
> ),
> 'state' => array(
> 'state_required' => array(
> 'rule' => array('minLength', 2),
> 'required' => true,
> 'message' => 'Please select a State.'
> )
> ),
> 'federal_taxid' => array(
> 'federal_taxid_required' => array(
> 'rule' => array('custom', '/[0-9]{2}-[0-9]{7}$/i'),
> 'required' => true,
> 'message' => 'Your Agency\'s Federal Tax ID is required.
> Format: 12-3456789.'
> )
> ),
> 'referral_id' => array(
> 'referral_id_required' => array(
> 'rule' => array('comparison', '>=', 1),
> 'required' => true,
> 'message' => 'Please select one of the \'Referred by\'
> options.'
> )
> ),
> 'agreed_to_terms' => array(
> 'agreed_to_terms_required' => array(
> 'rule' => array('comparison', '=', 1),
> 'required' => true,
> 'message' => 'You must agree to the Terms and Conditions for
> StatePayments.com.'
> )
> )
> );
>
> ==Member
> Model====================================================================================================
> var $validate = array(
> 'contact_name' => array(
> 'alphanumeric' => array(
> 'rule' => 'alphaNumeric',
> 'required' => true,
> 'message' => 'Required. Letters and numbers only.'
> )
> ),
> 'email' => array(
> 'email_required' => array(
> 'rule' => 'email',
> 'required' => true,
> 'message' => 'A valid email is required to complete the signup
> process.'
> )
> )
> );
> =====================================================================================================================
>
> The Controller & Action:
> ==================================================================================================================
> class AgenciesController extends AppController {
>
> var $name = 'Agencies';
> var $helpers = array('Html', 'Form');
> var $uses = array('Agency', 'Member');
>
> function signup() {
> if (!empty($this->data)) {
> $this->Agency->create();
> if ($this->Agency->saveAll($this->data)) :
> $this->Session->setFlash(__('Thank you for
> joining
> StatePayments.com! Your new account has been saved', true));
> $this->redirect(array('url'=>'/files/
> StatePaymentsSignup.pdf'));
> else :
> $this->Session->setFlash(__('We are sorry but
> your new account
> could not be saved. Please, check the Agency Details for errors and
> try again.', true));
> endif;
> }
> $referrals = $this->Agency->Referral->find('list');
> $this->set(compact('referrals'));
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---