How do I disable CakePHP's client side email validation?

585 views Asked by At

The kind of validation that pops out even before sending the data to the server. The other fields in my form, namely 'name', 'message', had these too but I removed that by taking their respective validators in my FormTable. Did the same for the email validator but its still there.

The email field checks for the email's validity (having '@' and dots).

This is the form in my view. $form is just an array that will contain values passed through sessions.:

<?= $this->Form->create($message, ['class' => 'form-group']) ?>
<?= $this->Form->input('name', ['value' => $form['name']]) ?>
<?= $this->Form->input('email', ['value' => $form['email']]) ?>
<?= $this->Form->input('message', ['value' => $form['message']]); ?>
<?= $this->Form->button('Submit', ['class' => 'btn btn-primary btn-lg btn-block']) ?>
<?= $this->Form->end() ?>

Im not really sure why my code is needed so sorry, but when creating an email field, following the cake's convention, the client side validation is built in and that's what I'm trying to get rid of.

1

There are 1 answers

2
Alex Stallen On BEST ANSWER

It is not cake that does that, its HTML5

If you want to disable client side validation for a form in HTML5 add a novalidate attribute to the form element. Fx:

   <?= $this->Form->create($message, ['class' => 'form-group', 'novalidate' => true]) ?>

wich will result in something like:

<form method="post" action="/foo" novalidate>...</form>

See https://www.w3.org/TR/html5/sec-forms.html#element-attrdef-form-novalidate