문제

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>
도움이 되었습니까?

해결책

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.

다른 팁

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", ));

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top