CakePHP :: Changing The Way It Is Sending Form Data [Passwords]? - cakephp

I have built a form using the CakePHP form helper and I am trying to get it to change my users password, that should not be to hard. But for some reason when I submit the form it submits in plan text.
$UsersPass = $this->Form->create('PasswordUpdate', array('id' => 'ChangePassword', 'url' => '/update_password'));
$UsersPass .= $this->Form->input('oldpassword', array('div' => false, 'type' => 'password', 'label' => 'Old Password'));
$UsersPass .= $this->Form->input('passwordnew', array('div' => false, 'type' => 'password', 'label' => 'New Password'));
$UsersPass .= $this->Form->input('passwordconfirm', array('div' => false, 'type' => 'password', 'label' => 'Confirm'))l
$UsersPass .= $this->Form->submit(' ', array('div' => false, 'type' => 'submit', 'class' => 'Button_DoneSubmit') );
echo UsersPass;
Any way of getting CakePHP to make sure that it does not submit in plan text?
thanks.

Related

cakephp : how to displays the checkbox value that has been selected in from edit

echo $this->Form->input('product_id', array(
'label'=>false,
'type'=>'select',
'multiple'=>'checkbox',
'options'=>$product,
));
I am trying to adding 'checked=>true' in from input but failed
this is screenshoot of the form edit, the data already selected is not checked
You can tell CakePHP which checkboxes are checked by passing an array of selected values:-
$selected = []; // An array of selected values
echo $this->Form->input('product_id', array(
'label' => false,
'type' => 'select',
'multiple' => 'checkbox',
'options' => $product,
'selected' => $selected
));
If you wanted to select all the values to start with you could pass the array keys of $product to the selected option:-
$selected = array_keys($product);
echo $this->Form->input('product_id', array(
'label' => false,
'type' => 'select',
'multiple' => 'checkbox',
'options' => $product,
'selected' => $selected
));

Auth->login() function not working properly

