Log in

View Full Version : dynamic form in php session



sfchun
11-10-2008, 10:01 AM
Hello everyone i'm back with a new challenge =P

I'm looking for a code which allow a user to change his password under a php sessions dynamicaly (so i don't want new page, or any page refresh).
info : password is stored in MySQL db , and in variable : $_SESSION[passwd]

the plus would be that this code can be adapted to any other form =P

until now i was using jQuery to manage this kind of form , but i experienced an issue (which i couldn't solve) under php session, it cause disconnection when i submit...

thanks a lot for any help ^^;

sfchun
11-11-2008, 05:50 AM
no one can help ?? ^^;
maybe my request was not clear ...

the main purpose is to catch an input field content with javascript and pass it to php without using the classic 'submit' ^^;

tech_support
11-11-2008, 06:28 AM
What do you mean by disconnection? Can you show us what error code comes up?
And let's see your jQuery code.

sfchun
11-11-2008, 06:58 AM
i have no error code sadly (or i don't know how to get it)...
if i had maybe i could have solved my problem ...
about the jQuery code , i'm using exactly the same model as the one provided in the example demo.

anyway here is my code :
index.php


<head>
...
<script language="php">@include ('traitement_changePassWord.php');</script>
<script src="js/jquery.pack.js" type="text/javascript"></script>
<script src="js/runonload.js" type="text/javascript"></script>
<script src="js/jQ_changePass.js" type="text/javascript"></script>
...
</head>
...
<div id="changePassContainer">
<fieldset class="Field"><legend>Changement de password</legend>
<form method="post" action="" >
<div class="ctrlHolder">
<label for="oldpasswd" id="oldpasswd_label">Pass. actuel&nbsp;&nbsp;&nbsp;&nbsp;</label>
<input type="password" name="oldpasswd" id="oldpasswd" size="12" maxlength="12" class="inputbox" title="oldpasswd" />
<label class="error" for="oldpasswd" id="oldpasswd_error">Entrez votre pass actuel</label>
</div>
<div class="ctrlHolder">
<label for="futurpasswd" id="futurpasswd_label">Pass. desire&nbsp;&nbsp;&nbsp;&nbsp;</label>
<input type="password" name="futurpasswd" id="futurpasswd" size="12" maxlength="12" class="inputbox" title="futurpasswd" />
<label class="error" for="futurpasswd" id="futurpasswd_error">Entrez le password desire</label>
</div>
<div class="ctrlHolder">
<label for="fpasswdconf" id="fpasswdconf_label">re Password&nbsp;&nbsp;&nbsp;</label>
<input type="password" name="fpasswdconf" id="fpasswdconf" size="12" maxlength="12" class="inputbox" title="fpasswdconf" />
<label class="error" for="fpasswdconf" id="fpasswdconf_error">Confirmez votre password desire</label>
</div><br />
<div class="buttonHolder" style="text-align:center">
<button type="submit" class="submitButton" id="submit_changepwd" name="ChangePassWordForm" value="Ok">- Go -</button>
</div>
</form>
</fieldset>
</div>
...


jQ_changePass.js


$(function() {
$('.error').hide();
$('input.text-input').css({backgroundColor:"#FFFFFF"});
$('input.text-input').focus(function(){
$(this).css({backgroundColor:"#FFDDAA"});
});
$('input.text-input').blur(function(){
$(this).css({backgroundColor:"#FFFFFF"});
});

$(".button").click(function() {
// validate and process form
// first hide any error messages
$('.error').hide();

var ancienpasswd = $("input#oldpasswd").val();
if (ancienpasswd == "") {
$("label#oldpasswd_error").show();
$("input#oldpasswd").focus();
return false;
}
var ftrpasswd = $("input#futurpasswd").val();
if (ftrpasswd == "") {
$("label#futurpasswd_error").show();
$("input#futurpasswd").focus();
return false;
}
var ftrpasswdconf = $("input#fpasswdconf").val();
if (ftrpasswdconf == "") {
$("label#fpasswdconf_error").show();
$("input#fpasswdconf").focus();
return false;
}

var dataString = 'oldpasswd='+ oldpasswd + '&futurpasswd=' + futurpasswd + '&fpasswdconf=' + fpasswdconf;
//alert (dataString);return false;

$.ajax({
type: "POST",
url: "bin/process.php",
data: dataString,
success: function() {
$('#contact_form').html("<div id='message'></div>");
$('#message').html("<h2>Form Submitted!</h2>")
.append("<p>Thanks.</p>")
.hide()
.fadeIn(1500, function() {
$('#message').append("<img id='checkmark' src='images/check.png' />");
});
}
});
return false;
});
});
runOnLoad(function(){
$("input#oldpasswd").select().focus();
});


traitement_changePassWord.php


<?php
session_start();
function changeP()
{
echo '<br />CurrentUser :'.$_SESSION['CurrentUser'];
echo '<br />CurrentUserPass :'.$_SESSION['CurrentPasswd'];
echo '<br />futur password :'.$_POST['futurpasswd'];
echo '<br />futur password conf :'.$_POST['fpasswdconf'];
$oldpasswd=trim($_POST['oldpasswd']);
$oldpasswd=md5(trim($oldpasswd));
$oldpasswdconf=($_SESSION['CurrentPasswd']);
$chgPassUser=($_SESSION['CurrentUser']);
$futurpasswd=trim($_POST['futurpasswd']);
$fpasswdconf=trim($_POST['fpasswdconf']);
if ($oldpasswd==$oldpasswdconf && $futurpasswd==$fpasswdconf) {
$futurpasswd=md5(trim($futurpasswd));
$fpasswdconf=md5(trim($fpasswdconf));
$con = mysql_connect("dbserv","dbadmin","dbadminpass");
if ($con) {
$chgPassQ="UPDATE `mainTable`.`T_users` SET `user_password` = '$futurpasswd' WHERE CONVERT( `T_users`.`user_name` USING utf8 ) = '$chgPassUser' LIMIT 1 ;";
if ($chgPassQ) {
$_SESSION['CurrentPasswd']=$futurpasswd;
echo 'mise a jour effectuee';
echo '<script type="text/javascript">';
echo 'ajax_loadContent(\'TopRightSessionStatus\',\'traitement_changePassWord_status.php\');';
echo '</script>';
} else {
echo 'Update Error.';
}
} else {
echo 'Connection Error.';
}
mysql_close($con);
} else {
if ($firstpasschgpasswd) {
echo '<br />(re)Enter your password.';
} else {
echo '<br />Error when entering password.';
}
}
}
?>

sfchun
11-11-2008, 03:11 PM
so no one have the magic solution ?? :(

sfchun
11-12-2008, 06:24 AM
Well i finally found a way to solve my problem ...

i changed the jquery plugins, and i have no more issue ...

for those who are interested the plugin is here :
jQuery Form Plugin (http://www.malsup.com/jquery/form/#getting-started)

sadly we cannot thanks ourself ... :rolleyes: