Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 4 of 4

This is a discussion on Branching to a new page based upon conditions in the Shared & Semi-Dedicated forum
I've been struggling with a problem and don't see a solution so I'll ask all you experts. I've been writing my form-containing scripts where I ...

  1. #1
    JPC Addict
    Join Date
    May 2002
    Location
    Northwest Florida
    Posts
    202

    Branching to a new page based upon conditions

    I've been struggling with a problem and don't see a solution so I'll ask all you experts.

    I've been writing my form-containing scripts where I call the same script repeatedly until all of the info entered is correct. It works something like this ...

    start pseudocode ---
    If user is logged on then
    if form is filled out then
    check for errors (missing data, etc)
    if ok then
    write info to database
    use hyperlink to move to the next page
    else
    allow user to correct errors
    else
    create form to fill out
    when user selects "Continue" start over at top of page
    else
    give error message
    use hyperlink to allow the user to log in
    --- end pseudocode

    I'd like to get rid of the hyperlinks and redirect or branch to a different page based upon the conditions. The revised script would look something like ...

    start pseudocode ---
    If user is logged on then
    if form is filled out then
    check for errors (missing data, etc)
    if ok then
    write info to database
    automatically send the user to the next page
    else
    allow user to correct errors
    else
    create form to fill out
    when user selects "Continue" start over at top of page
    else
    give error message
    automatically send the user to the login page
    --- end pseudocode

    Suggestions, anyone? I can't imagine that this is hard to do but I've never seen the code to do it.

    Jim
    Jim Winters
    Technology Lighthouse, Inc.
    Lighting the way for small business and nonprofit organizations.

  2. #2
    Jag Veteran
    Join Date
    Sep 2002
    Posts
    650
    To make it short, use header():
    Code:
    header("Location: $url");
    http://us2.php.net/header

  3. #3
    JPC Addict
    Join Date
    May 2002
    Location
    Northwest Florida
    Posts
    202
    I think I can make that work. I'd thought of trying to use a redirect through the headers but (1) didn't realize I could from the middle of my code and (2) my reference book doesn't list anything about redirection in the index.

    The way I'm set up here, when the "Continue" button is clicked, the page is reloaded from scratch and the format is set based on the content of variables before the form is submitted. All I'll have to do is set an option variable and go from there when the page reloads.

    Thanks a bunch!

    Jim
    Jim Winters
    Technology Lighthouse, Inc.
    Lighting the way for small business and nonprofit organizations.

  4. #4
    Jag Veteran
    Join Date
    Sep 2002
    Posts
    650
    Quote Originally Posted by techlighthouse
    I'd thought of trying to use a redirect through the headers but (1) didn't realize I could from the middle of my code
    As long as your code doesn't generate any output before calling header(), you can call it anywhere. Here is what official PHP manual says about it:
    Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

    Quote Originally Posted by techlighthouse
    The way I'm set up here, when the "Continue" button is clicked, the page is reloaded from scratch and the format is set based on the content of variables before the form is submitted. All I'll have to do is set an option variable and go from there when the page reloads.
    You can create url in the form http://domainname/script.php?PARAM1=VALUE1, which will basically "fake" form submission. You might need to adjust your script, though, if it currently assumes POST parameters.

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
  •