我想在控制器(CI)中创建一个确认框。我该怎么做?我知道在view.php文件中写javascript确认但是现在我有会话并在点击提交按钮的最后提交表单上验证为null或有效。所以,我需要在CI控制器功能中进行确认对话。请帮帮我。
这是我的观看代码。
<div align="center" class="col-md-9" id="label">
<form method="post" id="formsubmit1" name="formsubmit1" action="{base_url('home/completionform')}" enctype="multipart/form-data">
<div class="form_block">
<p class="question">
You can now submit that you answered above or you can continue to answer next questions.
</p>
<br>
<input type="submit" name="submit" class="btn btn-default nextbutton" id="btn_submit" value="Submit" onclick="completionform();" />
<a href="{base_url('home/question5')}" class="btn btn-default">Continue</a>
</div>
</form>
</div>
这是我的提交完成表单控制器功能代码。
public function completionform()
{
$sess_data=$this->session->userdata();
$ses_key = key($sess_data);
if (empty($sess_data['user_info']))
{
echo "Session has been destroyed~!";
}
else
{
$user_info = ($sess_data['user_info']);
if (!empty($sess_data['question5']))
{
$q1 = ($sess_data['question1']);
$q2 = ($sess_data['question2']);
$q3 = ($sess_data['question3']);
$q4 = ($sess_data['question4']);
$q5 = ($sess_data['question5']);
$q6 = ($sess_data['question6']);
$q7 = ($sess_data['question7']);
}
else
{
$q1 = ($sess_data['question1']);
$q2 = ($sess_data['question2']);
$q3 = ($sess_data['question3']);
$q4 = ($sess_data['question4']);
}
$username = '';
$email = '';
$phone = '';
$answer1 = '';
$answer2 = '';
$answer3 = '';
$answer4 = '';
$answer5 = '';
$answer6 = '';
$answer7 = '';
if (!empty($sess_data['question5']))
{
for ($i = 0; $i < count($user_info); $i++)
{
$key=key($user_info);
$val=$user_info[$key];
if ($val<> ' ')
{
if ($key === 'name')
{
$username = $val;
//echo $result1;
}
else if ($key === 'phone')
{
$phone = $val;
//echo $result2;
}
else if ($key === 'mail')
{
$email = $val;
//echo $result3;
}
//echo $key ." = ". $val ." <br> ";
}
next($user_info);
}
for ($i = 0; $i < count($q1); $i++)
{
$key=key($q1);
$val=$q1[$key];
if ($val<> ' ')
{
if ($key === 'answer1')
{
$answer1 = $val;
//echo $result1;
}
//echo $key ." = ". $val ." <br> ";
}
next($q1);
}
for ($i = 0; $i < count($q2); $i++)
{
$key=key($q2);
$val=$q2[$key];
if ($val<> ' ')
{
if ($key === 'answer2')
{
$answer2 = $val;
//echo $result1;
}
//echo $key ." = ". $val ." <br> ";
}
next($q2);
}
for ($i = 0; $i < count($q3); $i++)
{
$key=key($q3);
$val=$q3[$key];
if ($val<> ' ')
{
if ($key === 'answer3')
{
$answer3 = $val;
//echo $result1;
}
//echo $key ." = ". $val ." <br> ";
}
next($q3);
}
for ($i = 0; $i < count($q4); $i++)
{
$key=key($q4);
$val=$q4[$key];
if ($val<> ' ')
{
if ($key === 'answer4')
{
$answer4 = $val;
//echo $result1;
}
//echo $key ." = ". $val ." <br> ";
}
next($q4);
}
for ($i = 0; $i < count($q5); $i++)
{
$key=key($q5);
$val=$q5[$key];
if ($val<> ' ')
{
if ($key === 'answer5')
{
$answer5 = $val;
//echo $result1;
}
//echo $key ." = ". $val ." <br> ";
}
next($q5);
}
for ($i = 0; $i < count($q6); $i++)
{
$key=key($q6);
$val=$q6[$key];
if ($val<> ' ')
{
if ($key === 'answer6')
{
$answer6 = $val;
//echo $result1;
}
//echo $key ." = ". $val ." <br> ";
}
next($q6);
}
for ($i = 0; $i < count($q7); $i++)
{
$key=key($q7);
$val=$q7[$key];
if ($val<> ' ')
{
if ($key === 'answer7')
{
$answer7 = $val;
//echo $result1;
}
//echo $key ." = ". $val ." <br> ";
}
next($q7);
}
}
else
{
for ($i = 0; $i < count($user_info); $i++)
{
$key=key($user_info);
$val=$user_info[$key];
if ($val<> ' ')
{
if ($key === 'name')
{
$username = $val;
//echo $result1;
}
else if ($key === 'phone')
{
$phone = $val;
//echo $result2;
}
else if ($key === 'mail')
{
$email = $val;
//echo $result3;
}
//echo $key ." = ". $val ." <br> ";
}
next($user_info);
}
for ($i = 0; $i < count($q1); $i++)
{
$key=key($q1);
$val=$q1[$key];
if ($val<> ' ')
{
if ($key === 'answer1')
{
$answer1 = $val;
//echo $result1;
}
//echo $key ." = ". $val ." <br> ";
}
next($q1);
}
for ($i = 0; $i < count($q2); $i++)
{
$key=key($q2);
$val=$q2[$key];
if ($val<> ' ')
{
if ($key === 'answer2')
{
$answer2 = $val;
//echo $result1;
}
//echo $key ." = ". $val ." <br> ";
}
next($q2);
}
for ($i = 0; $i < count($q3); $i++)
{
$key=key($q3);
$val=$q3[$key];
if ($val<> ' ')
{
if ($key === 'answer3')
{
$answer3 = $val;
//echo $result1;
}
//echo $key ." = ". $val ." <br> ";
}
next($q3);
}
for ($i = 0; $i < count($q4); $i++)
{
$key=key($q4);
$val=$q4[$key];
if ($val<> ' ')
{
if ($key === 'answer4')
{
$answer4 = $val;
//echo $result1;
}
//echo $key ." = ". $val ." <br> ";
}
next($q4);
}
}
$this->load->model('answer_model');
$this->answer_model->add_data('user_tbl',['U_Id'=>"default", 'User_Name'=>$username, 'Phone_Number'=>$phone, 'Mail_Address'=>$email, 'Answer_1'=>$answer1, 'Answer_2'=>$answer2, 'Answer_3'=>$answer3, 'Answer_4'=>$answer4, 'Answer_5'=>$answer5, 'Answer_6'=>$answer6, 'Answer_7'=>$answer7]);
答案 0 :(得分:0)
在控制器功能
中尝试此操作echo "<script language=\"javascript\">confirm('confirm box');</script>";
这可以帮到你
$this->load->library('session');
$result = $this->your_model->user_ques($question);
if ($result) {
foreach ($result as $ans)
{
$sess_array = array(
'full_name' => $ans->full_name,
'catagory' => $ans->catagory,
);
$this->session->set_userdata('logged_in', $sess_array);
}
return TRUE;