Muhammad Maaz
Muhammad Maaz

Reputation: 79

CakePhp help needed

I am a newbie to cakephp. For security updation I am asking the user to enter his date of birth. If he enters the correct date of birth i want to show him the other form which contains his security question and then his password.

There are two different forms.One is security check(date of birth verification) and the other is set security(security question + password).

If the security is set then security check form is first shown and asks to enter his date of birth.If date of birth is correct then set security form should be shown,which i am unable to do.

My profile page code which shows these two forms;

<?php if($_GET['edit'] == 'set_security'){ ?>
        <?php if (empty($security_set)): ?>
        <?= $this->element('../users/set_security') ?>
        <?php else:?>
         <?= $this->element('../users/set_security_check') ?>
        <?php endif; ?>
        <?php } ?>

The function which I have written in conntroller is,

function set_security_check()
{
   $user = $this->_authenticate_user();
   $id = $user['account_num'];
   $this->loadModel('UserProfile');
   $user_profile = $this->UserProfile->read(null, $id);
   $oldBirthdate = $user_profile['UserProfile']['birthday']; 
     if (!empty($this->data)) {
         $birthday = $this->data['UserProfile']['birthday'];
         if($oldBirthdate != $birthday)
         {
           $this->flashMessage(__('Your Birthday is Invalid. Please, try again.', true));

         }
         else
         {
          $this->flashMessage(__('Your Birthday Verified successfully', true), 'Sucmessage');
          $this->set('success', true);
         }

     }


}

When user click on security edit buttons I am sending a query string /profile?edit=set_security.

How to show the other form when correct date of birth is entered?

Upvotes: 0

Views: 81

Answers (1)

Arun Jain
Arun Jain

Reputation: 5464

You can simply show any other form using the following code in your controller where your conditions meets:

$this->render('/users/other_form');

If I am correct, then your code should looks like:

function set_security_check()
{
  $user = $this->_authenticate_user();
  $id = $user['account_num'];
  $this->loadModel('UserProfile');
  $user_profile = $this->UserProfile->read(null, $id);
  $oldBirthdate = $user_profile['UserProfile']['birthday']; 
  if (!empty($this->data)) {
     $birthday = $this->data['UserProfile']['birthday'];
     if($oldBirthdate != $birthday)
     {
       $this->flashMessage(__('Your Birthday is Invalid. Please, try again.', true));

     }
     else
     {
      $this->flashMessage(__('Your Birthday Verified successfully', true), 'Sucmessage');
      $this->set('success', true);
      $this->render('/controller_name/other_form');
     }
  }
}

Upvotes: 1

Related Questions