Welcome Guest, Not a member yet? Register   Sign In
Templating App Forms
#4

[eluser]CroNiX[/eluser]
Well, you can probably narrow it down a little by doing something like
Helper
Code:
//$labelText = Label to display
//$labelFieldName is the corresponging field name of the form element this is the label for
//$formElement is the raw html element for the individual field.
function form_group($labelText, $labelFieldName, $formElement)
{
  $html = '<div class="form-group">';
  $html .= form_label($labelText, $labelFieldName, array('class' => 'strong'));
  $html .= $formElement;
  $html .= '</div>';
  return $html;
}

Use like:
Code:
//create the form element
$data = array('class' => 'input-block-level form-control', 'name' => 'password', 'placeholder' => 'Your Password');
//pass the label text and field name along with the field.
echo form_group('Password', 'password', form_password($data));

which would replace this:
Code:
<div class="form-group">
&lt;?php
$attributes = array('class' => 'strong');
echo form_label('Password', 'password', $attributes);
$data = array('class' => 'input-block-level form-control', 'name' => 'password', 'placeholder' => 'Your Password');
echo form_password($data);
?&gt;
</div>
But you'd still have to create the individual form control and pass it to the helper, since that can change so much from field to field. I imagine you might want to add an css class to the form element if it fails validation and this would be easier to do that by keeping it outside of the helper.


Messages In This Thread
Templating App Forms - by El Forum - 12-10-2013, 12:36 PM
Templating App Forms - by El Forum - 12-10-2013, 01:09 PM
Templating App Forms - by El Forum - 12-10-2013, 01:16 PM
Templating App Forms - by El Forum - 12-10-2013, 01:29 PM



Theme © iAndrew 2016 - Forum software by © MyBB