<?php
$att = array('id' => 'survey_form', 'role' => 'ajax-form');
echo form_open('welcome/addsurvey', $att);
?>
<div class="span5 offset1" id="form_div">
<?php echo validation_errors('<div class="alert alert-danger reg_error">', '</div>'); ?>
<div class="form-group control-group warning">
<label for="SurveyTitle">Survey Title</label>
<input name="SurveyTitle" type="text" class="form-control" data-validation-required-message="Please enter a Survey Title" id="SurveyTitle" required placeholder="Please enter the Survey Title" value="<?php echo set_value('SurveyTitle'); ?>">
<p class="help-block"></p>
</div>
<div class="form-group control-group warning">
<label for="SurveyIntroduction">Survey introduction</label>
<textarea name="SurveyIntroduction" type="text" class="form-control" id="SurveyIntroduction" placeholder="Enter the Survey Introduction" value="<?php echo set_value('SurveyIntroduction'); ?>"></textarea>
</div>
<button type="submit" class="btn btn-large btn-success">Add Survey</button>
</div>
</form>
我通过上面的表单插入数据它工作得很好如何在插入后通过set_value显示表单上的字段,因为它现在不适合我。
以下是我的控制器功能:
public function addsurvey() {
if (isset($_POST['SurveyTitle']) && isset($_POST['SurveyIntroduction'])) {
$this->load->library('form_validation');
$this->load->helper(array('form', 'url'));
$this->load->database();
$this->form_validation->set_rules('SurveyTitle', 'Survey Title', 'required');
$this->form_validation->set_rules('SurveyIntroduction', 'Survey introduction', 'required');
$this->form_validation->set_message('required', 'Survey Title and Survey Introduction cannot be empty');
if ($this->form_validation->run() == FALSE) {
$this->load->view('SurveyPage');
} else {
$today = date("Y-m-d H:i:s");
$UserId = "m123456789";
$SurveyTitle = $this->input->post('SurveyTitle');
$SurveyIntroduction = $this->input->post('SurveyIntroduction');
$SurveyLink = base_url() + rand() + $SurveyTitle;
$isDisabled = 0;
$db_query = $this->db->query("INSERT into survey(SurveyTitle,SurveyIntro,SurveyLink,DateCreated,CreatedBy,isDisabled) VALUES('" . $SurveyTitle . "','" . $SurveyIntroduction . "','" . $SurveyLink . "','" . $today . "','" . $UserId . "','" . $isDisabled . "')");
if ($this->db->insert_id($db_query)) {
$id = $this->db->insert_id();
$lastid['last_id'] = $id;
} else {
}
$data = $this->displayallsurveys();
$surveydata = $this->getsurveydatabasedonId($id);
$drpquestiontype = $this->displayquestiontypedropdown();
$chkvalidations = $this->displayvalidationscheckboxes();
$chkvalidationsother = $this->displayvalidationscheckboxesother();
$parent_data = array('drpquestiontype' => $drpquestiontype, 'chkvalidations' => $chkvalidations, 'chkvalidationsother' => $chkvalidationsother, 'lastid' => $lastid);
$parent_datasurveypage =array('data' => $data, 'surveydata' => $surveydata);
$this->load->view('SurveyPage', $parent_datasurveypage);
$this->load->view('question_data', $parent_data);
}
}
else
{
$data = $this->displayallsurveys();
$this->load->view('SurveyPage', array('data' => $data));
}
}