Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    james s's Avatar
    Senior Member

    Status
    Offline
    Join Date
    May 2009
    Posts
    126
    Downloads
    0
    Uploads
    0

    PHP, pause script until form is submitted?

    I was wondering if there was a way to request information from a form, and when the form is submitted continue the script (such as with JavaScript event handlers) I have a user logon script which, when an instance of the class 'User' is created, displays a form and uses the information to create the user in the database. However, what is happening is that the $_POST variables are being tested (i.e. if(isset(...)) ), and an error message is displayed before the user has inputted any information.

    Here is my code:
    function __construct() {
    $this->displayForm();
    $this->name = $_POST["setup_fullname"];

    if(count(str_split($_POST["setup_usr"], 1)) > 4 && usrIsFree($_POST["setup_usr"])) {
    $this->username = $_POST["setup_usr"];
    print($this->username);
    } else {
    echo '<script type="text/javascript">alert("Invalid Username! Username may be taken or is under the character limit.")</script>';
    unset($_POST['setup_sbmt']);
    $this->displayForm();
    }

    if(count(str_split($_POST["setup_pwd"], 1)) > 4) {
    $this->password = md5($_POST["setup_pwd"]) + saltify($this->username);
    } else {
    echo '<script type="text/javascript">alert("Invalid Password")</script>';
    unset($_POST['setup_sbmt']);
    $this->displayForm();
    }

    if(isset($_POST['kmli'])) { $this->keepSession = true; } else { $this->keepSession = false; }

    }
    }
    By the end of it I get 2 JScript messages saying ("invalid password/username") and the form is displayed 3 times.
    Thanks in advance
    - James

  2. #2
    Silent's Avatar
    Newbie - NLP

    Status
    Offline
    Join Date
    May 2011
    Posts
    8
    Downloads
    0
    Uploads
    0
    I don't think you fully understand how PHP works or what it's for.

    This code isn't running in your browser. It can't be "paused" while you're interacting with the page, because by the time you see the page it's already finished.

    A PHP script runs on the web server. It generates an HTML document that's then sent to the user's web browser. All the user sees is that generated HTML -- the PHP code is not sent to the user's browser. It's already done its job and finished by the time the user sees anything.

 

 

Quick Reply Quick Reply

Click here to log in


In what corner do we have Search box?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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