SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot TCJeter's Avatar
    Join Date
    Jun 2002
    Location
    Anchorage, AK
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form within a form? Multiple destinations for info?

    I am looking to create a form that has about 15 fields of info. In submitting the form, I would like ALL of the information to go to a specified (mail) account with the appropriate php 'mail' function. Additionally, I would like the core information (name, e-mail, address, ph#) to go to our mail list manager's database (external server).

    Up until now, I can send it either way - posting the form via the action="$PHP_SELF" function, or sending it to the mail manager's server by way of a URL in the 'action=' (it's a Pearl script).

    Can I do both?? Has anyone done this before? can you point me in the right direction? I figure if it's feasable then PHP can do it, I'm just not that versatile in the language yet.

    THANKS FOR THE HELP!

    -TC

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First, if you have PHP >= 4.1 use $_SERVER['PHP_SELF'].
    About your question, pass the data to your script and then have it send it's own POST request with the form data to this external perl script.

    Maybe something like this (untested)
    PHP Code:
    $fp fsockopen('www.example.com'80);
    if (
    $fp) {
        
    $res   '';
        
    $query '';
        foreach (
    $_POST as $name => $content) {
            
    $query .= $name '=' urlencode($content) . '&';
        }
        
    $query substr($query0, -1);
        
    fwrite($fp"POST /script.pl HTTP/1.1\n");
        
    fwrite($fp"Host: www.example.com\n");
        
    fwrite($fp"Content-type: application/x-www-form-urlencoded\n");
        
    fwrite($fp"Content-length: ".strlen($query)."\n");
        
    fwrite($fp"Connection: close\n\n");
        
    fwrite($fp$query);
        while(!
    feof($fp)) {
            
    $res .= fgets($fp128);
        }
        
    fclose($fp);

    Last edited by Gaheris; Nov 3, 2003 at 15:29.

  3. #3
    SitePoint Zealot TCJeter's Avatar
    Join Date
    Jun 2002
    Location
    Anchorage, AK
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the example.
    Like I mentioned, I'm not that fluent yet, but as I understand it you have made the connection to the server, asked for a response - if there is a response then you post each item ($name, $address, etc.) to the specified URL. Did I understand that correctly?

    Do the different variables get listed in the
    Quote Originally Posted by Gaheris
    PHP Code:
    $query ''
    field?? And do I need to specify anything in the server response area?

    This still kind of scrapes the top of my head as it goes by, but this sort of direction helps greatly.

    Thanks,
    -TC

  4. #4
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you pretty much got it. I open a connection to the server and send a POST request with the form data. Then I read the response which you can analyse to know if everything went okay (look for status code 200 for example).
    Yes, the query variable will contain the form names and their values, it gets generated by this part
    PHP Code:
    foreach ($_POST as $name => $content) {
        
    $query .= $name '=' urlencode($content) . '&';

    $query substr($query0, -1); 
    Hope that helps

  5. #5
    SitePoint Zealot TCJeter's Avatar
    Join Date
    Jun 2002
    Location
    Anchorage, AK
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, it does help.
    This is an excellent starting point. If I can make it work, it will be one more building block (learned) in PHP. I don't get as much time as I'd like to jump into it, but I do appreciate the kickstart.

    Thanks,
    -TC


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
  •