validate Bootstrap form in Cakephp

631 views Asked by At

When i use Form Helper of Cakephp, it can be validated in Model with many rules like this: (for example)

$this->validate = array(
      "name" => array(
           "rule" => "notBlank",
           "message" => "Name not empty !",
       ),
       "email" => array(
           "rule" => "notBlank", 
           "message" => "Email not empty !", 
        ),

    );

Bootstrap Form:

<form>
<div class="form-group">
      <label for="name">Name:</label>
      <input type="text" name="name" class="form-control" id="name" placeholder="Enter name">
    </div>
    <div class="form-group">
      <label for="email">Email:</label>
      <input type="email" name="email" class="form-control" id="email" placeholder="Enter email">
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
  </form>

. But when i use Form created in Bootstrap, the validation is not occured.

How to fix that????

1

There are 1 answers

0
tarikul05 On BEST ANSWER

if you use Form helper then your input field name should be name="data[Modelname][fieldname]" Base on it your code should be (if your model is Users)

<form>
   <div class="form-group">
      <label for="name">Name:</label>
      <input type="text" name="data[User][name]" class="form-control" id="name" placeholder="Enter name">
    </div>
    <div class="form-group">
      <label for="email">Email:</label>
      <input type="email" name="data[User][email]" class="form-control" id="email" placeholder="Enter email">
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
  </form>

Details is Here