Jump to content

Need help with php code for member form


Mboxer511

Recommended Posts

I'm working on a project for a website in wordpress.  The original developor has dissapeared and I'm stuck trying to fix his code.  The client wants his members to be able to edit their password and I can't figure out what php code to put into the wordpress template to make it work.  All I need to do is make a field that lets the user change their password.

 

The website is www.papausa.com

 

This is the page I'm working on: http://www.papausa.com/edit-user/

 

A test account I made is:

 

User: as

Password: as

 

Below is the code I'm working with:

<?php
ob_start();
/*
Template Name: Edit User
*/

if (!session_id()) {
    session_start();
}
get_header(); ?>
 <?php
$memberedit = $wpdb->get_row("SELECT * FROM blog_all_members WHERE user = '".$_SESSION['user_log_true']."'");
global $wpdb;
	//include ABSPATH . WPINC . '/class-phpass.php';
 if(isset($_REQUEST['sendinq'])){
    $to = array(
	"Admin <info@papausa.com>",
	"$memberedit->fname <$memberedit->email>"	
	);
	$message = "<html>
					<head>
					<title>Previous User Profile</title>
					</head>
					<body>
					<p>Previous information of user profile</p>
					<table border=1>
					<tr><th>User Name</th><td>".$memberedit->user."</td></tr>
					<tr><th>First Name</th><td>".$memberedit->fname."</td></tr>
					<tr><th>Last Name</th><td>".$memberedit->lname."</td></tr>
					<tr><th>City</th><td>".$memberedit->city."</td></tr>
					<tr><th>State</th><td>".$memberedit->state."</td></tr>
					<tr><th>Phone No.</th><td>".$memberedit->phone."</td></tr>
					<tr><th>Email</th><td>".$memberedit->email."</td></tr>
					<tr><th>Address</th><td>".$memberedit->address."</td></tr>
					<tr><th>Profession</th><td>".$memberedit->profession."</td></tr>
					</table>
					<br><br>
					<p>Update information of user profile</p>
					<table border=1>
					<tr><th>User Name</th><td>".$_REQUEST['userid']."</td></tr>
					<tr><th>First Name</th><td>".$_REQUEST['fname']."</td></tr>
					<tr><th>Last Name</th><td>".$_REQUEST['lname']."</td></tr>
					<tr><th>City</th><td>".$_REQUEST['city']."</td></tr>
					<tr><th>State</th><td>".$_REQUEST['state']."</td></tr>
					<tr><th>Phone No.</th><td>".$_REQUEST['phone']."</td></tr>
					<tr><th>Email</th><td>".$_REQUEST['email']."</td></tr>
					<tr><th>Address</th><td>".$_REQUEST['address']."</td></tr>
					<tr><th>Profession</th><td>".$_REQUEST['profession']."</td></tr>
					</table>
					</body>
					</html>
					";
	$headers = 'From: '.$memberedit->fname.'   <'.$memberedit->email.'>' . "\r\n";
	$headers .= 'Content-type: text/html; charset=UTF-8';
	$subject = "User edit profile";
	$status = wp_mail($to, $subject, $message ,$headers); 
	$wpdb->query("update blog_all_members set `user` = '".$_REQUEST['userid']."',
	                                          `fname` = '".$_REQUEST['fname']."',
											  `lname` = '".$_REQUEST['lname']."',
											  `city` = '".$_REQUEST['city']."',
											  `state` = '".$_REQUEST['state']."',
											  `phone` = '".$_REQUEST['phone']."',
											  `email` = '".$_REQUEST['email']."',
											  `address` = '".$_REQUEST['address']."',
											  `profession` = '".$_REQUEST['profession']."'
											  where user ='".$_SESSION['user_log_true']."'");
											  
	$wpdb->query("update blog_users set `user_login` = '".$_REQUEST['userid']."',
	                                          `user_nicename` = '".$_REQUEST['fname']."',
										      `user_email` ='".$_REQUEST['email']."',
											  `display_name` ='".$_REQUEST['fname']."'
										       where `user_login` ='".$_SESSION['user_log_true']."'");
       echo '<div id="box-2" class="main">
				<div class="main-inner">
					<div class="main-inner-1">
					
						<div class="box-1-inner custom-template">
						
									<div class="custom-template-heading">
										User Profile
									</div>
								<?php breadcrumb_trail(); ?>
								<div class="template-gallery-videos">
														
								
								<!--content body starts -->
<div class ="membership-template" style="width:66%;">
 

	 <div class="alert-box success"><span>success: </span>Record has been successfully update</div>
	 <div style="height:250px"></div>
									</div>
									
									
								<!--content body ends -->
								
								</div>
									<div class="clear"></div>					
								</div>
									
						<div class="clear"></div>	
					</div>
					<div class="clear"></div>
				</div>
				<div class="clear"></div>
			</div>';											   
										
     echo '<script type="text/javascript">
	$(function() {
    		$("#box-2").delay(2000000).fadeOut(0);
	});
</script>';

get_footer(); 
	$_SESSION['user_log_true'] = $_REQUEST['userid'];
	echo "<script>window.location.href = 'http://www.papausa.com/edit-user/';</script>";
}	
		
?>
<script>
function fna()
{
 var fn1 = document.getElementById('fname').value;
 if(fn1 == '')
 {
    alert('Please enter your name ');
    document.getElementById('fname').style.borderColor="#FF0000";
	return false;
 }
  else{
   document.getElementById('fname').style.borderColor="";
   return true;
 }
}
function add1()
{
 var ad1 = document.getElementById('address').value;
 if(ad1 == '')
 {
    alert('Please enter address');
    document.getElementById('address').style.borderColor="#FF0000";
	return false;
 }
  else{
   document.getElementById('address').style.borderColor="";
   return true;
 }
}
function cty1()
{
 var st1 = document.getElementById('city').value;
 if(st1 == '')
 {
    alert('Please enter your city');
    document.getElementById('city').style.borderColor="#FF0000";
	return false;
 }
  else{
   document.getElementById('city').style.borderColor="";
   return true;
 }
}
function stat1()
{
 var st1 = document.getElementById('state').value;
 if(st1 == '')
 {
    alert('Please enter your state');
    document.getElementById('state').style.borderColor="#FF0000";
	return false;
 }
  else{
   document.getElementById('state').style.borderColor="";
   return true;
 }
}
function phno1()
{
  var ph = document.getElementById('phone').value;
  if(isNaN(ph))
  {
    alert('Please Enter valid phone number');
    document.getElementById('phone').style.borderColor="#FF0000";
	return false;
  }
  else if(ph == ''){
    alert('Please Enter valid phone number');
    document.getElementById('phone').style.borderColor="#FF0000";
	return false;
  }
  else{
   document.getElementById('phone').style.borderColor="";
   return true;
  }
}
function profs()
{
 var prof = document.getElementById('profession').value;
 if(prof == '')
 {
    alert('Please Enter Profession ');
    document.getElementById('profession').style.borderColor="#FF0000";
	return false;
 }
  else{
   document.getElementById('profession').style.borderColor="";
   return true;
 }
}
function ValidateEmail(x) {
    
    var atpos = x.indexOf("@");
    var dotpos = x.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {
	    alert('Please Enter valid email Id');
        document.getElementById('email').style.borderColor="#FF0000";
		
        return false;
    }
	else
	 {
	   document.getElementById('email').style.borderColor="";
	   return true;
	 }
} 

</script>
 
<!-- Membership template start -->

<div id="box-2" class="main">
				<div class="main-inner">
					<div class="main-inner-1">
					
						<div class="box-1-inner custom-template">
						
									<div class="custom-template-heading">
										User Profile
									</div>
								<?php breadcrumb_trail(); ?>
								<div class="template-gallery-videos">
														
								
								<!--content body starts -->
<div class ="membership-template" style="width:66%;">
 
<form id="edituser" name="edituser" action="" method="post" autocomplete="off">
	 <table width="100%" align="center">
	  <tr><td colspan="2"><label style="color:gr"></label></td></tr>
	  <tr><td><label class="">User Id</label></td><td><input type="text" name="userid" id="userid"  width="200" value="<?php echo $memberedit->user;?>"></td></tr>
	  <tr><td><label class="">First Name</label></td><td><input type="text" name="fname" id="fname"  width="200" value="<?php echo $memberedit->fname;?>" onblur="fna();"></td></tr>
	  <tr><td><label class="">Last Name</label></td><td><input type="text" name="lname" id="lname"  width="200" value="<?php echo $memberedit->lname;?>" ></td></tr>
	  <tr><td><label class="">Address</label></td><td><input type="text" name="address" id="address"  width="200" value="<?php echo $memberedit->address;?>" onblur="add1();"></td></tr>
	  <tr><td><label class="">City</label></td><td><input type="text" name="city" id="city"  width="200" value="<?php echo $memberedit->city;?>" onblur="cty1();"></td></tr>
	  <tr><td><label class="">State</label></td><td><input type="text" name="state" id="state"  width="200" value="<?php echo $memberedit->state;?>" onblur="stat1();"></td></tr>
	  <tr><td><label class="">Phone No.</label></td><td><input type="text" name="phone" id="phone" maxlength="14"  width="200" value="<?php echo $memberedit->phone;?>" onblur="phno1();"></td></tr>
	  <tr><td><label class="">Email</label></td><td><input type="email" name="email" id="email"  width="200" value="<?php echo $memberedit->email;?>" onblur="ValidateEmail(this.value)"></td></tr>
	  <tr><td><label class="">Profession</label></td><td><input type="text" name="profession"  id="profession" width="200" value="<?php echo $memberedit->profession;?>" onblur="profs();"></td></tr>
	  <tr><td>  </td><td  align="left" class="mm"><input type="submit"  name="sendinq" id="registration-submit" value="Submit"></td></tr>
	  </table>
	  </form>
	 
									</div>
									
									
								<!--content body ends -->
								
								</div>
									<div class="clear"></div>					
								</div>
									
						<div class="clear"></div>	
					</div>
					<div class="clear"></div>
				</div>
				<div class="clear"></div>
			</div>
			<script> 
		 $(document).ready(function(){ 
			$(".p1").click(function(){
				var amt  = $(this).attr('lang');  
				$("#mfee").val(amt);
			});
			$("#ccode").blur(function(){
				var captch = '<?=$randomString?>';
				var entered = $("#ccode").val();
				if(captch!=entered){ alert('Please enter a valid captcha code!');
				return false;
				}
			});
		 });
   </script>
<!--Membership template end-->
<?php get_footer(); ?>

I appreciate any help, I've been stuck on this for days.

 

Thanks.

Link to comment
Share on other sites

Sounds like you are in over your head. As the Admin told you, you need to add a password field to the form.

<tr><td><label class="">User Password</label></td><td><input type="password" name="userpass" id="userpass"  width="200" value="<?php echo $memberedit->password;?>" onblur="checkPass(this.value)"></td></tr>

You should actually have two fields...one for the password and another to confirm that they typed the password in correctly.

You are then going to need to write a javascript function checkPass() to validate the password for acceptable length, chars etc.

You will need to fill in the password form value from the database just as the code does with the other field values. You will need to add additional sql to update the database with the password field value. It looks like the admin gets sent an email after an update, so depending if he wants to know the password used, you will have to add this to the email form as well. 

Edited by hansford
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.