php - CakePHP 2.2.3: How to pass variables from one form to another -
i'm pretty new cakephp , i've tried searching question related i'm trying think hasn't been asked here is:
i'm developing student forms site school. school has own special log in system want users able use instead of site having own separate log in system. in user
view i've got login.ctp
file calls login()
usercontroller
, login function connects school's log-in system , validates user's credentials (username , password stored in $user_name
, $user_pass
).
i have log-in function check if first time user has logged in checking user
model username used log in school's system. if username doesn't exist form redirects register.ctp
(still user
view) user required fill in first name, last name , other info gets stored in user
model. need register form store username , password used log school's system. once user registers in should redirect student/forms
view , use studentcontroller
.
how access $user_name
, $user_pass
in new form? don't want users able input information (it should placed in read-only input box).
should make function register()
in usercontroller
creates new user
add database?
sorry if has been covered before!
here's pseudo-example of code:
usercontroller: login(){ $user_name = $_post['username']; $user_pass = $_post['pwd']; $data = array('username' => $user_name, 'pwd' => $user_pass); if(validate($user_name, $user_pass)){ if(!exists($user_name)){ $this->redirect(array('action' => 'register', $data));//passing log in data register function , view } else {$this->redirect(array('controller' => 'forms', 'action' => 'students'));} } else {//display invalid credential message} } register(){ appcontroller::loadmodels(array('user')); $this->set($data);//setting data passed login() register.ctp view can use //grab post data registration form }
i error saying $data undefined variable though in register function, though i'm passing in redirect. how do properly?
login view:
<div class="main-content"> <div class="hero-unit span5 centerit"> <?php echo $this->session->flash(); ?> <?php echo $this->session->flash('auth'); ?> <?php echo $this->form->create('user', array('action'=>'login')); ?> <fieldset id="login"> <h2> user login</h2> <p> please enter [sic] credentials </p> <p> <?php echo $this->form->input('username', array('label' => 'username: ', 'type' => 'text', 'value' =>'')); ?> </p> <p> <?php echo $this->form->input('password', array('label' => 'password: ', 'type' => 'password')); ?> </p> <p> <?php echo $this->form->input('remember', array('type'=>'checkbox', 'label'=>'remember me')); ?> </p> </fieldset> <div class="submit pull-right"> <input type="submit" value="login" class="btn btn-primary"> </div> </div> </div>
register view:
<div class="main-content"> <div class="hero-unit span5 centerit"> <?php echo $this->form->create('user', array('action'=>'register')); ?> <fieldset> <legend><?php echo __('register new user'); ?></legend> <p class="subhead"> note: information can't changed later, please check info correct.</p> <?php echo $this->form->input('username', array( //'value' => $_post['data']['username'], 'readonly' => 'readonly')); echo $this->form->input('password', array( //'value' => $_post['data']['pwd'], 'readonly' => 'readonly')); echo $this->form->input('fname', array( 'label' => 'first name')); echo $this->form->input('lname', array( 'label' => 'last name')); echo $this->form->input('role', array( 'options' => array('student' => 'student'))); ?> </fieldset> <div class="submit pull-right"> <input type="submit" value="submit" class="btn btn-primary"> </div> </div> </div>
work on login method way writing method not practice. follow article login
this not practice end form submit button. after
<?php echo $this->form->end(__('submit')); ?> //login method public function login() { $user = $this->user->findbyusername($this->request->data['user']['username']); if(empty($user)){ $this->request->data = $this->user->read(null, $user['user'][''id]); $this->redirect method... } }
Comments
Post a Comment