-1
我有問題,我輸入「類型」從來沒有在數據庫職位,因爲我不給視圖中的輸入類型(我想我喜歡的類型的附加價值是由控制器設置/隱藏)...這是我的代碼PHP,笨如何從控制器隱藏視圖
控制器:
<?php
public function addSmsCampaign() {
if (isset($_POST['addSmsCampaign'])) {
$this->form_validation->set_rules('campaign_name', 'campaign name', 'required|is_unique[campaigns.campaign_name]');
$this->form_validation->set_rules('sequence_qty', 'sequence quantity', 'required|integer');
$this->form_validation->set_rules('label_id', 'label id', 'required');
$this->form_validation->set_rules('type', '', 'required');
//if form validation true
if ($this->form_validation->run() == TRUE) {
$sms = 1;
$newcampaign = [
'campaign_name' => $_POST['campaign_name'],
'sequence_qty' => $_POST['sequence_qty'],
'label_id' => $_POST['label_id'],
'type' => $this->input->post('type'),
'created_at' => date('Y-m-d')
];
$this->db->insert('campaigns', $newcampaign);
redirect('userCont/sequenceform', 'refresh');
}
}
?>
,這是我的看法:
<form action="" method="POST">
<div class="form-group">
<label for="campaign_name">Input Campaign Title </label>
<input type="text" class="form-control" name="campaign_name" id="name">
</div>
<div class="form-group">
<label for="sequence_qty">Sequence qty </label>
<input type="text" class="form-control" name="sequence_qty" id="qty">
<input type="hidden" class="form-control" name="type" value="1">
</div>
<div class="form-group">
<label for="label_id">Choose Category</label>
<select class="form-control" name="label_id" id="label_id">
<?php
foreach ($label_content as $e) {
echo "<option value='$e->id;'>" . $e->label_name . "</option>";
}
?>
</select>
</div>
<div class="text-right">
<button class="btn btn-primary form-control" value="1" name="addSmsCampaign type">next</button>
</div><hr>
</form>
我每次發佈類型的值時是默認值= 0,我想將值設置爲1 ... 個非常感謝
一些其他的名字,你不是需要在每次控制器 – AZinkey
***在HTML類型字段,只需設定值I類型的後值是默認= 0,我想設置值爲1 ***? whare?解釋你的問題 –
我在我的控制器中編輯類型 'type'=> $ this-> input-> post('type'), to this 'type'=>'1', 但值還是0,這就是爲什麼我設置隱藏在視圖,但仍然無法正常工作 – huamgg