witam, chciałem użyć captchy z Kohana Fk do ajaxowego dodawania komentarzy i robie to tak:
Metoda generujaca captche i widok z kontrolerze o nazwie Ajax_Controller: public function add_comment() {
$this->template = new View('App/tab_template');
$this->template->content =new View('App/elements/comment');
$this->template->content->captcha = new Captcha;
if($_POST) {
if ( Captcha::valid($this->input->post('captcha_response'))) {
}else {
}
}
$this->template->render(true);
}
Widok comment:<div id="add_comment_wrapper">
<?php echo form
::open('ajax/add_comment',array('id'=>'valid_form','method'=>'post')); ?> <?php echo form
::input('name'); ?> <?php echo form
::textarea('text'); ?> <?php
echo $captcha->render(); // Shows the Captcha challenge (image/riddle/etc) echo '<br />Przepisz kod:'; echo form
::input('captcha_response'); if (!Captcha
::valid($this->input->post('captcha_response')) && !empty($_POST['submit']) ) { echo ' <span style="color:red;margin:2px 0px 0px 5px;padding:0px;font-size:13px;">Zły kod</span>'; }
?>
<?php echo form
::submit('submit','Dodaj'); ?> <?php echo form
::close(); ?> </div>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("#valid_form").submit(function(e){
e.preventDefault();
var captcha = $("input[name='captcha_response']").val();
$.ajax({
type: "POST",
url: "
<?php echo url
::base(); ?>ajax/add_comment",
data:"captcha_response="+captcha,
async: true,
success: function(msg) {
$('#add_comment_wrapper').html(msg);
},
error: function(msg) {
alert('error2');
}
});
});
});
</script>
proszę nie zwracać uwagi na prostote, chodzi o test poki co , moim zamiarem jest po wyslaniu posta ajaxem ponownie wczytac medote add_comment wrac z widokiem i NOWA captcha..(jest ciagle ta sama)
ps. dziala jak pomiedzy postami usune sesje recznie, ale juz nie dziala jak usune w kodzie.. nic z tego nie rozumiem prosze o pomoc!
Ten post edytował big_shoes 29.04.2010, 10:00:47