You are probably running into the HTML5 validation that was added in 2.3:
On Tuesday, July 15, 2014 3:49:37 AM UTC-4, Lorenzo Milesi wrote:
-- - The FormHelper now also adds the HTML5 required attribute to your input elements based on validation rules for a field. If you have a "Cancel" button in your form which submits the form then you should add'formnovalidate' => true to your button options to prevent the triggering of validation in HTML. You can also prevent the validation triggering for the whole form by adding 'novalidate' => true in your FormHelper::create() options.
See this link for more information on changes in the FormHelper:
http://book.cakephp.org/2.0/en/appendices/2-3-migration-guide.html#formhelper
On Tuesday, July 15, 2014 3:49:37 AM UTC-4, Lorenzo Milesi wrote:
Hi.
I did a massive upgrade from 2.0 series to 2.5, now I'm stuck with some errors in a form. I have two issues: 1. for some fields, which should not be compulsory, I get empty errors. 2. when I have errors the HTML structure gets corrupted and the page view is broken.
I'm new to Cake, I've taken over this project and I'm starting to use it. I'm experienced in PHP and other frameworks, tough.
This is the UserDetail module validation:
public $validate = array(
'user_id' => array(
'numeric' => array(
'rule' => array('numeric'),
),
),
'sex_id' => array(
'numeric' => array(
'rule' => array('numeric'),
'message' => 'Please specify your sex',
),
),
'birth' => array(
'date' => array(
'rule' => array('date'),
'message' => 'Please select your date of birth',
),
),
/*'organization' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please specify your organization name',
),
),*/
'country_id' => array(
'numeric' => array(
'rule' => array('numeric'),
'message' => 'Please select your country',
),
),
'state_province' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please select your province',
),
),
'city' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please complete the city field',
),
),
'url' => array(
'url' => array(
'rule' => array('url'),
'message' => 'Please specify a correct URL',
'allowEmpty' => true,
'required' => false,
),
),
'bio' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please provide some information about you',
'allowEmpty' => true,
),
),
'secret' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please create a secret question',
),
),
'secret_answer' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please supply an answer to the above question',
),
),
'discoverable' => array(
'boolean' => array(
'rule' => array('boolean'),
),
),
);
This is the user add template:
<div class="grid_24">
<div class="clear"> </div>
<?php echo $this->Form->create('User', array('type' => 'file', 'url' => array('controller' => 'users', 'action' => 'add'), 'class' => 'WfGenericForm')); ?>
<div class="grid_6">
<h2><legend><?php echo __('Sign Up') . " "; /* .$this->Html->link(__('(Knowledge Base)'), array('controller' => 'pages', 'action' => 'view','knowledge-base'), array('style' => 'font-size:12px;', 'target' => '_blank')); */ ?></legend></h2>
<?php
echo $this->Form->inputs(array(
'legend' => false,
'fieldset' => false,
'name' => array('label' => $this->element('form_tooltip', array('code' => 'register_name')) . __('Name')),
'surname' => array('label' => $this->element('form_tooltip', array('code' => 'register_surname')) . __('Surname')),
'email' => array('label' => $this->element('form_tooltip', array('code' => 'register_email')) . __('Email')),
'UserDetail.organization' => array('label' => $this->element('form_tooltip', array('code' => 'register_organization')) . __('Organization')),
'user_types_id' => array('label' => 'User Type', 'type' => 'select', 'options' => $userTypes),
//'username',
'password',
'confirm_password' => array('type' => 'password', 'label' => __('Confirm Password')),
'UserDetail.url' => array('label' => __('Website URL')),
));
?>
</div>
<div class="grid_2 alpha omega"> </div>
<div class="grid_6">
<h2><legend> </legend></h2>
<?php
echo $this->Form->inputs(array(
'legend' => false,
'fieldset' => false,
'UserDetail.sex_id' => array('type' => 'select', 'options' => $sexes, 'label' => __('Sex')),
'UserDetail.birth' => array(
'label' => __('Date of Birth'),
'type' => 'date',
'dateFormat' => 'DMY',
'minYear' => date('Y') - 70,
'maxYear' => date('Y') - 18,
'before' => '',
'between' => '',
'after' => '',
'separator' => ''
),
'UserDetail.country_id' => array('label' => __('Country'), 'options' => $countries),
'UserDetail.state_province' => array('label' => __('State / Province')),
'UserDetail.city',
'UserDetail.bio' => array('type' => 'textarea', 'label' => $this->element('form_tooltip', array('code' => 'register_about_yourself')) . __('About Yourself (Bio)')),
));
?>
</div>
<div class="grid_2 alpha omega"> </div>
<div class="grid_6">
<h2><legend> </legend></h2>
<?php
echo $this->Form->inputs(array(
'legend' => false,
'fieldset' => false,
'UserDetail.secret' => array('label' => __('Secret Question (create one)'), 'type' => 'textarea'),
'UserDetail.secret_answer' => array('type' => 'textarea'),
'UserDetail.key' => array('label' => 'Security Key (choose up to 5 characters)', 'value' => substr(str_shuffle(substr(String::uuid(), 8, 15)), 0, 10), 'maxlength' => '10'),
'UserDetail.discoverable' => array('type' => 'select', 'options' => array('1' => 'Yes', '0' => 'No'), 'label' => __('Do you want to be discoverable on this site?')),
'User.profile_image' => array('type' => 'file', 'label' => __('Profile Image')),
'active' => array('type' => 'hidden', 'value' => '0'),
'date' => array('type' => 'hidden', 'value' => date('Y-m-d')),
));
?>
</div>
<div class="clear"></div>
<div>
<?php
$options = array(
'type' => 'submit',
'label' => __('Create My User Account') . " >",
'value' => 'Register >',
'class' => 'btn btn-large btn-hau-grey',
'style' => 'font-weight:bold;font-size:1.4em;float:left;clear:none; margin:50px 0 50px 20px;'
);
?>
<div style="float:left;clear:none;margin:50px 0 0 180px;">
<?php
echo $this->Form->inputs(array(
'legend' => false,
'fieldset' => false,
'privacy_policy' => array('label' => __('I agree to the %s', $this->Html->link(__('Privacy Policy'), array('controller' => 'pages', 'action' => 'view', 'privacy-policy'), array('class' => 'label label-info cbox', 'rel' => 'privacy'))), 'type' => 'checkbox', 'value' => '1'),
'terms_of_service' => array('label' => __('I agree to the %s', $this->Html->link(__('Terms of Service'), array('controller' => 'pages', 'action' => 'view', 'terms-of-service'), array('class' => 'label label-info cbox', 'rel' => 'terms'))), 'type' => 'checkbox', 'value' => '1')
));
?>
</div>
</div>
<div style="foat:left;clear:none;">
<?php echo $this->Form->end($options); ?>
</div>
</div>
This is the form_tooltip.ctp file:
$this->Html->script('https://ajax.googleapis.com/ajax/libs/ ', array('once' => true,'inline'=>false));jquery/1.7.2/jquery.min.js
$this->Html->script('bootstrap/bootstrap.min', array('once' => true,'inline'=>false));
$this->Html->css('bootstrap/css/bootstrap.min');
$this->Html->script('form_tooltip', array('once'=>true,'inline'=> false));
$messages = array(
// PROJECT CREATION
'project_title' =>
__('This is the title by which people will identify your project site wide.'),
'project_description' =>
__('This will describe your project, it is vital that the first 20 - 30 words are the most descriptive.'),
'project_start_date' =>
__('On which date does this project start?'),
'project_end_date' =>
__('On which date does this project end?'),
// USER REGISTRATION
'register_name' =>
__("Your first name, required"),
'register_surname' =>
__("Your last name, required"),
'register_email' =>
__("Your email address, you'll use this to log in to Trust Hau"),
'register_organization' =>
__("The organization you represent, if any"),
'register_about_yourself' =>
__("A short blurb about you, this adds a personal touch to your projects")
);
?>
<span<?php echo isset($style) && $style ? ' style="' . $style . '"' : ""; // $this->Html->image('icons/ico_tooltip-help.png') ?>>
<?php echo $this->Html->link('<span class="icon-question-sign"></span>', '#', array('escape' => false, 'rel' => 'tooltip', 'class' => 'icon icon-help', 'title' => $messages[$code])); ?>
</span>
<div class="WfTooltipMsg">
<div style="float:right;clear:none;margin:0 0 5px 5px;padding:0;color:#000;font- weight:bold;" class="exit">X</div>
<?php echo $messages[$code]; ?>
</div>
In my form if I omit "bio" or "url" the form is not considered valid. If I var_dump validationErrors I get array keys for bio and others but with empty message.
Why this? Any hint?
thanks
--
Lorenzo Milesi - lorenzo...@yetopen.it
YetOpen S.r.l. - http://www.yetopen.it/
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment