Yii Framework Forum: Recapchalib - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Recapchalib recapchalib Rate Topic: -----

#1 User is offline   canailla007 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 06-January 13

Posted 21 January 2013 - 06:43 PM

Actualmente he modificado el condigo para eliminar el captcha y que solamente aparezca el recaptcha

He seguido los pasos que se indican en http://www.yiiframew...-your-projects/

1) Yii::import('ext.recaptchalib',true);
$publickey = "my key public";
echo recaptcha_get_html($publickey); ?>

Con esto consigo que se muestre el recaptcha

Modifique la parte de la vista :

<?php
/* @var $this SiteController */
/* @var $model ContactForm */
/* @var $form CActiveForm */

$this->pageTitle=Yii::app()->name . ' - Contact Us';
$this->breadcrumbs=array(
'Contact',
);
?>
<?php Yii::import('ext.recaptchalib',true);
$publickey = "mi publico key ";?>

<h1>Contact Us</h1>

<?php if(Yii::app()->user->hasFlash('contact')): ?>

<div class="flash-success">
<?php echo Yii::app()->user->getFlash('contact'); ?>
</div>

<?php else: ?>

<p>
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
</p>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'contact-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>

<p class="note">Campos con <span class="required">*</span> son obligatorios.</p>

<?php echo $form->errorSummary($model); ?>

<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name'); ?>
<?php echo $form->error($model,'name'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'email'); ?>
<?php echo $form->textField($model,'email'); ?>
<?php echo $form->error($model,'email'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'subject'); ?>
<?php echo $form->textField($model,'subject',array('size'=>60,'maxlength'=>128)); ?>
<?php echo $form->error($model,'subject'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'body'); ?>
<?php echo $form->textArea($model,'body',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'body'); ?>
</div>


<?php endif; ?>-->
<?php echo recaptcha_get_html($publickey); ?>

<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>

<?php $this->endWidget(); ?>

</div><!-- form -->

<?php endif; ?>

Asimismo he cambiado en SiteController.php la funciĆ³n:

public function actionContact()
{

//----- DeclaraciĆ³n del Recaptcha
Yii::import('ext.recaptchalib',true);
$privatekey = 'my private key';
$resp = recaptcha_check_answer($privatekey, $_SERVER['REMOTE_ADDR'],
Yii::app()->request->getParam('recaptcha_challenge_field'),
Yii::app()->request->getParam( 'recaptcha_response_field' ) );
// ---------------------------------------------------------------------------------------
$model=new ContactForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
$name='=?UTF-8?B?'.base64_encode($model->name).'?=';
$subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
$headers="From: $name <{$model->email}>\r\n".
"Reply-To: {$model->email}\r\n".
"MIME-Version: 1.0\r\n".
"Content-type: text/plain; charset=UTF-8";
// recaptcha_check_answer returns a ReCaptchaResponse object
// which has two properties: is_valid and error.
// I dont think I need to explain that
if($resp->is_valid)
{
mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
}
else
{
Yii::app()->user->setFlash('contact','Introduce un correcto codigo recaptcha');
$this->render('contact',array('model'=>$model));
}



$this->refresh();
}
}
$this->render('contact',array('model'=>$model));
}

Pero no me manda el email es decir no validad el captcha, alguien me puede ayudar. Un saludo.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users