errorBag = Session::get('errors', new MessageBag);
}
public function text($name, $options = [])
{
$hasError = $this->errorBag->has($name) ? 'has-error' : '';
$htmlForm = '
';
return $htmlForm;
}
public function textarea($name, $options = [])
{
$hasError = $this->errorBag->has($name) ? 'has-error' : '';
$htmlForm = '';
$rows = isset($options['rows']) ? $options['rows'] : 3;
$value = isset($options['value']) ? $options['value'] : null;
$fieldParams = ['class'=>'form-control','rows' => $rows];
if (isset($options['readonly']) && $options['readonly'] == true) { $fieldParams += ['readonly']; }
if (isset($options['disabled']) && $options['disabled'] == true) { $fieldParams += ['disabled']; }
if (isset($options['required']) && $options['required'] == true) { $fieldParams += ['required']; }
if (isset($options['placeholder'])) { $fieldParams += ['placeholder' => $options['placeholder']]; }
$htmlForm .= $this->setFormFieldLabel($name, $options);
$htmlForm .= Form::textarea($name, $value, $fieldParams);
$htmlForm .= $this->errorBag->first($name, ':message');
$htmlForm .= '
';
return $htmlForm;
}
public function select($name, $selectOptions, $options = [])
{
$hasError = $this->errorBag->has($name) ? 'has-error' : '';
$htmlForm = '';
$value = isset($options['value']) ? $options['value'] : null;
$fieldParams = ['class'=>'form-control'];
if (isset($options['class'])) { $fieldParams['class'] .= ' ' . $options['class']; }
if (isset($options['readonly']) && $options['readonly'] == true) { $fieldParams += ['readonly']; }
if (isset($options['disabled']) && $options['disabled'] == true) { $fieldParams += ['disabled']; }
if (isset($options['required']) && $options['required'] == true) { $fieldParams += ['required']; }
if (isset($options['multiple']) && $options['multiple'] == true) { $fieldParams += ['multiple', 'name' => $name . '[]']; }
if (isset($options['placeholder']))
$fieldParams += ['placeholder' => $options['placeholder']];
else
$fieldParams += ['placeholder' => '-- Pilih ' . str_split_ucwords(str_replace('_id', '', $name)) . ' --'];
$htmlForm .= $this->setFormFieldLabel($name, $options);
$htmlForm .= Form::select($name, $selectOptions, $value, $fieldParams);
$htmlForm .= $this->errorBag->first($name, ':message');
$htmlForm .= '
';
return $htmlForm;
}
public function multiSelect($name, $selectOptions, $options = [])
{
$options['multiple'] = true;
return $this->select($name, $selectOptions, $options);
}
public function email($name, $options = [])
{
$options['type'] = 'email';
return $this->text($name, $options);
}
public function password($name, $options = [])
{
$options['type'] = 'password';
return $this->text($name, $options);
}
public function radios($name, array $radioOptions, $options = [])
{
$hasError = $this->errorBag->has($name) ? 'has-error' : '';
$htmlForm = '';
return $htmlForm;
}
public function checkboxes($name, array $checkboxOptions, $options = [])
{
$hasError = $this->errorBag->has($name) ? 'has-error' : '';
$htmlForm = '';
return $htmlForm;
}
public function textDisplay($name, $value, $options = [])
{
$label = isset($options['label']) ? $options['label'] : str_split_ucwords($name);
$htmlForm = '';
return $htmlForm;
}
public function file($name, $options = [])
{
$hasError = $this->errorBag->has($name) ? 'has-error' : '';
$label = isset($options['label']) ? $options['label'] : str_split_ucwords($name);
$htmlForm = '';
return $htmlForm;
}
public function delete($form_params = [], $button_label = 'x', $button_options = [], $hiddenFields = [])
{
$form_params['method'] = 'delete';
$form_params['class'] = isset($form_params['class']) ? $form_params['class'] : 'del-form';
$form_params['style'] = isset($form_params['style']) ? $form_params['style'] : 'display:inline';
if (! isset($button_options['class']))
$button_options['class'] = 'pull-right';
if (! isset($button_options['title']))
$button_options['title'] = 'Remove this';
$htmlForm = Form::open($form_params);
if (!empty($hiddenFields))
{
foreach ($hiddenFields as $k => $v)
{
$htmlForm .= Form::hidden($k, $v);
}
}
$htmlForm .= Form::submit($button_label, $button_options);
$htmlForm .= Form::close();
return $htmlForm;
}
public function arrays($name, array $fieldKeys, $options = [])
{
$hasError = $this->errorBag->has($name) ? 'has-error' : '';
$label = isset($options['label']) ? $options['label'] : str_split_ucwords($name);
$htmlForm = '';
return $htmlForm;
}
public function price($name, $options = [])
{
$options['addon'] = ['before' => isset($options['currency']) ? $options['currency'] : 'Rp'];
$options['class'] = 'text-right';
return $this->text($name, $options);
}
private function setFormFieldLabel($name, $options)
{
if (isset($options['label']) && $options['label'] != false) {
$label = isset($options['label']) ? $options['label'] : str_split_ucwords($name);
return Form::label($name, $label, ['class'=>'control-label']) . ' ';
} elseif (! isset($options['label'])) {
return Form::label($name, str_split_ucwords($name), ['class'=>'control-label']) . ' ';
}
}
}