예제 #1
0
 /**
  * Create a form label element.
  *
  * @param  string  $name
  * @param  string  $value
  * @param  array   $options
  * @return string
  */
 public function label($name, $value = null, $options = array())
 {
     if ($this->validationErrors && $this->validationErrors->has($name)) {
         $options = $this->addClass($options, $this->errorCssClass);
     }
     return parent::label($name, $value, $options);
 }
예제 #2
0
 public function testHasIndicatesExistence()
 {
     $container = new MessageBag();
     $container->setFormat(':message');
     $container->add('foo', 'bar');
     $this->assertTrue($container->has('foo'));
     $this->assertFalse($container->has('bar'));
 }
예제 #3
0
 /**
  * @param string $key
  * @return string
  */
 public static function getErrorClass($key)
 {
     if (isset(self::$_messages)) {
         $hasErrors = self::$_messages->has($key);
         $hasErrors = $hasErrors ?: self::$_messages->has(self::_dotNotation($key));
         if ($hasErrors) {
             return isset(self::$_errorClass) ? self::$_errorClass : config('coaster::frontend.form_error_class');
         }
     }
     return '';
 }
예제 #4
0
파일: Validator.php 프로젝트: imydou/dkuu
 /**
  * Stop on error if "bail" rule is assigned and attribute has a message.
  *
  * @param  string  $attribute
  * @return bool
  */
 protected function shouldStopValidating($attribute)
 {
     if (!$this->hasRule($attribute, ['Bail'])) {
         return false;
     }
     return $this->messages->has($attribute);
 }
예제 #5
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $user = User::findOrFail($id);
     $input = Input::only('email', 'first_name', 'last_name', 'role_id', 'confirmed', 'county_id', 'phone', 'school', 'password');
     $extra = Input::only('address', 'about');
     try {
         $in = Input::all();
         $in['id'] = $user->id;
         $this->editUserForm->validate($in);
     } catch (FormValidationException $e) {
         $this->errors = $e->getErrors();
     }
     foreach ($input as $key => $value) {
         if (!$this->errors->has($key)) {
             if ($key === 'password' && !empty($value)) {
                 $user->password = $value;
                 continue;
             }
             $user->{$key} = $value;
         }
     }
     foreach ($extra as $key => $value) {
         if (!$this->errors->has($key)) {
             $user->setMeta($key, e($value));
         }
     }
     $user->save();
     if ($this->errors->any()) {
         return back()->withErrors($this->errors);
     }
     flash('Modificările au fost salvate cu succes.');
     return back();
 }
예제 #6
0
 /**
  * Check if we should stop further validations on a given attribute.
  *
  * @param  string  $attribute
  * @return bool
  */
 protected function shouldStopValidating($attribute)
 {
     if ($this->hasRule($attribute, ['Bail'])) {
         return $this->messages->has($attribute);
     }
     if (isset($this->failedRules[$attribute]) && in_array('uploaded', array_keys($this->failedRules[$attribute]))) {
         return true;
     }
     // In case the attribute has any rule that indicates that the field is required
     // and that rule already failed then we should stop validation at this point
     // as now there is no point in calling other rules with this field empty.
     return $this->hasRule($attribute, $this->implicitRules) && isset($this->failedRules[$attribute]) && array_intersect(array_keys($this->failedRules[$attribute]), $this->implicitRules);
 }
예제 #7
0
 /**
  * @return \Response
  */
 public function update()
 {
     $input = Input::only('email', 'first_name', 'last_name', 'phone', 'school');
     $extra = Input::only('address', 'about');
     try {
         $this->accountForm->validate(Input::all());
     } catch (FormValidationException $e) {
         $this->errors = $e->getErrors();
     }
     foreach ($input as $key => $value) {
         if (!$this->errors->has($key)) {
             $this->user()->{$key} = e(trim($value));
         }
     }
     foreach ($extra as $key => $value) {
         if (!$this->errors->has($key)) {
             $this->user()->setMeta($key, e(trim($value)));
         }
     }
     $this->user()->save();
     return json($this->errors->isEmpty() ? trans('app.saved') : ['errors' => $this->errors]);
 }
예제 #8
0
 /**
  * Determine if it's a necessary presence validation.
  *
  * This is to avoid possible database type comparison errors.
  *
  * @param  string  $rule
  * @param  string  $attribute
  * @return bool
  */
 protected function hasNotFailedPreviousRuleIfPresenceRule($rule, $attribute)
 {
     return in_array($rule, ['Unique', 'Exists']) ? !$this->messages->has($attribute) : true;
 }
