www.webdeveloper.com
+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 15 of 42
  1. #1
    Join Date
    Jul 2006
    Posts
    249

    'Submit Button' Function?

    Once I validate the user info on a form, how do I send it on to another page?

    For example:

    user inputs information and clicks submit.
    the submit button sends the data back to the page again, using PHP_SELF.
    the script processes the data, and determines that it's accurate
    the script inserts it into the mySQL database

    once this happens, i need it to also send the values of the posted variables to another page, and take the user there.

    Is there such a thing as a hidden 'clickless' submit button, or a function/command that does that?

    for example:

    if (data_is_good)
    {
    submit_data_to (nextpage.php);
    }

    Hope that makes sense...


    Thanks,

    Nick

  2. #2
    Join Date
    Dec 2006
    Location
    Escazú (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Is the other page a form?

  3. #3
    Join Date
    Jul 2006
    Posts
    249
    It will be, yes.

    The idea being that page one takes requested user name, desired password, and email address, checks the input for errors, and then does one of the following:

    If the Email address already exists in the database, it goes to a 'forgot password page' (and hopefully fills in the email fild for them, so they only have to click 'submit password reset request')

    If all the data checks out, it goes to another form that greets them by thier new username, and asks for real name / phone number / address / etc.
    Last edited by lightnb; 02-25-2007 at 06:18 AM.

  4. #4
    Join Date
    Dec 2006
    Location
    Escazú (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    If the data to be sent to the next page is less than 2KB, you can pass it as GET variables in the URL.

    You have other options (session variables) but this is likely to be the easiest.

  5. #5
    Join Date
    Jul 2006
    Posts
    249
    What is the code that tells the browser to 'go' to the next page, without the user clicking a button or link?

  6. #6
    Join Date
    Dec 2006
    Location
    Escazú (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    PHP Code:
    header("Location: http://www.domain.com/nextpage.php"); 

  7. #7
    Join Date
    Dec 2006
    Location
    Escazú (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    PHP Code:
    header("Location: http://www.domain.com/nextpage.php?var1=abc&var2=123&var3=a1b2c3"); 

  8. #8
    Join Date
    Jul 2006
    Posts
    249
    And that goes inside the if statement at the point when I want it to advance?


    Such as:

    if (empty($error))
    {
    header("Location: /nextpage.php");
    }

  9. #9
    Join Date
    Dec 2006
    Location
    Escazú (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Yes:
    PHP Code:
    if (empty($error)) {
      
    header("Location: http://www.domain.com/nextpage.php");

    Use the domain part. It's technically required. An option is to use:
    PHP Code:
    if (empty($error)) {
      
    header("Location: http://" $_SERVER['HTTP_HOST'] . "/nextpage.php");

    Of course, today most browsers will work without the Host part, but if that ever changes, your script will break and you'll wonder why...

  10. #10
    Join Date
    Jul 2006
    Posts
    249
    That's Awesome. Thank you very much

  11. #11
    Join Date
    Jul 2006
    Posts
    249
    I'm using:

    Code:
    header("Location: http://" . $_SERVER['HTTP_HOST'] . "/register_dup_email.php");
    and getting
    Warning: Cannot modify header information - headers already sent by (output started at /home/rahl/public_html/RVM/registration/register1.1.php:2) in /home/rahl/public_html/RVM/include/functions.php on line 82

  12. #12
    Join Date
    Dec 2006
    Location
    Escazú (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    That happens when you are already displaying something on the page - which doesn't make sense if you're going to redirect to another page.

    You probably have to restructure your script so that a redirect happens first - if the conditions are met - and information is only output if the conditions for a redirect do not exist, i.e. failed validation.

  13. #13
    Join Date
    Jul 2006
    Posts
    249
    I can get it to work if it's on line two before any other code, but other than that I get the "headers already sent" error.

    It doesn't do much good If I can't run my function first, or make the page change conditional.

    Is there another way of doing this that's more flexible as to where it can be placed in the script?

    Thanks again,

    Nick

  14. #14
    Join Date
    Dec 2006
    Location
    Escazú (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Post the script and we'll find a logical spot for it.

    Otherwise, you can do output bufffering until you decide whether to redirect or not - see the manual for ob_start(), ob_end_flush() and ob_end_clean().

  15. #15
    Join Date
    Jul 2006
    Posts
    249
    This is 'register1.1.php, the page that actually loads in the browser:
    PHP Code:
    <?PHP

    $location_ID 
    ="RVM Registration"// Set the location variable 

    // Include Database connection information 

    Require('../include/SQL_connect.php');

    // Include the shared registration functions

    Require('../include/functions.php');

    // Include the registration forms functions page

    Require('../registration/registration_forms.php');


    // Check to see if the form has been submited


    if (isset($HTTP_POST_VARS["submit"])) //if the form has been submited, do the following
        
    {
        
        
    $email_address $HTTP_POST_VARS["email_address"];
        
    $user_name $HTTP_POST_VARS["user_name"];
        
    $password1 $HTTP_POST_VARS["password1"];
        
    $password2 $HTTP_POST_VARS["password2"];    
        
        
    $ret_error form_validator($user_name$password1$password2$email_address);
        
        
    registration_form_1();
            
        }else 
    //(if the form has not be submited)
        
    {
        
    registration_form_1(); //display the form
        
    }
        
    ?>
    </body>
    This is the function that checks data integrity from 'functions.php':

    PHP Code:
    function form_validator ($user_name$password1$password2$email_address)
        {

        
    $next_condition 1;    
        
        
    //remove HTML tags and other special charecters, using the "cleanup_input" function
        
        
    $user_name cleanup_input($user_name);
        
    $password1 cleanup_input($password1);
        
    $password2 cleanup_input($password2);
        
    $email_address cleanup_input($email_address);
        
        
    //create an empty error variable
        
        
    $error "";
        
        
    //verify that a user name has been choosen
        
        
    if (empty($user_name))
            {
            
    $error .= "<li>Please choose a username</li>"
            }
            
        
    //verify that passwords have been entered, and that they match
            
        
    if (empty($password1))
            {
            
    $error .= "<li>Please enter a password in both fields</li>";
            }
            elseif (empty(
    $password2))
            {
            
    $error .= "<li>Please confirm your password</li>";
            }
            elseif (
    $password2 != $password1)
            {
            
    $error .= "<li>Your passwords don't match, please try again</li>";
            }    
            
                    
        
    // verify that the email address is in a valid format
        
        
    if (empty($email_address))
            {
            
    $error .= "<Li>Please provide an email address</li>";
            }
            elseif(!
    eregi("^[A-Za-z0-9\_-]+@[A-Za-z0-9\_-]+.[A-Za-z0-9\_-]+.*"$email_address))
            {
            
    $error .= "<li>$email_address doesn't appear to be a valid email address</li>";
            }
            else
            {  
    //if the email format is OK, check to see if it's already in the database.
            
            
    $query "SELECT * FROM Users WHERE email = '$email_address'";
            
    $result safe_query($query);
            if (
    mysql_num_rows($result) >0)
                {
                
    $next_condition 2// email address already exists in database
                
    }
            }
            
        if(empty(
    $error) && $next_condition == 1)
            {
            
    //$query = "INSERT INTO Users "
            //." (handle, password, email) VALUES "
            //."('$user_name', '$password1', '$email_address')";
            
            //safe_query($query);
            
    echo "Code here to foward user to 2nd registration page, and pass on the variable '$user_name'.";

              }
            elseif(
    $next_condition == 2)
            {
            echo 
    "code goes here to direct user to duplicate email address page";
            }
            elseif(
    $next_condition == 3)
            {
            echo 
    "code goes here to direct user to 'choose another username page'";
            }
            else
            {
            
    $error "<ol>".$error."</ol>";
            return 
    $error;
            }
        
        
        } 
    And this is the function from 'registration_forms.php' that displays the form.

    PHP Code:
    <?PHP

    // Store the registration forms as functions

    function registration_form_1()
        {
        
        
    // Include the header information

        
    Require('../include/header.php');
        
        
    // declare global variables
         
        
    global $ret_error;
        global 
    $email_address;
        global 
    $user_name;
        global 
    $password1;
        global 
    $password2;
        
        if(empty(
    $ret_error))
            {
            
    $ret_error 'Please choose a user ID and password, and provide your email address.';
            }
        
        echo 
    "
        
    <table align='center' background='http://www.rahlentertainment.com/RVM/Images/registration/register1.1.jpg' border='0' width='778px' height='379px'>

    <! ROW ONE >

        <tr height='75px'>
            <td>
            
            </td>
        </tr>
        
    <! ROW TWO >

        <tr height='73px'>
            <td>
            <Table border='0'>
                <tr>
                    <td width='240px'>
                    
                    </td>
                    <td width='450px' align='center'>
                    <div class='form_instructions'>
                    "
    .$ret_error."
                    </div>
                    </td>
                    <td>
                    </td>
                </tr>
            </table>
            </td>
        </tr>

    <!ROW THREE>
    <form action='"
    .$_SERVER[PHP_SELF]."' method='post'>
        <tr height='120px' valign='top'>
            <td>
            <table height='120px' valign='top' border='0'>
                <tr>
                    <td width='400px'>
                    
                    </td>
                    <td width='170'>
                    <table border='0' width='210px' align='left'>
                        <tr valign='top' height='29px'>
                            <td>
                            <input type='text' name='user_name' value='"
    .$user_name."' />
                            </td>
                        </tr>
                        <tr valign='top' height='29px'>
                            <td>
                            <input type='text' name='password1' value='"
    .$password1."' />
                            </td>
                        </tr>
                        <tr valign='top' height='29px'>
                            <td>
                            <input type='text' name='password2' value='"
    .$password2."' />
                            </td>
                        </tr>
                        <tr valign='top' height='25px'>
                            <td>
                            <input type='text' name='email_address' value='"
    .$email_address."' />
                            </td>
                        </tr>
                    </table>
                    </td>
                    <td>
                    <input type='submit' name='submit' value='Register' />
                    </td>
                </tr>
            </table>
            </td>
        </tr>
    </form>
    <! ROW FOUR >

        <tr height='57'>
            <td>
            
            </td>
        </tr>
        
    <! ROW FIVE >

        <tr>
            <td>
            <table border='0'>
                <tr>
                    <td width='131'>
                    
                    </td>
                    <td>
                    <a href='#' class='small_text_links'>Terms of Use</a>
                    </td>
                    <td width='346px'>
                    </td>
                    <td>
                    <a href='#' class='small_text_links'>Privacy Policy</a>
                    </td>
                </tr>
            </table>
            </td>
        </tr>
    </table>
        "
    ;
        }
    Last edited by lightnb; 02-25-2007 at 08:19 PM.

Thread Information

Users Browsing this Thread

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

     

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
HTML5 Development Center



Recent Articles