original_string: public function validate($field, array $attributes = array())
      {
          foreach ($this->validator->rules($field) as $validate => $param) {
              $attributes["data-rule-{$validate}"] = htmlspecialchars($param);
          }
          foreach ($this->validator->messages($field) as $rule => $message) {
              $attributes["data-msg-{$rule}"] = htmlspecialchars($message);
          }
  
          return $attributes;
      }
code: public function validate($field, array $attributes = array())
      {
          foreach ($this->validator->rules($field) as $validate => $param) {
              $attributes["data-rule-{$validate}"] = htmlspecialchars($param);
          }
          foreach ($this->validator->messages($field) as $rule => $message) {
              $attributes["data-msg-{$rule}"] = htmlspecialchars($message);
          }
  
          return $attributes;
      }
code_tokens: public function validate ( $ field , array $ attributes = array ( ) ) { foreach ( $ this -> validator -> rules ( $ field ) as $ validate => $ param ) { $ attributes [ "data-rule-{$validate}" ] = htmlspecialchars ( $ param ) ; } foreach ( $ this -> validator -> messages ( $ field ) as $ rule => $ message ) { $ attributes [ "data-msg-{$rule}" ] = htmlspecialchars ( $ message ) ; } return $ attributes ; }
docstring: This adds the jQuery Validation rules and messages set earlier to the input field's submitted attributes.  This is used internally when creating form fields using this class.
  
  @param string $field      The input's name.
  @param array  $attributes The currently constituted attributes.
  
  @return array The submitted attributes with the data rules and messages applied.
  
  @see http://johnnycode.com/2014/03/27/using-jquery-validate-plugin-html5-data-attribute-rules/
  
  ```php
  $form->validator->set('field', array('required' => 'Do this or else.'));
  $attributes = $form->validate('field', array('name' => 'field'));
  ```
docstring_tokens: This adds the jQuery Validation rules and messages set earlier to the input field s submitted attributes . This is used internally when creating form fields using this class .