Results 1 to 6 of 6

Thread: dynamic form in php session

  1. #1
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default dynamic form in php session

    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 ^^;
    Last edited by sfchun; 11-10-2008 at 10:07 AM.

  2. #2
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    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' ^^;

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    What do you mean by disconnection? Can you show us what error code comes up?
    And let's see your jQuery code.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  4. The Following User Says Thank You to tech_support For This Useful Post:

    sfchun (11-11-2008)

  5. #4
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    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
    HTML Code:
    <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
    Code:
    $(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 Code:
    <?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.';
                            }
                    }
            }
    ?>

  6. #5
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    so no one have the magic solution ??

  7. #6
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    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

    sadly we cannot thanks ourself ...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •