[eluser]haily_php[/eluser]
I have module "Commit" which is used to feedback News. I want to use ajax to execute process but my code hasn't run exact.
View---
Code:
<div id="detail_comment1">
<div id="ketqua"></div>
<h3>Send Feedback</h3>
<p> <input id="comment_title" type="text" maxlength="250" class="comment_input text" value="Title *"/> <input id="comment_telephone" type="text" maxlength="250" class="comment_input" value="Telephone *"/></p>
<p> <input id="comment_fullname" type="text" maxlength="250" class="comment_input text2" value="Full Name *"/>
<input id="comment_email" type="text" maxlength="250" class="comment_input text2" value="Your Email *"/>
</p>
<p><input id="comment_address" type="text" maxlength="250" class="comment_input text" value="Your Address"/></p>
<p>
<textarea rows="10" cols="130" class="comment_textarea" id="comment_content"></textarea>
</p>
</div>
</form>
Controller-----
Code:
public function checkcomment(){
$this->load->helper(array("url","form"));
$name=$this->input->post("c_name");
$title=$this->input->post("c_title");
$telephone=$this->input->post("c_telephone");
$email=$this->input->post("c_email");
$adress=$this->input->post("c_adress");
$content=$this->input->post("c_content");
$this->load->library("form_validation");
$this->form_validation->set_rules($title,"Comment title","required");
$this->form_validation->set_rules($name,"Full name","required");
$this->form_validation->set_rules($telephone,"Telephone","required|is_natural");
$this->form_validation->set_rules($email,"Email","required|valid_email");
$this->form_validation->set_rules($content,"Content","required");
if($this->form_validation->run()==FALSE){
$this->load->view("comment");
}else{
echo "Correct information"; // debug code
}
View "Comment" --- to show error validation
Code:
<?php echo validation_errors();?>
File ajax ---
Code:
function comment(){
document.getElementById("ketqua")[removed]="Loading data ... ";
title=encodeURI(document.getElementById('comment_title').value);
telephone=encodeURI(document.getElementById('comment_telephone').value);
email=encodeURI(document.getElementById('comment_email').value);
adress=encodeURI(document.getElementById('comment_address').value);
content=encodeURI(document.getElementById('comment_content').value);
name=encodeURI(document.getElementById('comment_fullname').value);
http.open('post','http://localhost/ci/index.php/index/checkcomment',true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
http.onreadystatechange=process;
http.send('c_title='+title+"&c_telephone="+telephone+"&c_email="+email+"&c_adress="+adress+"&c_content="+content+"&c_name="+name);
}
function process(){
if(http.readyState == 4 && http.status == 200){
kq=http.responseText;
document.getElementById('ketqua')[removed]= kq;
}
}
Error: if I enter correct information, program has also shown about Form validation
Please help me