Codeigniter - input form placeholder

Hi everyone, how can I use the placeholder tag in the CodeIgniter helper function form_input() ?

Thanks:)

+4
source share
4 answers

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

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

Or you can pass the form_input() array.

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

CodeIgniter Form Helper

+16
source

The Rocket-related Codeigniter User Guide 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 the Rocket response, passing 'placeholder'=>'my_placeholder' to this array should result in a 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 that the attr placeholder is very new and not supported in all browsers. Check out this article in the html center for html5, jQuery, and pure javascript methods for creating placeholders.

+2
source

Codeigniter form filler 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 )); 
0
source

you can set the placeholder this way

 echo form_input('username','','placeholder=username'); 

it will look like

 <input type='text' name='username' placeholder='username'/> 
0
source

Source: https://habr.com/ru/post/1333831/


All Articles