form doesn't send

hi, one of my super noob questions:

I created a simple recovery password script and it doesn’t seem to move at all when i submit the form

did i miss something ?

controller code




	public function actionForget()

	{

		$form = new Wsmembers;

		

		if(isset($_POST['Wsmembers']))

		{

			$form->attributes = $_POST['Wsmembers'];

			$sql = "SELECT sha1(WSLoginPassword) FROM wsmembers WHERE WSEmailAddress = :email";

			$command = Yii::app()->db->createCommand($sql);

			$command->bindValue(":email", $_POST['WSEmailAddress']);

			$pass = $command->query();

			

			if($pass === 1){

				$to = $_POST['WSEmailAddress'];

				$subject = "Your Password";

				$message = "Your password is = $pass";

				$headers  = 'MIME-Version: 1.0' . "\r\n";

				$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

				$headers .= 'From: buggyman<buggyman@gmail.com>' . "\r\n";


				mail($to, $subject, $message, $headers);

				Yii::app()->user->setFlash('recover','Your password has been sent to your email address');			

				$this->redirect('forget', array('wsmembers/forget'));

				

			}

		}			

		$this->render('forget', array('form' => $form));		

	}



forget.php view form




<?php

$this->breadcrumbs=array(

	'Member'=>array('index'),

	'forget',

);

?>


<h3>Recover Password</h3>

<div class="form">

<?php echo CHtml::beginForm(); ?>

<?php echo CHtml::errorSummary($form)?>

Please Enter Your Email Address

<div class="row">

	<?php echo CHtml::activeLabelEx($form,'WSEmailAddress'); ?>

	<?php echo CHtml::activeTextField($form,'WSEmailAddress'); ?>

</div>


<div class="action">

<?php echo CHtml::submitButton('Recover'); ?>

</div>


<?php echo CHtml::endForm(); ?>

</div>






$pass = $command->query();

                        

