Perform validations for the form

I am using jQuery and cakephp for my application.

I have a form created on my page using $form->create. The form contains many fields that the user will fill out and submit; data is saved

function submit($id = null)
{
foreach ($_POST as $key => $value):

        $this->data['Result']['form_id']=$id;//form id
        $this->data['Result']['label']=$key;//this is the fieldname
    $this->data['Result']['value']=$value;//fieldvalue  

endforeach;

    $this->Session->setFlash('Your entry has been submitted.');
  }

Now I want to perform checks in the form, like all the filled field values. If it is not completed, it should show a warning or message asking to fill in the appropriate field. How to do it?

Another suggestion is needed: which would be better, client-side or server-side validation?

+3
source share
1 answer

CakePHP : . , ( " " ..). save, .

:

<?php
class User extends AppModel {
    var $name = 'User';
    var $validate = array(
        'login' => 'alphaNumeric',
        'email' => 'email',
        'born' => 'date'
    );
}
?>
+2

Source: https://habr.com/ru/post/1711729/


All Articles