php - 使用 PHP、CSS、CodeIgniter 和 Bootstrap 的联系表单

标签 php html css codeigniter twitter-bootstrap

我正在使用 CodeIgniter,使用 Bootstrap 设计样式来构建一个网站,该网站有一个联系页面。

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

Controller :

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -  
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */

    protected   $sendEmailTo    =   'you@you.com'
    protected   $subjectLine    =   ""; // actually set on line 39.

    // views
    protected   $formView       =   'contact';
    protected   $successView    =   'contact_success';
    protected   $headerView     =   ''; //null to disable
    protected   $footerView     =   ''; //null to disable

    // other
    public      $data           =   array(); // used for the views


        public function contact()
    {

        $this->load->library('form_validation');
        $this->load->helper('url');
        $this->subjectLine = "Contact form response from " . $_SERVER['HTTP_HOST'];
        $this->form_validation->set_rules('name', 'Your name', 'trim|required');
        $this->form_validation->set_rules('email', 'Your Email', 'trim|required|valid_email');
        $this->form_validation->set_rules('message', 'Message', 'trim|required|xss_clean');

        if($this->form_validation->run() == FALSE) {
            // show the form

            if ($this->headerView) { $this->load->view($this->headerView,$this->data); }
            $this->load->view($this->formView,$this->data);
            if ($this->footerView) { $this->load->view($this->footerView,$this->data); }

        } else {
            // success! email it, assume it sent, then show contact success view.

            $this->load->library('email');
            $this->email->from($this->input->post('email'), $this->input->post('name'));
            $this->email->to($this->sendEmailTo);
            $this->email->subject($this->subjectLine);
            $this->email->message($this->input->post('message'));
            $this->email->send();

            if ($this->headerView) { $this->load->view($this->headerView,$this->data); }
            $this->load->view($this->successView,$this->data);
            if ($this->footerView) { $this->load->view($this->footerView,$this->data); }


    }

查看:

    <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="../../assets/ico/favicon.png">

    <title>Carousel Template for Bootstrap</title>

    <link href="<?php echo base_url().'css/bootstrap.css' ?>" rel="stylesheet" type="text/css">
    <link href="<?php echo base_url().'css/bootstrap-responsive.css' ?>" rel="stylesheet" type="text/css"> </head>


     <div class="input-group">
     <h1>Contact Form</h1>
     <?php echo validation_errors(); ?>
<?

    echo form_open(current_url()); 

?>

<p>
<?php

    echo "<tr>
        <td>" . form_label('Name: ', 'name') . "</td>
        <td>" . form_input('name', set_value('name')) . "</td>
        </tr>";

    echo "<tr>
        <td>" . form_label('Email: ', 'email'). "</td>
        <td>" . form_input('email', set_value('email')) . "</td>
        </tr>";

    echo "<tr>
        <td>".form_label('Message: ', 'message'). "</td>
        <td><textarea name='message'>" . set_value("message") . "</textarea></td>
        </tr>";

    echo "<tr>
        <td>".form_submit('submit', 'Submit Message') . "</td>
        </tr>";

?>
</table>

<?
    echo form_close();
?>
</div>

我想使用的 Bootstrap CSS 示例:

<div class="input-group">
  <span class="input-group-addon">@</span>
  <input type="text" class="form-control" placeholder="Username">
</div>

最佳答案

首先你应该在 php 标签之外构建你的标记并且只使用 php 来回显各个输入,你可以将你需要的属性作为数组参数传递给 form_input(),更多信息关于 here .

例子:

<div class="input-group">
  <span class="input-group-addon">@</span>
  <?php echo form_input(array("class"=>"form-control","placeholder"=>"Username"))?>
</div>

关于php - 使用 PHP、CSS、CodeIgniter 和 Bootstrap 的联系表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18367331/

相关文章:

javascript - 汉堡包按钮未使用 Material Design Lite 正确对齐

javascript - 仅展开单击的列

html - 如何将带有工具提示的字形图标放入表单中

php - 在 PHP 中使用 if 语句和 $GET 的正确方法

php - Javascript代码多次指向相同的数字

php - 将输入过滤器添加到 ZF2 中的字段集

php - 如何使用 file_get_contents php 获取图像扩展名?

css - Chrome 开发工具将链接标签替换为样式标签

css - 我怎样才能添加两个过渡变换,但一个接一个?

css - 如何在图像中使用没有边框的 CSS Sprite