Here's the component declaration in AppController.php>
'Auth' => array(
'authenticate' => array(
'Form' => array(
'userModel' => 'User',
'fields' => array('username' => 'email', 'password' => 'code'),
'scope' => array('activated' => true),
),
),
'loginAction' => array('controller' => 'users', 'action' => 'login'),
'loginRedirect' => array('controller' => 'members', 'action' => 'dashboard', 'admin' => true),
'authError' => 'No Permission',
'logoutRedirect' => array('controller' => 'pages', 'action' => 'home'),
'userScope' => array('User.activated' => true),
),
The login form:
<?= $this->Form->create('User', array('url' => '/users/login', 'class' => 'form-inline'));?>
<div class="form-group">
<?= $this->Form->input('User.email', array(
'div' => false,
'label' => false,
'placeholder' => 'е-пошта',
'class' => 'form-control',
'required' => true,
));?>
<?= $this->Form->input('User.code', array(
'div' => false,
'label' => false,
'placeholder' => 'сериски број',
'class' => 'form-control',
'required' => true,
));?>
<?= $this->Form->button('<i class="fa fa-user"></i>', array('type' => 'submit', 'class' => 'btn btn-primary', 'escape' => false));?>
</div>
<?= $this->Form->end();?>
And a snippet of the login function:
// ...
if($this->request->is('post')) {
if($this->Auth->login()) {
if(isset($this->request->data['User']['token']) && $this->request->data['User']['token']) {
$token = substr(md5(time()), 0, 32);
$this->User->id = $this->Auth->user('id');
$this->User->saveField('token', $token);
$this->Cookie->write('remember_me', $token, false, '1 week');
}
return $this->redirect($this->Auth->loginRedirect);
}
// ...
Now, when I use $this->Auth->login($this->request->data) or $this->Auth->login($this->request->data['User']), it works, but when I use only $this->Auth->login() it doesn't. I can do a workaround by logging in with $this->request->data and then putting the rest of the user data manually to be available afterwards, but I want to know why this happens. Any ideas?
EDIT
So, as Karthik Keyan mentioned hashing, i figured this was the problem. CakePHP was automatically hashing the password (code field) and I didn't want it to. So I made a custom hasher class named NoPasswordHasher as follows:
App::uses('AbstractPasswordHasher', 'Controller/Component/Auth');
class NoPasswordHasher extends AbstractPasswordHasher {
public function hash($password) {
return $password;
}
public function check($password, $hashedPassword) {
return $password == $hashedPassword;
}
}
and used it in the Auth component:
'Auth' => array(
'authenticate' => array(
'Form' => array(
'userModel' => 'User',
'fields' => array('username' => 'email', 'password' => 'code'),
'scope' => array('activated' => true),
'passwordHasher' => 'No',
),
),
It works now. Thank you.
Tell what type of errors can be display for you.Please check can you store the password in HASH (salt) format.

how to pass class in checkbox using cakephp form

i am using below code:-
echo $this->Form->input('my_radio',array(
'label' =>false,
'type' => 'select',
'multiple' => 'checkbox',
'class'=>'checkbox12',
'div'=>false,
'selected' => array_keys($sub_cat_name1),
'options' => $parent_cat_detail1
));
i did false the div but still the 'checkbox12' is adding to div.
the problem is not in the class , is in the mutiple value , you should put it true not checkbox :
echo $this->Form->input('my_radio',array(
'label' =>false,
'type' => 'select',
'multiple' => true,
'class'=>'checkbox12',
'selected' => array_keys($sub_cat_name1),
'options' => $parent_cat_detail1
));

Add form Drupal Error Page

I am working on Drupal 7. I want to display a form on "Error! The website encountered an unexpected error. Please try again later." page.
I have copied the maintenance-page.tpl.php file to my theme folder. and rendered a form in that template. Up until now the form is showing but when I submit the form, drupal is not getting into _validate and _submit functions.
Here is the code
Template File
<div class="complaint-form-message">
<h5>
We’re sorry you’re having trouble with myCCS!
Tell us about the error you’ve experienced and we’ll
get right back to you!
</h5>
</div>
<div class="complaint-form">
<?php echo drupal_render(drupal_get_form('complaint_form_form')); ?>
</div>
Form Function
function complaint_form_form($form, &$form_state){
$form['name'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#title' => 'First Name & Last Name',
);
$form['email'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#title' => 'Email Address',
);
$form['browser'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#title' => 'What browser you are using?',
);
$form['tell_us_about_error'] = array(
'#type' => 'textarea',
'#required' => TRUE,
'#title' => 'Tell us about error you experienced?',
);
$form['attachment'] = array(
'#type' => 'file',
'#title' => 'Attachment',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#submit' => 'complaint_form_submit',
);
return $form;
}
function complaint_form_validate($form, $form_state){
echo 'PPPPP<pre>'; print_r($form_state); die;
$mail = $form_state['values']['submitted_tree']['email'];
if (!valid_email_address($mail))
form_set_error('[submitted][email_address]', t('The email
address appears to be invalid.'));
}
function complaint_form_submit($form, $form_state){
echo 'DDDDD<pre>'; print_r($form_state); die;
$values = $form_state['values'];
}
Your #submit is an array you have put is as string,
So change your submit entry to the following.
and place $form['submit'] to $form['actions']['submit'];
$form['actions']['submit']=array(
'#type' => 'submit',
'#value' => t('Submit'),
'#submit' => array('complaint_form_submit'),
);
Note: **'#submit' is an array**
to add validations
$form['#validate'][] = 'complaint_form_validate';
Note: '#validate' is an array

Cakephp validations not working

Validations are working but form is not getting submitted and data is not inserted:
addgroup.ctp:
echo $form->create('Group', array('url' => array('controller' => 'admin', 'action' =>'addgroup'), 'onSubmit' => 'return Validate()'));
echo $form->input('name',array('label' => false));
<input type="submit" value="Submit"/>
<input type="button" value="Cancel"/>
Group Model:
var $validate = array(
'name' => array(
'isRequired' => array(
'rule' => 'required',
'message' => 'Enter group name.'
),
'isUnique' => array(
'rule' => 'isUnique',
'message' => 'This group name has already been taken.'
),
),
);
in controller:
$this->Group->save($this->data,array('validate' => true)
If I make any empty entry or duplicate entry it gives errormessge,
but if I make valid entries then also form gives error-message,
What m I missing here?
you need to close the form $this->Form->end('Submit'); and the save function: $this->Group->save($this->data); It will validate when it saves.

Resources