if($pass === 1){



$pass can’t be an integer. Check the API: http://www.yiiframework.com/doc/api/1.1/CDbCommand#query-detail

Maybe you should use queryRow() and check if it is not false.

Try This




 public function actionForget()

        {

                $form = new Wsmembers;

                

                if(isset($_POST['Wsmembers']))

                {

                        $form->attributes = $_POST['Wsmembers'];

                        

                        $CRI=new CDbCriteria;

                        $CRI->select = 'sha1(WSLoginPassword)';

                        $CRI->condition = 'WSEmailAddress = '.$form->WSEmailAddress; // or  $CRI->condition = "WSEmailAddress = '".$form->WSEmailAddress."' ";

                        $pass = $form->find($CRI);// if dosent work try $form->findAll($CRI)

                        

                        if($pass === 1){

                                $to = $form->WSEmailAddress;

                                $subject = "Your Password";

                                $message = "Your password is = $pass";

                                $headers  = 'MIME-Version: 1.0' . "\r\n";

                                $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

                                $headers .= 'From: buggyman<buggyman@gmail.com>' . "\r\n";


                                mail($to, $subject, $message, $headers);

                                Yii::app()->user->setFlash('recover','Your password has been sent to your email address');                      

                                $this->redirect('forget', array('wsmembers/forget'));

                                

                        }

                }                       

                $this->render('forget', array('form' => $form));                

        }  






thanks, but i got this

how do we quote this line ?




$CRI->condition = 'WSEmailAddress = ' .$form->WSEmailAddress; 



I tried

  • $CRI->condition = ‘WSEmailAddress = \’$form->WSEmailAddress\’’; ( doesn’t work )

  • $CRI->condition = “WSEmailAddress = \’$form->WSEmailAddress\’”; ( doesn’t work as well)

  • $CRI->condition = “WSEmailAddress = ‘$form->WSEmailAddress’”; ( same with this )




$CRI->condition = 'WSEmailAddress = :mail';

$CRI->params=array(':mail'=>$form->WSEmailAddress); 



I just tried this before i got your reply, but it doesn’t work too ???

Error is because mysql coomand this will work




 public function actionForget()

        {

                $form = new Wsmembers;

                

                if(isset($_POST['Wsmembers']))

                {

                        $form->attributes = $_POST['Wsmembers'];

                        

                        $CRI=new CDbCriteria;

                        $CRI->select = 'sha1(WSLoginPassword)';

                        $CRI->condition = "WSEmailAddress = '".$form->WSEmailAddress."' ";

                        $pass = $form->find($CRI);// if dosent work try $form->findAll($CRI)

                        

                        if($pass === 1){

                                $to = $form->WSEmailAddress;

                                $subject = "Your Password";

                                $message = "Your password is = $pass";

                                $headers  = 'MIME-Version: 1.0' . "\r\n";

                                $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

                                $headers .= 'From: buggyman<buggyman@gmail.com>' . "\r\n";


                                mail($to, $subject, $message, $headers);

                                Yii::app()->user->setFlash('recover','Your password has been sent to your email address');                      

                                $this->redirect('forget', array('wsmembers/forget'));

                                

                        }

                }                       

                $this->render('forget', array('form' => $form));                

        }  









$CRI->condition = "WSEmailAddress = '".$form->WSEmailAddress."'";

$pass = $form->find($CRI);



or




$pass = $form->findAll($CRI);



doesn’t throw quote error anymore, but it got stuck, that the page won’t move at all after clicking the

submit button… why is that happening, any idea ? ???

this will help you create in Wsmebers model

object name :

public $emailed;


              

 public function actionForget()

        {

                $form = new Wsmembers;

                $form->emailed = "Email Form";


                if(isset($_POST['Wsmembers']))

                {

                        $form->attributes = $_POST['Wsmembers'];

                        

                        $CRI=new CDbCriteria;

                        $CRI->select = 'sha1(WSLoginPassword)';

                        $CRI->condition = "WSEmailAddress = '".$form->WSEmailAddress."' ";

                        $pass = $form->find($CRI);// if dosent work try $form->findAll($CRI)

                        

                        if($pass === 1){

                                $form->emailed = "Sent";

                                $to = $form->WSEmailAddress;

                                $subject = "Your Password";

                                $message = "Your password is = $pass";

                                $headers  = 'MIME-Version: 1.0' . "\r\n";

                                $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

                                $headers .= 'From: buggyman<buggyman@gmail.com>' . "\r\n";


                                mail($to, $subject, $message, $headers);

                                Yii::app()->user->setFlash('recover','Your password has been sent to your email address');                      

                             $this->render('forget', array('form' => $form));    

                                

                        }

                }                       

                $this->render('forget', array('form' => $form));                

        }  




and in forget View This





<?php if($form->emailed = "Email Form") : ?>


<?php

$this->breadcrumbs=array(

        'Member'=>array('index'),

        'forget',

);

?>


<h3>Recover Password</h3>

<div class="form">

<?php echo CHtml::beginForm(); ?>

<?php echo CHtml::errorSummary($form)?>

Please Enter Your Email Address

<div class="row">

        <?php echo CHtml::activeLabelEx($form,'WSEmailAddress'); ?>

        <?php echo CHtml::activeTextField($form,'WSEmailAddress'); ?>

</div>


<div class="action">

<?php echo CHtml::submitButton('Recover'); ?>

</div>


<?php echo CHtml::endForm(); ?>

</div>

<?php else if($form->emailed = "Sent") :?>

<?php 

//echo something hire like 


echo "Email was send to your email, thank you for using our password reset form"; ?>


<?php endif; ?>




i forgot you have to echo password

in your mail form




  if($pass === 1){

                                $to =  $form->WSEmailAddress;

                                $subject = "Your Password";

                                $message = "Your password is = ".$pass->WSLoginPassword;

                                $headers  = 'MIME-Version: 1.0' . "\r\n";

                                $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

                                $headers .= 'From: buggyman<buggyman@gmail.com>' . "\r\n";


                                mail($to, $subject, $message, $headers);

                                Yii::app()->user->setFlash('recover','Your password has been sent to your email address');                      

                                $this->redirect('forget', array('wsmembers/forget'));

                                

                        }









I did try, but what’s bothering me now is that, it doesn’t send the email nor do the query, when it doesn’t have much difference in my registration stuff, only the query itself

try to echo out all $form->attributes in your view to see if thy are full

yeah i did




<?php echo $form->WSEmailAddress; ?>



or even




<?php echo "<pre>",print_r($form->attributes),"</pre>"; ?>






Array

(

    [WSEmailConfirmed] => 0

    [WSMembershipLoginAttempts] => 0

    [WSMembershipLockedOut] => 0

    [WSMembershipSystemLockedOut] => 0

    [WSEmailAddress] => buggyman@gmail.com

    [MemberShipID] => 

    [WSLoginName] => 

    [WSLoginPassword] => 

    [WSMembershipDateSetup] => 

    [WSMembershipDateConfirmed] => 

    [WSMembershipContactName] => 

    [WSMembershipSecretQuestion] => 

    [WSMembershipSecretAnswer] => 

    [WSMembershipLockOutDateTime] => 

    [WSLoginNameAllUsers] => 

    [WSLoginPasswordAllUsers] => 

    [IntroducingMemberID] => 

)

1



email should be sent

try to echo out




if($pass === 1){


echo $form->WSEmailAddress;

echo $pass->WSLoginPassword;


}



and see if thy are filed

doesn’t echo out anything, but i did this




if($pass !== null)



it does send the email now

but the email body contains no password retrieved from table




Your password is = 



???

print_r($pass) see what is in there if dosent show anything try to findAll()




$CRI=new CDbCriteria;

                        //$CRI->select = 'sha1(WSLoginPassword)';

                        $CRI->condition = "WSEmailAddress = '".$form->WSEmailAddress."' ";

                        $pass = $form->findAll($CRI);


print_r($pass);



i`n mysql

you cant decode sha(WSLoginPassword);

but it works with my login script in yii, I use sha1() when checking,

a few minutes ago I was able to send the email and retrieve back the encrypted password, it’s weird sha1 doesn’t work now…maybe it’s with the way i am quoting each variables ???

yes but mysql doesen`t support decoding sha1

upoad entire login system and i will help you, you can only upadate your password or , create a random update password and then send new password to email