Good morning I have a php button like this.
echo CHtml::button(Yii::t('site', 'Help (F2)'), array('id' => 'run_example'));
that calls a function js:
<script> $("#run_example").click(function(){ Sideshow.start({ listAll:true });}); </script>
What I need to do is that when a user clicks on the button, the user information is sent as user name, date and time of the action.
the log data is taken in the file LoginForm.php
class LoginForm extends CFormModel
{
public $username;
public $password;
public $rememberMe;
public $language;
public $loginMobile;
private $_identity;
/**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated.
*/
public function rules()
{
return array(
// username and password are required
array('username, password, language', 'required'),
// rememberMe needs to be a boolean
array('rememberMe, loginMobile', 'boolean'),
// password needs to be authenticated
array('password', 'authenticate'),
);
}
/**
* Declares attribute labels.
*/
public function attributeLabels()
{
return array(
'rememberMe'=>Yii::t('site','Remember me next time'),
'username' => Yii::t('site','Username'),
'password' => Yii::t('site','Password'),
'language' => Yii::t('site','Languages'),
);
}
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute,$params)
{
if(!$this->hasErrors())
{
$this->_identity=new UserIdentity($this->username,$this->password);
if(!$this->_identity->authenticate()){
switch($this->_identity->errorCode){
case UserIdentity::ERROR_USERNAME_INVALID:
$this->addError('username',Yii::t('site','Incorrect username'));
break;
case UserIdentity::ERROR_PASSWORD_INVALID:
$this->addError('password',Yii::t('site','Incorrect password'));
break;
case UserIdentity::ERROR_USERNAME_INACTIVE:
$this->addError('username',Yii::t('site','Your Accout Not active'));
break;
case UserIdentity::ERROR_USERNAME_LOCKED:
$this->addError('username',Yii::t('site','The user is blocked, please wait a few minutes before trying again'));
break;
}
}
}
}
/**
* Logs in the user using the given username and password in the model.
* @return boolean whether login is successful
*/
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->username,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 3600*24; // 30 days
//$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
Yii::app()->session['login']=true;
//Se agrega logica para accesos desde Dispositivos Moviles
Yii::app()->session['loginMobile']=isset($_POST['LoginForm'])?($_POST['LoginForm']['loginMobile']=='1'?true:false):false;
return true;
}
else
return false;
}
}
I do not know very well how to do it I understand that it can be done with ajax but I have not used it so I have no idea how to do it ..
I hope you can help me; thank you very much.