So I understand that CakePHP automatically loads the error message into the view if you validate it against the Model’s validators. I am trying to setup a date dropbox validation, and I want to control where the error message shows up.
Before submitting to validate form:
<div class="input text required">
<label for="UserEmail">Email</label>
<input name="data[User][email]" maxlength="50" type="text" id="UserEmail">
</div>
After validating, error shows up here:
<div class="input text required error">
<label for="UserEmail">Email</label>
<input name="data[User][email]" maxlength="50" type="text" value="" id="UserEmail" class="form-error">
<div class="error-message">An email is required</div>
</div>
Is it possible to control it where I can have it show up here?
<div class="input text required error">
<div class="error-message">An email is required</div>
<label for="UserEmail">Email</label>
<input name="data[User][email]" maxlength="50" type="text" value="" id="UserEmail" class="form-error">
</div>
Or here:
<div class="error-message">An email is required</div>
<div class="input text required error">
<label for="UserEmail">Email</label>
<input name="data[User][email]" maxlength="50" type="text" value="" id="UserEmail" class="form-error">
</div>
In the VIEW:
1) Disable automatic error display:
2) Get the current form errors from
$this->validationErrors3) Display them where ever you prefer with your own markup or Cake’s default markup via $this->Form->error()
UPDATE:
I misunderstood your original question. The order of the elements can be specified via either the create() call (to apply to all fields) or an input() call (for an individual field):
The above would place the
errordiv before thelabeldiv. You can re-arrange that array in any order you prefer.