我想在控制器(CI)中做一個確認框。我應該怎麼做?我知道在view.php文件中寫javascript確認,但現在我有會話,並在點擊提交按鈕的最後提交表單上驗證爲空或有效。所以,我需要確認對話框進入CI控制器功能。請幫幫我。如何在codeigniter控制器中使用javascript確認?
這是我的視圖代碼。
<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]);
顯示控制器代碼 - 或@least到目前爲止,你已經嘗試過什麼,恕我直言,你可以隨時使用一個視圖或一個js文件,無論如何;) – sintakonte
我更新了我的問題。請檢查我的代碼。在那個函數中有來自整個項目的會話數據,我想檢查該控制器中的會話數據,並使確認框提交或不提交。 –