Search code examples
formskohanakohana-3form-helpers

kohana form helper include javascript


i do my forms in my views using kohana helper, but i need to include some javascript in some fields (like onclick, onblur, etc). How can i do this without giving up to kohana form helper?

for example, in pure html i have:

               <input class="field" type="text" id="email" name="email" value="<?php if (Cookie::get('email')) echo Cookie::get('email'); else echo 'Adresă Email'; ?>" onclick="if (this.value=='Adresă Email') this.value='';" onblur="if (this.value=='') this.value='Adresă Email';" />

and using the form helper:

            <?php echo Form::input('email', $email_value , array('id'=>'email', 'class'=>'field',$validator['email'])) ?>

which is okey, but i also want to add the onclick and onblur. any idea about how can this be done? thanks !


Solution

  • Simply add onclick, onblur to the attributes array:

    echo Form::input('email', $email_value, array('onlick' => 'something;', 'onblur' => 'something else;'))
    

    or consider using jQuery and stop worrying about inline attributes ;)