I am trying to get errors from the Model to show up on form submission. I do not save this data anywhere on the DB, so not using the save method. The problem is that I am unable to see the validation errors set in the Model AnonymousRider. Code follows- ctp file
<?php
echo $this -> Form -> create(null, array('action' => 'confirmBooking'));
echo $this -> Form -> input('Name', array('type' => 'text', 'id' => 'name', 'placeholder' => 'Name'));
echo $this -> Form -> input('AnonymousRider.email', array( 'id' => 'email', 'placeholder' => 'Email'));
echo $this -> Form -> input('AnonymousRider.phone_number', array( 'type' => 'tel', 'id' => 'number', 'placeholder' => 'Mobile Number'));
echo $this -> Form -> input('address', array('type' => 'textarea', 'id' => 'pickup-point', 'placeholder' => 'pickup address and landmark details', 'required' => 'true'));
echo $this -> Form -> input('tnc', array('type' => 'checkbox', 'id' => 'tnc', 'required' => 'true'));
echo $this->Html->link('Terms and conditions', '/pages/home', array('class' => 'button', 'target' => '_blank'));
$options = array('label' => 'Book Now', 'class' => 'btn btn-success .btn-large');
echo $this -> Form -> end($options);
?>
Following is the model-
var $name = 'AnonymousRider';
public $validate = array
(
'phone_number' => array('rule' => array('phone', null, 'us'), 'message' => 'valid phone number required'),
'email' => array('rule' => 'email', 'message' => 'valid phone number required'),
);
}?>
I can see that the model rules are generating a required around the HTML. See HTML-
<form action="/91/itinerary_requests/confirmBooking" id="ItineraryRequestConfirmBookingForm" method="post" accept-charset="utf-8">
<div style="display:none;">
<input type="hidden" name="_method" value="POST">
</div>
<div class="input text">
<label for="name">Name</label>
<input name="data[ItineraryRequest][Name]" id="name" placeholder="Name" type="text">
</div>
<div class="input email required">
<label for="email">Email</label>
<input name="data[AnonymousRider][email]" id="email" placeholder="Email" maxlength="256" type="email" required="required">
</div>
<div class="input tel required">
<label for="number">Phone Number</label>
<input name="data[AnonymousRider][phone_number]" id="number" placeholder="Mobile Number" type="tel" required="required">
</div>
<div class="input textarea">
<label for="pickup-point">Address</label> <textarea name="data[ItineraryRequest][address]" id="pickup-point" placeholder="pickup address and landmark details" required="required" cols="30" rows="6"></textarea>
Tnc Terms and conditions
you can validate your data in your controller
see manual
all you have to do is somethin like:
if ($this->ModelName->validates()) {
// it validated logic
} else {
// didn't validate logic
$errors = $this->ModelName->validationErrors;
}