Domanda

i'm trying to set autofocus on my input form, i'm confused to apply existing example to my program.. please anybody help me. thanks.

    <body>
 <div id="wrapper">
     <div id="text"> 
    <h2>Login</h2>
    <?php 

    echo form_open('login/validateform');
        echo 'user name';
    echo form_input('username', '');
    echo 'password';
        echo form_password('password', '');

        echo form_submit('submit', 'Login');


 </div>
 </body>
È stato utile?

Soluzione

I found the solution on the manual: echo form_input($auto_focus); where $auto_focus is (create it):

$auto_focus = array(
              'autofocus'   => 'autofocus',
            );

echo form_input($auto_focus);

http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html search for (ctrl + f) *form_input()* on this page

Your code will be:

<body>
  <div id="wrapper">
     <div id="text"> 
       <h2>Login</h2>
        <?php 
            $auto_focus = array(
              'name'        => 'username',
              'autofocus'   => 'autofocus',
            );

        echo form_open('login/validateform');
            echo 'user name';
        echo form_input($auto_focus);
        echo 'password';
            echo form_password('password', '');

            echo form_submit('submit', 'Login');

           //dont forget to close php
         ?>
        </div>
    </div>
</body>

Before using php, and library, be sure to know how to write good html code... You made lot of mistakes.

Altri suggerimenti

Not only for PHP but also for others web applications, we can set autofocus on input field by following HTML 5 and Javascript code

<input type='text' name='username' id='inputFieldId' autofocus="autofocus" />

<script>
    if (!("autofocus" in document.createElement("input")))
            document.getElementById("inputFieldId").focus();
</script>

Use html5 autofocus it is supported now in all majore browsers.

 <input type='text' name='username' autofocus="true" />

echo form_input(array( "name" => "username", "id" => "email", "class" => "form-control", "maxlength" => "255", "size" => "50", "autofocus" => "autofocus", ));

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top