예제 #9
0
 /**
  * Create a form group element.
  *
  * @param string                         $name
  * @param \Illuminate\Support\MessageBag $errors
  * @param string                         $class
  *
  * @return string
  */
 protected function group($name, $errors = null, $class = 'form-group')
 {
     $return = '<div class="' . $class;
     if ($errors && $errors->has($name)) {
         $return .= ' has-error';
     }
     $return .= '">' . "\n";
     return $return;
 }
예제 #10
0
 /**
  * Return whether a field has errors or not.
  *
  * @return bool
  */
 public function hasError($fieldName)
 {
     return $this->errors->has($fieldName);
 }
예제 #11
0
 /**
  * Check if session in parent class has error
  *
  * @param  string $name
  *
  * @return bool
  */
 private function hasError($name = null)
 {
     return $this->local_errors->has($name);
 }
예제 #12
0
파일: FormTrait.php 프로젝트: jarick/bx
 /**
  * Return is has errror
  *
  * @return boolean
  */
 public function hasErrors()
 {
     return $this->error->has();
 }
예제 #13
0
 /**
  * Create a form group element.
  *
  * @param string                         $name
  * @param \Illuminate\Support\MessageBag $errors
  * @param string                         $class
  * @param array                          $options
  *
  * @return string
  */
 protected function group($name, $errors = null, $class = 'form-group', array $options = array())
 {
     $options = array_merge(array('class' => $class), $options);
     $options['class'] .= $errors && $errors->has($name) ? ' has-error' : '';
     $return = '<div' . $this->html->attributes($options) . '>' . "\n";
     return $return;
 }
예제 #14
0
 /**
  * Create a select box field.
  *
  * @param  string  $name
  * @param  array   $list
  * @param  string  $selected
  * @param  array   $options
  * @return string
  */
 public function select($name, $list = array(), $selected = null, $options = array())
 {
     $selected = $this->getValueAttribute($name, $selected);
     $options['id'] = $this->getIdAttribute($name, $options);
     if (!isset($options['name'])) {
         $options['name'] = $name;
     }
     // The form-control class should be a default class for every input
     // generated. The class option on the input also overrides every
     // default classes set.
     if (isset($options['class'])) {
         $this->setClass($options['class']);
     }
     $options['class'] = "form-control " . $this->class;
     // Removes keys for the wrapper from the $options array and puts them
     // into variables to prevent them from appearing as attributes on the
     // input itself.
     array_key_exists('label', $options) ? $label = array_pull($options, 'label') : ($label = null);
     $html = array();
     foreach ($list as $value => $display) {
         $html[] = $this->getSelectOption($display, $value, $selected);
     }
     // Once we have all of this HTML, we can join this into a single element after
     // formatting the attributes into an HTML "attributes" string, then we will
     // build out a final select statement, which will contain all the values.
     $options = $this->html->attributes($options);
     $list = implode('', $html);
     // Sets the $input variable to the newly generated input field, this
     // variable will then be used within the Bootstrap wrapper instead of
     // being returned directly.
     $input = "<select{$options}>{$list}</select>";
     // If there are errors we want to add the has-error class to the form-group
     // tag to make the border glow red.
     if (!is_null($this->errors) && $this->errors->has($name) && $name != NULL) {
         $this->formGroupClass .= " has-error";
         // If exteded feedback is also enabled we will also add the has-feedback
         // class to allow showing the icons.
         if ($this->feedback === true) {
             $this->formGroupClass .= " has-feedback";
         }
     }
     // The return variable holds the HTML output that is returned to the user.
     // It's purposely divided into lines to allow for better reading and
     // easier conditionals for some of the output.
     $return = '<div class="form-group ' . $this->formGroupClass . '">';
     $return .= '<div class="row">';
     $return .= '<div class="col-md-4">';
     // If a label is given then we show the label here. Notice
     // that the form class is available as IlluminateFormBuilder
     // and not as Form.
     if (!is_null($label)) {
         $return .= IlluminateFormBuilder::label($name, $label);
     }
     $return .= '</div>';
     $return .= '<div class="col-md-8 text-right">';
     // If errors are present we show the error message here.
     // Error styling can be done using the validation-error
     // class that is added automatically.
     if (!is_null($this->errors) && $this->errors->has($name) && $name != NULL) {
         $return .= $this->errors->first($name, '<p class="text-danger validation-error">:message</p>');
     }
     $return .= '</div>';
     $return .= '</div>';
     $return .= $input;
     $return .= '</div>';
     $this->resetConfig();
     return $return;
 }