Stooney Posted February 16, 2008 Share Posted February 16, 2008 Need some opinions. This is a function from a class I'm working (this has nothing to do with the actual class though). In my change_password function should I show the form from it? Or should forms be shown from outside of a class/function? Here's what I mean (The question is marked near the bottom). It has been suggested that I include the form from a separate file (reset_pw_form.html). I'm just not sure where a form belongs (inside the function, wherever i need it in the script, or included from an external file). Note: ignore minor errors, I haven't tested it yet. And this is similar to my post in the OOP board, but this board seemed more appropriate. <?php public function change_password(){ if(isset($_POST['old_password'])){ global $dbc; global $user; //Form was submitted, sanitaze user input $data=$dbc->sanitize(array($_POST['old_password'], $_POST['new_password1'], $_POST['new_password2'])); //Check if old password matches $check=$dbc-query("SELECT id FROM ".$CONFIG['db_prefix']."_users WHERE id='$user->userid' AND password=PASSWORD('$data[0]')"); if($dbc->numrows($check)==1){ //Old password was a match, validate and set the new password. if(strlen($data[1])>5 && $data[1]==$data[2]){ //Password is greater than 6 characters and both match $update=$dbc->query("UPDATE ".$CONFIG['db_prefix']."_users SET password=PASSWORD('$data[1]') WHERE id='$user->userid'"); if($dbc->affected()==1){ //Password was updated successfully return true; } } else{ //New password wasn't valid } } else{ //Old password didn't match } } else{ //Form has not been submitted //*****************Should I show the form here? Or should that be done outside of the class? } } ?> Link to comment https://forums.phpfreaks.com/topic/91445-show-form-from-function/ Share on other sites More sharing options...
Stooney Posted February 17, 2008 Author Share Posted February 17, 2008 no opinions eh? Link to comment https://forums.phpfreaks.com/topic/91445-show-form-from-function/#findComment-468638 Share on other sites More sharing options...
spfoonnewb Posted February 17, 2008 Share Posted February 17, 2008 I would think it's more of a personal preference. I prefer to keep HTML outside of PHP whenever possible. Using a type of template system/class is generally cleaner in my opinion. Link to comment https://forums.phpfreaks.com/topic/91445-show-form-from-function/#findComment-468641 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.