SOLVED - 使用Codeigniter和Bootstrap的输入表单3 [英] SOLVED - Input Form Using Codeigniter and Bootstrap 3

查看:124
本文介绍了SOLVED - 使用Codeigniter和Bootstrap的输入表单3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Codeigniter,用Bootstrap 3构建一个网站。

I'm using Codeigniter, styled with Bootstrap 3 to build a website.

我无法对PHP / Form Helper建立的文本字段进行样式化,因为我不知道在哪里使用标签,我试过的每个解决方案都导致一个额外的文本字段,或者只是插件出现,或根本没有。

I can't stylize the text-fields built by the PHP/Form Helper, as I'm not sure where to use the tags, every solution I've tried has resulted in either an extra text field, or just the addon appearing, or nothing at all.

控制器

public function __construct ()
{
    parent::__construct();
}

public function index ()
{
    // Fetch all users
    $this->data['users'] = $this->user_m->get();

    // Load view
    $this->data['subview'] = 'admin/user/index';
    $this->load->view('admin/_layout_main', $this->data);
}

public function edit ($id = NULL)
{
    // Fetch a user or set a new one
    if ($id) {
        $this->data['user'] = $this->user_m->get($id);
        count($this->data['user']) || $this->data['errors'][] = 'User could not be found';
    }
    else {
        $this->data['user'] = $this->user_m->get_new();
    }

    // Set up the form
    $rules = $this->user_m->rules_admin;
    $id || $rules['password']['rules'] .= '|required';
    $this->form_validation->set_rules($rules);

    // Process the form
    if ($this->form_validation->run() == TRUE) {
        $data = $this->user_m->array_from_post(array('name', 'email', 'password'));
        $data['password'] = $this->user_m->hash($data['password']);
        $this->user_m->save($data, $id);
        redirect('admin/user');
    }

    // Load the view
    $this->data['subview'] = 'admin/user/edit';
    $this->load->view('admin/_layout_main', $this->data);
}

public function delete ($id)
{
    $this->user_m->delete($id);
    redirect('admin/user');
}

public function login ()
{
    // Redirect a user if he's already logged in
    $dashboard = 'admin/dashboard';
    $this->user_m->loggedin() == FALSE || redirect($dashboard);

    // Set form
    $rules = $this->user_m->rules;
    $this->form_validation->set_rules($rules);

    // Process form
    if ($this->form_validation->run() == TRUE) {
        // We can login and redirect
        if ($this->user_m->login() == TRUE) {
            redirect($dashboard);
        }
        else {
            $this->session->set_flashdata('error', 'That email/password combination does not exist');
            redirect('admin/user/login', 'refresh');
        }
    }

    // Load view
    $this->data['subview'] = 'admin/user/login';
    $this->load->view('admin/_layout_modal', $this->data);
}

public function logout ()
{
    $this->user_m->logout();
    redirect('admin/user/login');
}

public function _unique_email ($str)
{
    // Do NOT validate if email already exists
    // UNLESS it's the email for the current user

    $id = $this->uri->segment(4);
    $this->db->where('email', $this->input->post('email'));
    !$id || $this->db->where('id !=', $id);
    $user = $this->user_m->get();

    if (count($user)) {
        $this->form_validation->set_message('_unique_email', '%s should be unique');
        return FALSE;
    }

    return TRUE;
}

}

查看

    <div class="modal-body">
<?php echo validation_errors(); ?>
<?php echo form_open();?>

<div class="container">
    <div class="modal-header">
    <h3>Log in</h3>
    <p>Please log in using your credentials</p>
</div>
<table class="table">
    <tr>
        <td>Email</td>
        <td><?php echo form_input('email'); ?></td>
    </tr>
    <tr>
        <td>Password</td>
        <td><?php echo form_password('password'); ?></td>
    </tr>
    <tr>
        <td></td>
        <td><?php echo form_submit('submit', 'Log in', 'class="btn btn-primary"'); ?></td>
    </tr>
</table>
        <div class="modal-footer">
            &copy; <?php echo date('Y'); ?> <?php echo $meta_title; ?>
        </div>
<?php echo form_close();?>

    </div>
</div>
</div>

Bootstrap

Bootstrap

      <form class="form-signin" role="form">
    <h2 class="form-signin-heading">Please sign in</h2>
    <input type="text" class="form-control" placeholder="email" required autofocus value="<?php echo set_value('email') ?>">
    <input type="password" class="form-control" placeholder="password" required value"<?php echo set_value('password') ?>">
    <label class="checkbox">
      <input type="checkbox" value="remember-me"> Remember me
    </label>
    <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
  </form>


推荐答案

只需将所有数据作为数组传递给form_input



You just pass everything as an array to form_input

<?php echo form_input(['name' => 'email', 'id' => 'email', 'class' => 'form-control', 'value' => set_value('email')]); ?>

这是您提交的整个表格,

Here's your entire form as presented,

<?php echo form_open('controller/method', ['class' => 'form-signin', 'role' => 'form']); ?>

<h2 class="form-signin-heading">Please sign in</h2>

<?php echo form_input(['name' => 'email', 'id' => 'email', 'class' => 'form-control', 'value' => set_value('email'), 'placeholder' => 'Email']); ?>

<?php echo form_password(['name' => 'password', 'id' => 'password', 'class' => 'form-control', 'placeholder' => 'Password']); ?>

<label class="checkbox">
    <?php echo form_checkbox(['name' => 'remember_me', 'value' => 1]); ?>
</label>

<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>

<?php echo form_close(); ?>

这篇关于SOLVED - 使用Codeigniter和Bootstrap的输入表单3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