make password

salam!

hello

i want to make validasi password to download. in my attachment have a password. if everyone to download, he must input a password. nach! i use CActiveForm and i use method get and action to /download; like that my code

view




<div class="form">

        

  <?php $form=$this->beginWidget('CActiveForm', array(

		'id'=>'log-form',

		'enableClientValidation'=>true,

		'clientOptions'=>array(

			'validateOnSubmit'=>true,

		),

		'action'=>http://localhost/SupportSuite/index.php?r=down/download;

		

		'method'=>'post'

		

	)); ?>

          

    <h1>Judul <?php echo $model->downtitle; ?></h1>

        <div class="row">


            <?php  if($model->downpassword!=""){?>

                    <div class="row">

                    	

                    	<?php echo $form->hiddenField($model,'downid')?>

                        <?php echo $form->hiddenField($model,'downpassword')?>

                        <?php echo $form->labelEx($model,'Masukkan Password'); ?>

                        <?php echo $form->passwordField($model,'Password') ?>

                    </div>

                 

                    <div class="row buttons">

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

                    </div>

         

	 	    <?php }else {

                    echo 'silahkan download ';

                    echo CHtml::link($model->downurl,array('displaySavedImage','id'=>$model->downid));

          

                  }?>

           

            <div class="row">

                nilai <?php echo CHtml::encode($data->valPass); ?>

            </div>  

            

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

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

</div>



in my controler




public function actionDownload()

	{

		$model=new Down;

		// if it is ajax validation request

		if(isset($_POST['ajax']) && $_POST['ajax']==='log-form')

		{

			echo CActiveForm::validate($model);

			Yii::app()->end();

		}

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

		{

			$model->attributes=$_POST['Down'];

			$model2->attributes=$_POST['Down'];

			

			if($_POST['Password']==$_POST['downpassword'])

			//if($model->Password==$model->downpassword)

			{

				$this->redirect(array('download'));  

			}

			else 

			{

				//$this->redirect(array('index'));  

			}

		}

	}



i have problem in this.

this value always same $_POST[‘Password’] and $_POST[‘downpassword’]

can you all help me, how to get value from my database and inputan so that i can different this value. thanks

$_POST[‘Down’] holds the whole form values…

$_POST[‘Down’][‘password’] is the password

$_POST[‘Down’][‘downpassword’] is the downpassword

But your code is not good… as anybody that would take a look at the HTML source… would read the download password…

You need a form to just get the password, without the hidden field downpassword…

in the actionDownload you get the downpassword from the database and compare to the entered password…

btw

if you do


$model->attributes=$_POST['Down'];

you can use


$model->password

thanks you.

i have other problem. i cann’t get value rom CJuiDatePicker. the value always 0

this my code:




<div class="row">

     <?php echo $form->labelEx($model,'Time Expiyed'); ?>

        <?php 

		$this->widget('zii.widgets.jui.CJuiDatePicker', array(

		'name'=>'newsdtime',

		'model'=>$model,

		'attribute'=>'newsdtime',

		'language'=>Yii::app()->language=='et' ? 'et' : null,

		'options'=>array(

			'showAnim'=>'fold', // 'show' (the default), 'slideDown', 'fadeIn', 'fold'

			'showOn'=>'button', // 'focus', 'button', 'both'

			//'buttonText'=>Yii::t('ui','Select form calendar'), 

			'buttonImage'=>Yii::app()->request->baseUrl.'/images/calendar.gif', 

			'buttonImageOnly'=>true,

		),

		'htmlOptions'=>array(

			'style'=>'width:80px;vertical-align:top'

		),  

	));

<?php echo $form->error($model,'newsdtime'); ?>

</div>



can you help me again? hee :smiley: thanks before

For new / different problems, please open new threads in the future

As for the problem with the date… the code seems OK to me… could be that you don’t have a validation rule for this field and that’s why its always 0 ?

this my rules




return array(

			array('newstitle, newstext','required'),

			array('active', 'numerical', 'integerOnly'=>true),

			array('newstitle', 'length', 'max'=>255),

			array('newstext', 'length', 'max'=>4096),

			array('newstitle', 'safe', 'on'=>'search'),

			);



any problem ?

i donn’t know what must i do :-/

thanks you mdomba. i have been make new post about this but I donn’t know the result. so may be you more know than me :-D, heehee . thank a lot of friend

oh y.

how must i make a validation rule ?

This explains all about massive assignment - http://www.yiiframework.com/doc/guide/1.1/en/form.model#securing-attribute-assignments

if i use $model=>$_POST[‘Down’] the value of $model->downpassword is empty. it is my reason use that. but i think it’is enough if i post it’s downid only . what are you opinian? any ide :-/