Form Help!

Discussion in 'PHP' started by Bulldog-Designs, Sep 18, 2006.

  1. #1
    I know how to make a simple form that mails to my Email Address, but my server doesnt alow it.

    So i need some kind of way to post the info to a .txt file or some other way to store the info they submit.
    Can you please prvide the basic code. thank you!
     
    Bulldog-Designs, Sep 18, 2006 IP
  2. tangtang

    tangtang Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you have mysql? I think that would be the ideal solution.

    Create a db table w/ the following fields: ID (set to auto-increment), from (VARCHAR), body (TEXT). Then, just use a simple INSERT query.
     
    tangtang, Sep 18, 2006 IP
  3. Bulldog-Designs

    Bulldog-Designs Active Member

    Messages:
    912
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    60
    #3
    i have PHPmyAdmin- and i know absolutley nothing about it. Its really hard to navigate. so if theres another way id appreciate someone sharing it.
     
    Bulldog-Designs, Sep 18, 2006 IP
  4. pcoptimized

    pcoptimized Peon

    Messages:
    193
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you don't have access to mysql or text file is the only way you want to go...

    Make a php page called formprocess.php (or whatever name you want) with this code in it.
    
    foreach ($_POST as $key=>$value){
    $received .= "$key = $value\r\n";
    }
    $printout = fopen('formvariables.txt', 'w');
    fwrite($printout, $received);
    fclose($printout);
    
    
    //Add your thank you text, etc. here.
    
    PHP:
    Then post your form to formprocess.php.
     
    pcoptimized, Sep 18, 2006 IP
  5. Bulldog-Designs

    Bulldog-Designs Active Member

    Messages:
    912
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Not working
    Named contact.html
    Can you help?
     
    Bulldog-Designs, Sep 18, 2006 IP
  6. pcoptimized

    pcoptimized Peon

    Messages:
    193
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    On your formprocess.php page you'll need to start it with <?php and end it with ?> instead of your html tags.

    IE: <?php

    foreach ($_POST as $key=>$value){
    $received .= "$key = $value\r\n";
    }
    $printout = fopen('formvariables.txt', 'w');
    fwrite($printout, $received);
    fclose($printout);


    //Thankyou.


    ?>

    Don't need the <html> tags in there.
     
    pcoptimized, Sep 18, 2006 IP
  7. Bulldog-Designs

    Bulldog-Designs Active Member

    Messages:
    912
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    60
    #7
    alride!!!! thank you man
     
    Bulldog-Designs, Sep 18, 2006 IP
  8. Bulldog-Designs

    Bulldog-Designs Active Member

    Messages:
    912
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    60
    #8
    problem-when a new form is posted it deletes the old one...is there a way around this?
     
    Bulldog-Designs, Sep 18, 2006 IP
  9. affihq

    affihq Peon

    Messages:
    329
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I have never scripted php before, but I have started to learn:

    This will fix your problems:

    
    <?php
    
    foreach ($_POST as $key=>$value){
    $received .= "$key = $value\r\n";
    }
    !$printout = fopen('saved.txt', 'a');
    fwrite($printout, $received);
    fclose($printout);
    
    //Thanks!
    header("location: http://your-url.com/thankyou.html");
    
    ?>
    
    Code (markup):
    I edited the last line to redirect to a "thank you" type page, just change the "your-url" to your url.
    Like 2 minor changes, and it will do exactly what your looking for.
     
    affihq, Sep 19, 2006 IP
  10. affihq

    affihq Peon

    Messages:
    329
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #10
    disregard this post
     
    affihq, Sep 19, 2006 IP
  11. Bulldog-Designs

    Bulldog-Designs Active Member

    Messages:
    912
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    60
    #11
    ^disregard, it didnt work?
     
    Bulldog-Designs, Sep 19, 2006 IP
  12. pcoptimized

    pcoptimized Peon

    Messages:
    193
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Yes, when changing the switch in the fopen function to "a" it will "append" to your file and not replace the previous posts. Just make sure you have the text file there already. (which you should by now)


    $printout = fopen('formvariables.txt', 'a');
    fwrite($printout, $received);
    fclose($printout);

    echo "Thank you for using our form. Somebody will get with you shortly.";

    ?>

    And like affihq was showing, there are different approaches you can take as to what to do next. I personally use a "thankyou" page and have this "formprocess" page redirect to our "thankyou" page like affihq's example. But going further this is something you'll need to decide on what you want to do.

    There are also "checks" that you'd like to perform to make sure your function is getting processed before it goes any further, etc. etc., etc. It can ge quite in depth. But for the most part, your coding above should do the trick for what you're needing.
     
    pcoptimized, Sep 19, 2006 IP
  13. Bulldog-Designs

    Bulldog-Designs Active Member

    Messages:
    912
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    60
    #13
    That was prefect. thank you!!!!
     
    Bulldog-Designs, Sep 19, 2006 IP
  14. pcoptimized

    pcoptimized Peon

    Messages:
    193
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Glad it's working. Happy coding! :)
     
    pcoptimized, Sep 19, 2006 IP