public function postIndex() { $form = Form::fromFile(__DIR__ . '/contact.form.php'); $form->setInput(Input::all()); $validator = $form->accept(); if ($validator->fails()) { $form->setErrors($validator->messages()); return View::make('contact')->with('form', $form); } $data = $validator->getData(); // Get the label for an enum $data['found'] = $form->fieldSpec('found')['options'][$data['found']]; // Parse date inputs $data['from_date'] = strtotime($data['from_date']); $data['to_date'] = strtotime($data['to_date']); if (!Mail::send('emails.contact', $data, function ($message) use($data) { $message->to('*****@*****.**')->replyTo($data['email'], $data['person'])->subject('Contact form')->setCharset('UTF-8'); })) { $errors = new MessageBag(); // global here can be anything that's not an actual field name $errors->add('global', 'Could not send your contact request to contact@example.com. Please try again later.'); return View::make('contact')->with('form', $form)->with('errors', $errors); } return View::make('success'); }
/** * Prints out the current label * * @param string $field The field to create a label for * @return string A <label> tag */ private function getLabel($field) { if (!$this->label or !array_get($this->label, 'label')) { return false; } extract($this->label); // Add bootstrap class if necessary $attributes = Framework::getLabelClasses($attributes); // Get the field name to link the label to it $name = $field->name; if ($field->type == 'checkboxes' or $field->type == 'radios') { return '<label' . HTML::attributes($attributes) . '>' . $label . '</label>'; } return \Form::label($name, $label, $attributes); }
public function testRequiredAttribute() { $ts = array(); foreach (self::$form->fieldSpecs() as $f => $spec) { $t = $spec['type']; if (!array_key_exists($t, $ts)) { $ts[] = $t; $f = new Form(array($t => array('validate' => array('required')))); $o = $f->field($t); $this->assertRegExp('/<[^>]+ required\\b/', $o, "Required attribute not kept for type {$t}"); } } }
public static function renderLabel($label, $field) { // Get the label and its informations extract($label); // Add classes to the attributes $attributes = Framework::getLabelClasses($attributes); // Append required text if ($field->isRequired()) { $label .= Config::get('required_text'); } // Get the field name to link the label to it if ($field->isCheckable()) { return '<label' . HTML::attributes($attributes) . '>' . $label . '</label>'; } return \Form::label($field->name, $label, $attributes); }
/** * Prints out the current label * * @param string $name A field to link the label to * @return string A <label> tag */ private function getLabel($name) { if (!$this->label) { return false; } extract($this->label); $attributes = Helpers::addClass($attributes, 'control-label'); return \Form::label($name, $label, $attributes); }