我今天使用codeigniter 3,我希望从我的视图文件中获取发布数据,这里是我的视图文件
<form action="<?php echo base_url('action/getpost'); ?>" method="post">
<div class="row marketing">
<div class="col-lg-6">
<div class="form-group">
<input disabled required type="text" class="form-control" name="firstname_field" id="firstname_field" placeholder="First name">
</div>
<div class="form-group">
<input disabled required type="text" class="form-control" name="lastname_field" id="lastname_field" placeholder="last Name">
</div>
<div class="form-group">
<input disabled required type="text" class="form-control" name="cardholderid_field" id="cardholderid_field" placeholder="Cardholder ID">
</div>
<div class="form-group">
<input disabled required type="text" class="form-control" name="cardnumber_field" id="cardnumber_field" placeholder="Card Number">
</div>
</div>
</div
</form>
并且继承我的控制器..
function getpost()
{
if($this->input->post('submit')){
$firstname = $this->input->post('firstname_field');
$lastname = $this->input->post('lastname_field');
$cardholder = $this->input->post('cardholderid_field');
$cardnumber = $this->input->post('cardnumber_field');
$data = array(
'firstname' => $firstname,
'lastname' => $lastname,
'cardholder' => $cardholder,
'cardnumber' => $cardnumber
);
print_r($data);
我总是得到这样的结果,
Array ( [firstname] => [lastname] => [cardholder] => [cardnumber] => )
任何人都可以帮忙吗?
感谢好友'
答案 0 :(得分:4)
使用readonly而不是disable ...
readonly和disable click here之间的差异。
如果您使用readonly u hve来指定值并给出按钮
在视图中
<form action="<?php echo base_url('action/getpost'); ?>" method="post">
<div class="row marketing">
<div class="col-lg-6">
<div class="form-group">
<input value="firstname" readonly required type="text" class="form-control" name="firstname" id="firstname_field" placeholder="First name">
</div>
<div class="form-group">
<input value="lastname" readonly required type="text" class="form-control" name="lastname" id="lastname_field" placeholder="last Name">
</div>
<div class="form-group">
<input value="" readonly required type="text" class="form-control" name="cardholderid" id="cardholderid_field" placeholder="Cardholder ID">
</div>
<div class="form-group">
<input value="cardnumber" readonly required type="text" class="form-control" name="cardnumber" id="cardnumber_field" placeholder="Card Number">
</div>
<div class="form-group">
<button type="submit">Submit</button>
</div>
</div
</form>
控制器中的
function getpost()
{
print_r($this->input->post());
}