我如何将此表单转换为codeigniter

时间:2013-12-26 20:34:58

标签: php forms codeigniter

我有以下表格的登录页面

<form action = "http://<?php echo $_SERVER['HTTP_HOST']; ?>/user/login" method = "post">
    <fieldset>
        <label for="email" class="block clearfix">
            Email Address:
            <span class="block input-icon input-icon-right">
                <input type="text" class="form-control" placeholder="Email" name="email" id = "email"/> <i class="icon-user"></i>
            </span>
        </label>
        <label for ="password" class="block clearfix">
            Password:
            <span class="block input-icon input-icon-right">
                <input type="password" name="password" id = "password" class="form-control" placeholder="Password"/> <i class="icon-lock"></i>
            </span>
        </label>
        <div class="clearfix">
            <button type="submit" class="button width-35 pull-right btn btn-sm btn-primary">
                <i class="icon-key"></i>
                Login
            </button>
        </div>
    </fieldset>
</form>

我想将其转换为使用与CodeIgniter打包在一起的form_helper。我的问题是文档只显示了最基本的例子。我不确定如何在每个label(包括form_input)中添加如此多的额外数据。转换它的最简单方法是什么?

2 个答案:

答案 0 :(得分:1)

属性可以作为form_input()调用的数组提供。

如果我要重新创建email文本框:

<input type="text" class="form-control" placeholder="Email" name="email" id = "email"/>

我会将其创建为:

$data = array(

'name' => 'email' , 
'id'   => 'email' ,
'class' => 'form_control' ,
'placeholder' => 'Email'

);

echo form_input($data);

答案 1 :(得分:0)

<?php $attributes = array('id' => 'addsensorform'); ?>
<?php echo form_open_multipart('http://<?php echo $_SERVER['HTTP_HOST'];', $attributes); ?>
<fieldset>
    <label for="email" class="block clearfix">
        Email Address:
        <span class="block input-icon input-icon-right">
            <input type="text" class="form-control" placeholder="Email" name="email" id = "email"/> <i class="icon-user"></i>
        </span>
    </label>
    <label for ="password" class="block clearfix">
        Password:
        <span class="block input-icon input-icon-right">
            <input type="password" name="password" id = "password" class="form-control" placeholder="Password"/> <i class="icon-lock"></i>
        </span>
    </label>
    <div class="clearfix">
        <button type="submit" class="button width-35 pull-right btn btn-sm btn-primary">
            <i class="icon-key"></i>
            Login
        </button>
    </div>
</fieldset> 
<?php echo form_close(); ?>