如何在codeigniter中启用和禁用表单

时间:2017-03-05 07:54:14

标签: php codeigniter

请我正在开发一个涉及管理部门和客户部分的应用程序,我想控制客户部分的注册期限。例如,从一个日期,例如2017年5月5日到另一个日期05/04/2017,表格应该被禁用。

1 个答案:

答案 0 :(得分:3)

检查示例,这将自动显示您给定日期的表格

<?php
$today = date('d/m/y');
$date2 = "05/03/2017";
if(strtotime($today) == strtotime($date2))
{
    $display = "block";
}
else
{
    $display = "none";
}
?>
<style> 
form {
    display: <?php echo $display; ?>;
}
<style>
<form>
  <div class="form-group">
    <label for="email">Email address:</label>
    <input type="email" class="form-control" id="email">
  </div>
  <div class="form-group">
    <label for="pwd">Password:</label>
    <input type="password" class="form-control" id="pwd">
  </div>
  <button type="submit" class="btn btn-default">Submit</button>
</form>

Codeigniter查询

public function formEvent()
{
    $result = array();

    $today = date('d/m/y');    // get today date 

    /* get form submit values */

    #$startDate = $this->input->post('start_date')     // form input name should be start date 
    $endDate = $this->input->post('end_date');       //form input name should be end_date 

    /* check condition for enable or disable form */

    if(strtotime($today) == strtotime($endDate))
    {
        $display = "block";
    }
    else
    {
        $display = "none";
    }

    $result['display'] = $display ;

    $this->load->view('pagename', $result);   // view containing form 
}