Last active
December 29, 2015 11:29
-
-
Save KyleGawryluk/7663759 to your computer and use it in GitHub Desktop.
Add error messages to Jeffery Way's FormField class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create the form field | |
* | |
* @param string $name | |
* @param array $args | |
*/ | |
protected function createField($name, $args) | |
{ | |
// If the user specifies an input type, we'll just use that. | |
// Otherwise, we'll take a best guess approach. | |
$type = array_get($args, 'type') ?: $this->guessInputType($name); | |
// We'll default to Bootstrap-friendly input class names | |
$args = array_merge(['class' => Config::get('form::inputClass')], $args); | |
$field = $this->createLabel($args, $name); | |
unset($args['label']); | |
$field .= $this->createInput($type, $args, $name); | |
if(Session::has('errors')){ | |
$messages = Session::get('errors'); | |
if($messages->first($name)){ | |
$field .= '<span class="help-block">'.$messages->first($name).'</span>'; | |
} | |
} | |
return $field; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment