how do you handle form submissions |
[eluser]jvittetoe[/eluser]
in my current application, once a user logins in they are redirected to their dashboard, via the dashboard.php controller. currently residing at www.myproject.com/dashboard now from this page there is a link to modify settings. once clicked they are then routed to www.com/dashboard/settings - this function from within the dashboard controller loads a view file... Code: $template['mainContent'] = $this->load->view('dspSettings', $data, true); now from the dspSettings view file there is a form. im using the ci form helper. the form is as follows... Code: <?=form_open('dashboard/updateUserAccount'); ?> on submission, the form routes to the dashboard/updateUserAccount function: Code: function updateUserAccount(){ the current url is www.com/dashboard/updateUserAccount which brings up errors telling me 'Undefined property: password_new' because that field was submitted empty. how can i keep the field optional and still modify a record in the database without running into errors like this. im still new to the framework and developing in general. how is my structure. could i be doing these easier and faster? thanks.
[eluser]Michael Wales[/eluser]
Update your model method, placing the optional parameters at the end and defining default values. Something like this: Code: function updateUser($username, $password, $email, $new_password = '') { So, when you call that function - if you fail to define the 4th parameter it will default to ''
[eluser]jvittetoe[/eluser]
this issue arises when i submit the form and call the dashboard/updateUserAccount...when it gets tothe else statement, these lines are throwing errors. Code: $password_old = $this->validation->password_old; the errors are.. Message: Undefined property: password_old Message: Undefined property: password_new ...and so on for all 5. ive also updated my model function with your suggestion. but my script is failing before it even gets there.
[eluser]WolfgangA[/eluser]
[quote author="jvittetoe" date="1188811043"] ... $this->validation->password_old; ... Message: Undefined property: password_old [/quote] I guess your assumption is wrong that the validation object has such a property. It "only" has the rules assigned fro the fields it should check. See http://ellislab.com/codeigniter/user-gui...ation.html So why do you not take the values from your original array?
[eluser]jvittetoe[/eluser]
i guess im not reall sure how to take the values from the original array.
[eluser]Michael Wales[/eluser]
Try setting the fields' names - I think that will allow you to use $this->validation->var_name (as well as prettying up your error messages). Code: $field['password_old'] = 'old password';
[eluser]jvittetoe[/eluser]
Ok, i have a new idea on how to handle my logins / new registrations. upon coming to the site the default controller is welcome.php from here there is one form which submits a post array, containing an email address and a password, to the welcome/checkUser method is my welcome controller. this method checks to see if the submitted email address is already taken. if it is, redirect users to the welcome/doLogin method, if its not taken, redirect users to the welcome/doRegister method. and while inside welcome/doRegister, once the registration has returned from the model, i want to redirect users to the welcome/doLogin method to be automatically logged in. im having the hardest time getting things to work. Code: function checkUser(){ Code: function doLogin(){ Code: function doRegister(){ now my question is how can i pass my $data variable when using a redirect. because all of this is taking place in my welcome controller. so once someone logs in, they are taken to the dashboard controller. if i uncomment the redirect lines and using the load->view my url stays www.com/welcome/home instead of www.com/dashboard. |
Welcome Guest, Not a member yet? Register Sign In |