codeigniter - input form placeholder codeigniter - input form placeholder codeigniter codeigniter

codeigniter - input form placeholder


Do you mean the placeholder attribute (not tag)? form_input() takes a third parameter with additional attributes.

$opts = 'placeholder="Username"';form_input('username', '', $opts);

Or you can pass form_input() an array.

form_input(array(  'name' => 'username',  'value' => '',  'placeholder' => 'Username',));

CodeIgniter Form Helper


The Codeigniter user guide linked to by Rocket indicates that attributes other than name and value are passed to form_input() as an array:

 $data = array(              'name'        => 'username',              'id'          => 'username',              'value'       => 'johndoe',              'maxlength'   => '100',  );echo form_input($data);// Would produce:<input type="text" name="username" id="username" value="johndoe" maxlength="100" size="50" />

To expand on Rocket's answer, passing 'placeholder'=>'my_placeholder' into that array should produce the placeholder attribute.

$data = array(              'name'        => 'username',              'id'          => 'username',              'value'       => 'johndoe',              'maxlength'   => '100',              'size'        => '50',              'style'       => 'width:50%',              'placeholder' => 'my_placeholder'            );echo form_input($data);

Keep in mind, the placeholder attr is very new and not supported in all browsers. Check out this article at html center for html5, jQuery, and pure javascript ways to accomplish placeholders


Codeigniter form placeholder for IE6, IE7 and IE8

echo form_input(array(                'name' => 'stackoverflow',                'value' => 'yourplaceholder',                'placeholder' => 'yourplaceholder',                'onclick' => 'if(this.value == \'yourplaceholder\') this.value = \'\'', //IE6 IE7 IE8                'onblur' => 'if(this.value == \'\') this.value = \'yourplaceholder\''       //IE6 IE7 IE8));