예제 #1
0
 /**
  * Given a list of fields, validate some data.
  *
  * @param array $fields    List of args that would be sent to FormBuilder::input()
  * @param array $data      (optional) The data to validate. Defaults to $_POST
  * @param array $to_update (optional) Existing data to populate. Necessary for nested values
  *
  * @return array
  */
 public static function validate_post_data($fields, $data = null, $to_update = array())
 {
     if (null === $data) {
         $data = stripslashes_deep($_POST);
     }
     foreach ($fields as $field) {
         $value = FormBuilder::get_value($field['name'], $data);
         $fieldObj = FormField::create($field);
         $value = $fieldObj->validate($value);
         if (null !== $value) {
             self::set_value($to_update, $field['name'], $value);
         }
     }
     return $to_update;
 }
예제 #2
0
 /**
  * Get default values for one or all fields.
  *
  * @param string|array $field (optional) The field to get.
  *
  * @return mixed Whatever is in those fields.
  */
 public function get_defaults($field = null)
 {
     return FormBuilder::get_value($field, $this->defaults);
 }