php - Laravel : Undefined variable in a POST function -
i'm trying send post request containing variable, says variable undefined, here code .. first function view containing form. second function callback of post request of form. echo'ed out variable in view , succeeded error shows in second function ..
public function reset($code) { return view::make('recover', array('code' => $code, 'passwordreset' => 1,'nologinform' => 1)); } public function postresetpassword() { $validator = validator::make(input::all(), array('temppassword' => 'required','newpassword' => 'required|min:6','cnewpassword' =>'required|same:newpassword')); if($validator->fails()) return view::make('recover', array('passwordreset' => 1,'nologinform' => 1))->witherrors($validator); else { // error shows in following line in code variable comparison $user = user::where('temp_password','!=','')->where('code','=',$code)->first(); if($user) { $user->password = hash::make(input::get('newpassword')); $user->temp_password = ''; if($user->save()) return redirect::route('login')->with('msg','password changed correctly, use new password login.'); } else { return view::make('recover', array('passwordreset' => 1,'nologinform' => 1,'error' =>'invalid temporary password, please make sure typed password sent correctly.')); } } }
here error log
[2014-11-13 09:50:15] production.error: exception 'errorexception' message 'undefined variable: code' in c:\wamp\www\buddyly\app\controllers\usercontroller.php:155 stack trace: #0 c:\wamp\www\buddyly\app\controllers\usercontroller.php(155): illuminate\exception\handler->handleerror(8, 'undefined varia...', 'c:\wamp\www\bud...', 155, array) #1 [internal function]: usercontroller->postresetpassword() #2 c:\wamp\www\buddyly\vendor\laravel\framework\src\illuminate\routing\controller.php(231): call_user_func_array(array, array) #3 c:\wamp\www\buddyly\bootstrap\compiled.php(5776): illuminate\routing\controller->callaction('postresetpasswo...', array) #4 c:\wamp\www\buddyly\bootstrap\compiled.php(5764): illuminate\routing\controllerdispatcher->call(object(usercontroller), object(illuminate\routing\route), 'postresetpasswo...') #5 c:\wamp\www\buddyly\bootstrap\compiled.php(4971): illuminate\routing\controllerdispatcher->dispatch(object(illuminate\routing\route), object(illuminate\http\request), 'usercontroller', 'postresetpasswo...') #6 [internal function]: illuminate\routing\router->illuminate\routing\{closure}() #7 c:\wamp\www\buddyly\bootstrap\compiled.php(5329): call_user_func_array(object(closure), array) #8 c:\wamp\www\buddyly\bootstrap\compiled.php(4996): illuminate\routing\route->run(object(illuminate\http\request)) #9 c:\wamp\www\buddyly\bootstrap\compiled.php(4984): illuminate\routing\router->dispatchtoroute(object(illuminate\http\request)) #10 c:\wamp\www\buddyly\bootstrap\compiled.php(715): illuminate\routing\router->dispatch(object(illuminate\http\request)) #11 c:\wamp\www\buddyly\bootstrap\compiled.php(696): illuminate\foundation\application->dispatch(object(illuminate\http\request)) #12 c:\wamp\www\buddyly\bootstrap\compiled.php(7744): illuminate\foundation\application->handle(object(illuminate\http\request), 1, true) #13 c:\wamp\www\buddyly\bootstrap\compiled.php(8351): illuminate\session\middleware->handle(object(illuminate\http\request), 1, true) #14 c:\wamp\www\buddyly\bootstrap\compiled.php(8298): illuminate\cookie\queue->handle(object(illuminate\http\request), 1, true) #15 c:\wamp\www\buddyly\bootstrap\compiled.php(10957): illuminate\cookie\guard->handle(object(illuminate\http\request), 1, true) #16 c:\wamp\www\buddyly\bootstrap\compiled.php(657): stack\stackedhttpkernel->handle(object(illuminate\http\request)) #17 c:\wamp\www\buddyly\public\index.php(49): illuminate\foundation\application->run() #18 c:\wamp\www\buddyly\server.php(19): require_once('c:\wamp\www\bud...') #19 {main} [] []
since $code
isn't defined in function or handed parameter, doesn't exist. hence 'undefined variable' error getting.
if send $code
view, , want $code
when view posts form, add value of $code
form-element , read input::get()
.
view:
<!-- inside form --> <input type="hidden" name="code" value="{{ $code }}" />
model/controller:
$code = input::get('code');
alternatively, create session containing $code
, read value once method postresetpassword()
called.
Comments
Post a Comment