11.16
php
saved
ovihc
Note
validateField function for validating single fields from a form (using observeField) and passing along the message to the view.
validateField function for validating single fields from a form (using observeField) and passing along the message to the view.
- // view - first, view sends the input to the controller.
- 'url'=>"/wolistings/validateField/postcode",
- 'frequency'=>1)); ?>
- // controller - second, it gets the field contents, sends it to validate, and receives a message.
- function validateField($field = null) {
- if ($this->RequestHandler->isAjax()) {
- $this->Wolisting->set($this->data['Wolisting'][$field]);
- if ($this->Wolisting->create($this->data) && $this->Wolisting->validates()) {
- $this->set('message', null);
- $this->render('validateField', 'ajax');
- }
- else {
- $errorMessages = $this->validateErrors($this->Wolisting);
- foreach ($errorMessages as $val) {
- $errorMessage = $val;
- }
- $this->set('message', $errorMessage);
- $this->render('validateField', 'ajax');
- }
- }
- }
- // validate_field.ctp view - third, if a message is null, then it pasts validation, otherwise it failed and now i have the message.
- <?php
- echo '<img src="/img/cross.gif">';
- }
- ?>
Parsed in 0.063 seconds, using GeSHi 1.0.7.14