當我使用codeIgniter和ReCaptcha時,這是一個奇怪的行爲。ReCaptcha無效+ CodeIgniter表單助手=表單數據丟失
我用ReCaptcha作爲一個簡單的應用程序/幫手。我所做的唯一的變化是重命名API「recaptcha_helper.php」我加入
if(!defined('RECAPTCHA")){
define('RECAPTCHA',true);
[API code]
}
當發佈數據到我的控制器則結果並不如預期。
ReCaptcha valid/form valid = works fine!
ReCaptcha valid/form not valid = works fine!
ReCaptcha not valid/form valid = all form data lost
ReCaptcha not valid/form not valid = all form data lost + validation lost
此外,我使用「set_value('input_name')」像我所做的所有其他網站。它曾經像一個魅力工作,直到今天,當我把一個形式的recaptcha。
這裏是控制器:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Register extends MY_Controller {
var $form_rules = array(
array(
'field' => 'user_first_name',
'label' => 'Prénom ',
'rules' => 'trim|required|max_lenght[50]|xss_clean'),
array(
'field' => 'user_last_name',
'label' => 'Nom ',
'rules' => 'trim|required|max_lenght[50]|xss_clean'),
array(
'field' => 'user_email',
'label' => 'Courriel ',
'rules' => 'trim|required|max_lenght[100]|valid_email|xss_clean'),
array(
'field' => 'user_email_confirm',
'label' => 'Confirmation du courriel ',
'rules' => 'trim|required|max_lenght[100]|matches[user_email]|xss_clean'));
public function __construct(){
parent::__construct();
}
public function register(){
$this->load->library('form_validation');
$this->form_validation->set_rules($this->form_rules);
// RECAPTCHA STUFF
$this->load->helper('recaptcha');
$publickey = "****";
$privatekey = "****";
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
if(isset($_POST) && count($_POST)>0){
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($resp->is_valid) {
if($this->form_validation->run()){
$new_data = array( 'user_first_name' => $_POST['user_first_name'],
'user_last_name' => $_POST['user_last_name'],
'user_email' => $_POST['user_email']);
$this->db->insert('user', $new_data);
$new_user_id = $this->db->insert_id();
$this->load->view('header');
$this->load->view('sent');
$this->load->view('footer');
return;
}
}else{
$error = $resp->error;
}
$data = $_POST;
}
$data['recaptcha'] = recaptcha_get_html($publickey, $error);
$this->load->view('header');
$this->load->view('inscription_form', $data);
$this->load->view('footer');
}
}
這裏是形式
<div id="inscription">
<?php echo form_open(); ?>
<p>
<label for="user_first_name">Prénom *</label>
<input type="text" name="user_first_name" value="<?php echo set_value('user_first_name'); ?>" maxlength="50" />
<?php echo form_error('user_first_name'); ?>
</p>
<p class="clear">
<label for="user_last_name">Nom *</label>
<input type="text" name="user_last_name" value="<?php echo set_value('user_last_name'); ?>" maxlength="50" />
<?php echo form_error('user_last_name'); ?>
</p>
<p class="clear">
<label for="user_email">Courriel *</label>
<input type="text" name="user_email" value="<?php echo set_value('user_email'); ?>" maxlength="100" />
<?php echo form_error('user_email'); ?>
</p>
<p class="clear">
<label for="user_email_confirm">Confirmation du courriel *</label>
<input type="text" name="user_email_confirm" value="<?php echo set_value('user_email_confirm'); ?>" maxlength="100" />
<?php echo form_error('user_email_confirm'); ?>
</p>
<div class="clear"></div>
<div><?php echo $recaptcha; ?></div>
<p><input type="submit" value="Envoyer"/></p>
<p class="clear">* Tous les champs de ce formulaire sont requis.</p>
</form>
</div>
任何想法,爲什麼出現這種情況?
另外我使用驗證碼1.11版 – Simmoniz
您需要發佈您的查看+控制器表格,看看發生了什麼 – Laurence
當然。我在問題中添加了代碼。謝謝 – Simmoniz