Created
August 17, 2012 09:32
-
-
Save notomato/3377437 to your computer and use it in GitHub Desktop.
Customising form helper
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
<?php | |
// Default | |
<?=$this->form->text('email'); ?> | |
<input type="text" name="email" id="MemberEmail" value="[email protected]" /> | |
// Custom wrapper class | |
<?=$this->form->field('name', array( | |
'wrap' => array('class' => 'wrapper') | |
)); ?> | |
<div class="wrapper"> | |
<label for="MemberName">Name</label> | |
<input type="text" name="name" id="MemberName" /> | |
<div class="error">You don't have a name?</div> | |
</div> | |
// Custom field template | |
<?=$this->form->field('name', array( | |
'wrap' => array('class' => 'item'), | |
'template' => '<li{:wrap}>{:error}{:label}{:input}</li>' | |
)); ?> | |
<li class="item"> | |
<div class="error">You don't have a name?</div> | |
<label for="MemberName">Name</label> | |
<input type="text" name="name" id="MemberName" /> | |
</li> | |
// Or you can configure the helper | |
$this->form->config(array('templates' => array( | |
'field' => "<li{:wrap}>{:error}{:label}{:input}</li>" | |
))); | |
// Customising the field id | |
<? | |
$form = $this->form; | |
$this->form->config(array('attributes' => array( | |
'id' => function($method, $name, $options) use (&$form) { | |
if ($method != 'text' && $method != 'select') { | |
return; | |
} | |
$model = null; | |
if ($binding = $form->binding()) { | |
$model = basename(str_replace('\\', '/', $binding->model())) . '_'; | |
} | |
return Inflector::underscore($model . $name); | |
} | |
))); | |
<input type="text" name="email" id="member_email" value="[email protected]" /> | |
// Source: http://www.slideshare.net/nateabele/the-zen-of-lithium |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment