Jump to content

show form from function?


Stooney

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.