SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Server side form submission

    I have a php page where I post data to server and perform server side data validation. After I am finished with the validation, I want to post the info to another page for further input and processing if data is valid. How would I do this on the server?

  2. #2
    SitePoint Member maksimovic's Avatar
    Join Date
    Jul 2006
    Location
    Novi Sad, Serbia
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    save valid data to $_SESSION, and at the end of input process simply dump all you want from session data to the database or wherever you want.

  3. #3
    SitePoint Zealot krt's Avatar
    Join Date
    Sep 2005
    Location
    Australia
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simple solution

    Form:
    Code:
    <form action="process.php" method="post">
      <input type="text" name="phone_number" />
      <input type="submit" />
    </form>
    process.php
    PHP Code:
    <?php

    $errors 
    = array();

    if (!
    $_POST['phone_number']) $errors[] = 'No phone number provided';
    elseif (
    strlen($_POST['phone_number']) < 3$errors[] = 'Phone number too short';
    // ...

    if (!$errors) {
        
    // validated, do whatever you want
    } else {
        echo 
    'Validation errors: <br />' join('<br />'$errors);
    }

  4. #4
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by krt
    Simple solution

    Form:
    Code:
    <form action="process.php" method="post">
      <input type="text" name="phone_number" />
      <input type="submit" />
    </form>
    process.php
    PHP Code:
    <?php

    $errors 
    = array();

    if (!
    $_POST['phone_number']) $errors[] = 'No phone number provided';
    elseif (
    strlen($_POST['phone_number']) < 3$errors[] = 'Phone number too short';
    // ...

    if (!$errors) {
        
    // validated, do whatever you want
    } else {
        echo 
    'Validation errors: <br />' join('<br />'$errors);
    }

    Thats my problem. if no errors encounterd, how do I pass the data to lets say process_two.php for further processing. this needs to be on the server.

  5. #5
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats my problem. if no errors encounterd, how do I pass the data to lets say process_two.php for further processing. this needs to be on the server.
    You have to use session to store those values.
    Another solution (but a lengthy one) would be to store those values in a temporary table in the database. On the next page you can retrieve those values and process them. But I wouldn’t recommend this method, because it requires you to connect with the database.

  6. #6
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kailash Badu
    You have to use session to store those values.
    Another solution (but a lengthy one) would be to store those values in a temporary table in the database. On the next page you can retrieve those values and process them. But I wouldn’t recommend this method, because it requires you to connect with the database.
    It's not a given that connecting with the database is a bad thing though. A lot of applications store session data in the database.

  7. #7
    is_empty(2); foofoonet's Avatar
    Join Date
    Mar 2006
    Posts
    1,000
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was waiting to see if anyone had a better suggestion, but basically I think you want to construct a post header.

    http://www.zend.com/zend/spotlight/mimocsumissions.php Tutorial from 2001!

    Now I think this has been improved upon, you might look for CURL, and there is a new PEAR package http_{something or other}

    What I would do though, use Firefox, and look for the plugin called HTTP_LIVE_HEADERS and you can actually sit and watch what headers are sent to your pages, mess with the values etc and resend them to your own page.

    Now I am not positive about this, I have shown myself to be wrong about so much on this forum! but I am pretty sure it is non-trivial because you have to write in the header how many characters it is sending... But I am sure tools exist to get round this, as I have indicated. I would really be interested in hearing more accurate information than this.

    Upgrading to Mysql 5? Auto-increment fields now strict
    use NULL
    Or zero or leave the field name out completely.

  8. #8
    SitePoint Zealot krt's Avatar
    Join Date
    Sep 2005
    Location
    Australia
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Robbins, foofoonet's solution of POST headers is a good one. I still suggest to not use sessions.
    Also, you can try including the process file eg. process_two.php
    PHP Code:
    <?php
    if (!$errors) {
        
    // POST data accessible in included files
        
    include 'process_two.php';
    } else {
        echo 
    'Validation errors: <br />' join('<br />'$errors);
    }


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
  •