Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't change default error messages in CakePHP 2.3
    text
    copied!<p>In my CakePHP project, I want to display error messages but it's not working.</p> <p>When I'm submitting, I want it to display an error message like: "This field is required", but by default it's showing "Please fill out this field". I changed the message, but it's not changing from the core.</p> <p>My View, Model, and Controller codes are as following:</p> <p><code>add_district.ctp</code>:</p> <pre><code> &lt;div class="pg_title txtLeft"&gt;Add District&lt;/div&gt; &lt;?php echo $this-&gt;Form-&gt;create('Admins', array('action' =&gt; 'add_district'));?&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;label&gt;District Name&lt;span class="red required"&gt;*&lt;/span&gt;&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $this-&gt;Form-&gt;input('District.district_name',array('label'=&gt;false,'div'=&gt;false,'size'=&gt;50,'style'=&gt;'width:330px;')); ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2" align="right" style="padding-right: 113px;"&gt;&lt;input type="reset" value="Reset"&gt; | &lt;?php echo $this-&gt;Form-&gt;submit('ADD', array('div' =&gt; false));?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;?php print $this-&gt;Form-&gt;end();?&gt; &lt;div class="clear"&gt;&lt;/div&gt; </code></pre> <p>Model : <code>District.php</code></p> <pre><code>&lt;?php App::uses('AppModel', 'Model'); /** * Admin Login Model * */ class District extends AppModel { public $name='District'; public $usetables='districts'; public $validate = array( 'district_name' =&gt; array( 'rule' =&gt; 'notEmpty', 'allowEmpty' =&gt; false, 'message' =&gt; 'This field is required')); } ?&gt; </code></pre> <p>And my controller Code is (<code>AdminController.php</code>):</p> <pre><code>public function add_district() { $this-&gt;layout='common'; $this-&gt;District-&gt;create(); $this-&gt;District-&gt;set($this-&gt;data); if(empty($this-&gt;data) == false) { if($this-&gt;District-&gt;save($this-&gt;data)) { $this-&gt;Session-&gt;setFlash('District Added Successfully.'); $this-&gt;redirect('add_district'); } } else { $this-&gt;set('errors', $this-&gt;District-&gt;invalidFields()); } } </code></pre>
 

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