Note that there are some explanatory texts on larger screens.

plurals
  1. POCakephp data validation "notEmpty" "required"
    primarykey
    data
    text
    <p>I'm a newbie to cake, done the blog tutorial and now I'm trying something simple to start. But I got something I can't understand. On model PersonalInformation I got the data validation for the table fields:</p> <p>This is my model with the $validate array:</p> <pre><code>class PersonalInformation extends AppModel { /** * Validation rules * @var $validate */ public $validate = array( "first_name" =&gt; array( "name" =&gt; array( "rule" =&gt; "validName", "message" =&gt; 'Only alpha characters and "." (dots)', ), ), "last_name" =&gt; array( "name" =&gt; array( "rule" =&gt; "validName", "message" =&gt; 'Only alpha characters and "." (dots)', ), ), "birth_date" =&gt; array( "date" =&gt; array( "rule" =&gt; "date", "message" =&gt; "Enter a valid date", ), ), "nickname" =&gt; array( "alphanumeric" =&gt; array( "rule" =&gt; "alphaNumeric", "message" =&gt; "Only alpha-numeric characters", ), ), "gender" =&gt; array( "notEmpty" =&gt; array( "rule" =&gt; "notEmpty", "message" =&gt; "Can't be empty", ), ), ); } // end class </code></pre> <p>And this is my table:</p> <pre><code>CREATE TABLE `personal_informations` ( `id` INT NOT NULL UNIQUE AUTO_INCREMENT, `first_name` VARCHAR(45), `last_name` VARCHAR(45), `birth_date` DATE, `nickname` VARCHAR(45), `is_company` TINYINT DEFAULT 0 NOT NULL, `picture_url` VARCHAR(255), `gender` ENUM('m','f') NOT NULL, `notes` TEXT, `created` DATETIME, `modified` DATETIME, PRIMARY KEY (`id`) ) ENGINE=InnoDB CHARACTER SET=utf8; CREATE INDEX `id_idx` ON personal_informations(id); </code></pre> <p>And here is the view:</p> <pre><code>&lt;!-- /PersonalInformations/add --&gt; &lt;div class=""&gt; &lt;h2&gt;Create a personal information&lt;/h2&gt; &lt;?php echo $this-&gt;Form-&gt;create(); echo $this-&gt;Form-&gt;input( "PersonalInformation.first_name" ); echo $this-&gt;Form-&gt;input( "PersonalInformation.last_name" ); echo $this-&gt;Form-&gt;input( "PersonalInformation.birth_date", array( "separator" =&gt; " - ", "minYear" =&gt; date('Y') - 90, "maxYear" =&gt; date('Y') ) ); echo $this-&gt;Form-&gt;input( "PersonalInformation.nickname" ); echo $this-&gt;Form-&gt;input( "PersonalInformation.is_company", array( "type" =&gt; "checkbox" )); echo $this-&gt;Form-&gt;input( "PersonalInformation.piture_url", array( "type" =&gt; "file" )); echo $this-&gt;Form-&gt;radio( "PersonalInformation.gender", array( "m" =&gt; __("Male"), "f" =&gt; __("Female")), array( "hiddenField" =&gt; false )); echo $this-&gt;Form-&gt;textarea( "PersonalInformation.notes" ); echo $this-&gt;Form-&gt;end( "Done" ); ?&gt; &lt;/div&gt; </code></pre> <p>So the problem is that for some reason the "nickname" is kind of required, I mean, when I click on submit button with the "nickname" empty it shows "Only alpha-numeric characters". And for the "gender" it doesn't show anything when none is selected.</p> <p>If there is anything else that I need to post, just let me know.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload