Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    making a contact form write to a file...

    I have a contact form on my site but want it to write to a file instead of sending it to my email, here is the code I am using:

    PHP Code:
    <?
    $name 
    $_REQUEST['name'] ;
    $email $_REQUEST['email'] ;
    $subject $_REQUEST['subject'] ;
    $message $_REQUEST['message'] ;
    mail"name@domain.com""Feedback Form Site",
    $message"From: $email" );
    header"Location: http://www.domain.com/thankyou.php" );
    ?>
    I would like for it to write to a .txt file...
    But theres more!
    I then want to be abloe to view the messages in a html document with a little delete button next to the message...
    Could someone please do this for me?

    But do it in such a way I can do the html document myself and add in the bits where i want them, so to display the name of the person i coul insert $name or something,

    Thank you,
    Craig.

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have you tried the Work Offers forum on this site?

    We're here to help, but not to do your work for you.. for free.

    Good luck,
    Sadiq.

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thats a good idea... Thanks..... sad69!

  • #4
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    I already have the "write to text file" bit done. Adding an embedded "delete" section would be simple enough. I'll do it as soon as I get a chance.

    -Celt

  • #5
    Regular Coder
    Join Date
    Apr 2004
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you celtboy, thank you verry much!

  • #6
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    hmmm. Before I finish, do u want to store data in an xml file, or just use some custom separation tags?

  • #7
    Regular Coder
    Join Date
    Apr 2004
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont mind, some custom separation tags would be easier to understand I think...
    Whatever you think would be best...

  • #8
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    no, i haven't forgotten...just baby taking up most of my time!

    XML would be nice, but I haven't used PHP's parse functions before, so I'll have to read up on them first.

    Do you want to allow html code in the user's input data?

    -Celt

  • #9
    Regular Coder
    Join Date
    Apr 2004
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts
    not realy...
    but I dont mind...
    Last edited by cragllo; 10-14-2004 at 05:06 PM.

  • #10
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    done. Need to use XML. Several bugs. Instructions in 'index.php' at top.

    See attachment.

    -Celt

    ps. sorry took so long!
    Attached Files Attached Files

  • #11
    Regular Coder
    Join Date
    Apr 2004
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank You! Better late that never eh?

    It keeps comimg up...

    Parse error: parse error, unexpected ')' in /home/cragllo/public_html/radio/request/index.php on line 199

    what wrong?
    Last edited by cragllo; 11-02-2004 at 05:29 PM.

  • #12
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    delete one of the ")" beside the semicolon in index.php, line 199. Or use save the following, overwriting the original index.php:

    PHP Code:
    <?php
    /********************************************************************
     Comments.php
     
     Script Purpose:
               Allow the submission of visitor comments. Comments should
               be easily maintainable and viewable by the administrator.
               All entries are stored in a flat-file database.

     Script Setup:
               - Set appropriate values in the 'config' section
               - Make sure you have the appropriate files setup.
               - Using the provided templates for the files, make sure
                 that you use the following values for substitutions in
                 your html, surrounded by '<!--{{' and '}}-->' :
                      NAME            DATE            EMAIL
                      SUBJECT         MESSAGE         DELETE(for admin page)
               
               - The first time a comment is added, you will get a warning
                 regarding an undefined offset. This is because the function
                    'get_num_entries()' does not have any error checking.
                 It will not continue beyond the addition of the first
                 comment.

     Script Use:
               - Extract this file to the directory. The first time a
                 comment is added, it will create the comments file.
               - Comments can be deleted by accessing the admin page.
                 To Access the admin page, append ?app_action=admin' to
                 the url. Example:
                 
                 [url]http://www.example.com/comments/index.php?app_action=admin[/url]
                 
                 You can delete comments by simply clicking the button by
                 each corresponding comment.

     Known Issues:
               - No error checking
               - Need function clean-up
               - get_num_entries() bug on first comment addition
               - Need to add UBB code.           
    ********************************************************************/




    //====================================
    //           Config Section
    //====================================

    /* The templates */
    define("COMMENT_FILE","comment_file.txt");
    define("COMMENT_FORM","comment_form.htm");
    define("COMMENT_CONFIRMATION","comment_confirmation.htm");
    define("COMMENT_ADMIN","comment_admin.htm");

    /* Allow html in user comments? */
    define("ALLOW_HTML",FALSE);  // default is FALSE



    //====================================
    //           Logic Section
    //====================================

    /* Decide what to do */
    if (isset($_GET["app_action"])) {
       if (
    $_GET["app_action"] == "admin") {
           
    display_admin_form();
           exit;
       }
    }

    if (isset(
    $_POST["app_action"])) {
        
       switch (
    $_POST["app_action"]) {
           case 
    "submit_comment" :
                 
    perform_submit();
                 
    display_confirmation();
                 break;
           case 
    "delete_comment" :
                 
    perform_delete();
                 
    display_admin_form();
                 break;
           default :
                 
    display_submit_form();
                 exit();
       }

    } else {
      
    display_submit_form();
    }


    //====================================
    //         Functions Section
    //====================================


    function display_submit_form() {
        
    $template file_get_contents(COMMENT_FORM);
        print 
    $template;
    }

    function 
    display_confirmation() {
        
    $template file_get_contents(COMMENT_CONFIRMATION);
        print 
    $template;
    }


    function 
    perform_submit() {
       
    $name urlencode($_POST["name"]);
       
    $email urlencode($_POST["email"]);
       
    $subject urlencode($_POST["subject"]);
       
    $message urlencode($_POST["message"]);
       
    $comment = array("name" => $name"email" => $email"subject" => $subject"message" => $message);
       
       
    $num_entries = (int)get_num_entries();
       
    set_num_entries($num_entries+1);
       
       
    $file_handle fopen(COMMENT_FILE,"a+");
       
       
    fwrite($file_handle,"<!-- COMMENT:BEGIN -->\r\n");
       foreach (
    $_POST as $key => $value) {
           if (
    $key == "app_action") { continue; }
           
    fwrite($file_handle,strtoupper($key) . "=\"" urlencode($value) . "\"\r\n");
       }
       
    fwrite($file_handle,"DATE=\"" date("F j, Y, g:i a") . "\"\r\n");
       
    fwrite($file_handle,"<!-- COMMENT:END -->\r\n\r\n");
       
    fclose($file_handle);
    }

    function 
    get_num_entries() {
       
    $file file(COMMENT_FILE);
       return 
    $file[0];
    }

    function 
    set_num_entries($num_entries) {
       
    $file file(COMMENT_FILE);
       
    array_shift($file);
       
    $file_handle fopen(COMMENT_FILE,"w+");
       
    fwrite($file_handle,$num_entries "\r\n");
       foreach (
    $file as $line) {
          
    fwrite($file_handle,$line);
       }
       
    fclose($file_handle);
    }



    function 
    display_admin_form() {
       
    /* the html for the delete button that we sub into the admin form */
       
    $delete_button "<input type=\"submit\" name=\"comment_<!--COMMENT_NUM-->\" value=\"Delete\" />";
       
       
    /* We store the entire comments file (minus the first line) in this string */
       
    $comments "";

       
    $output "";
        
       
    /* get the admin template */
       
    $file file_get_contents(COMMENT_ADMIN);
       
       
    /* get an array breaking the form into an array, including the reusable block fore each entry */
       
    $parsed_array get_parse_block($file);
       
       
    /* the start of the output */
       
    $output $parsed_array[0];
       
       
    /* From the comments file, remove the first line */
       
    $file file(COMMENT_FILE);
       
    array_shift($file);
       foreach (
    $file as $line) { $comments .= $line; }

       
    /* Parse out each comment, and store it in an array */
       
    $finds "/<!-- COMMENT:BEGIN -->(.)*?<!-- COMMENT:END -->/si";
       
    $comments_block preg_match_all($finds,$comments,$matches);


       
    /* parse each line and split into name/value pairs */
       
    for ($x 0$x sizeof($matches[0]);$x++) {
           
          
    $lines explode("\r\n",$matches[0][$x]);
          
          foreach (
    $lines as $value) {
              if (
    $value[0] == "<") {
                 continue;
              } else {
                 
    parse_str($value);
              }
          }
          
          
    /* store the name/value pairs in an array */
          
    $values_array = array("name"=>$NAME,"email"=>$EMAIL,"subject"=>$SUBJECT,"message"=>$MESSAGE,"date"=>$DATE);
          foreach (
    $values_array as $key=>$value) {
              
               if (
    ALLOW_HTML == FALSE) {
                
    $values_array[$key] = htmlentities(trim($value,"\""));
             } else {
                
    $values_array[$key] = trim($value,"\"");
             }
          }
          
          
    /* replace sections of the template with the name/value pairs */
          
    $toutput eregi_replace("<!--{{NAME}}-->",trim($values_array["name"],"\""),$parsed_array[1]);
          
    $toutput eregi_replace("<!--{{EMAIL}}-->",trim($values_array["email"],"\""),$toutput);
          
    $toutput eregi_replace("<!--{{SUBJECT}}-->",trim($values_array["subject"],"\""),$toutput);
          
    $toutput eregi_replace("<!--{{MESSAGE}}-->",trim($values_array["message"],"\""),$toutput);
          
    $toutput eregi_replace("<!--{{DATE}}-->",trim($values_array["date"],"\""),$toutput);
          
          
    $del_button eregi_replace("<!--COMMENT_NUM-->",(STRING)$x,$delete_button);
          
    $toutput eregi_replace("<!--{{DELETE_BUTTON}}-->",$del_button,$toutput);
          
          
    /* add this new block to the final output */
          
    $output .= $toutput;
       }
       
       
       print 
    $output $parsed_array[2];
       
    }


    function 
    perform_delete() {
       
    $comments "";
       
       
    /* From the comments file, remove the first line */
       
    $file file(COMMENT_FILE);
       
    $num_comments array_shift($file);
       foreach (
    $file as $line) { $comments .= $line; }

       
    /* Parse out each comment, and store it in an array */
       
    $finds "/<!-- COMMENT:BEGIN -->(.)*?<!-- COMMENT:END -->/si";
       
    $comments_block preg_match_all($finds,$comments,$matches);
       
       
    /* figure out which comment to remove */
       
    $the_keys array_keys($_POST);
       foreach(
    $the_keys as $key) {
          if (
    substr($key,0,8) == "comment_") {
               
             
    $comment_to_del explode("_",$key);
             
    $comment_to_del = (Int)$comment_to_del[1];
          }
       }
       
       
    /* remove that comment from the comments array */
       
    $matches[0][$comment_to_del] = "";

       
    /* write everything back to the comments file */
       
    $file fopen(COMMENT_FILE,"w+");
       
       
    /* let's not forget to decrement the comment count! */
       
    fwrite($file$num_comments-1);
       
       
    /* write the comments back */
       
    for ($x 0$x sizeof($matches[0]);$x++) {
          
    fwrite($file,$matches[0][$x]);
          
    fwrite($file,"\r\n");
       }  
       
    fclose($file);
       
    }


    function 
    get_parse_block($content) {
       
    $finds "/<!-- BLOCK:COMMENTS:START -->(.)*?<!-- BLOCK:COMMENTS:STOP -->/si";
       
    $parse_block preg_match($finds,$content,$matches);
       
    $content preg_split($finds,$content);
       
       
    $return_array = array($content[0],$matches[0],$content[1]);
       
       return 
    $return_array;
       
    }
    ?>
    Sorry!

  • #13
    Regular Coder
    Join Date
    Apr 2004
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont know how to thank you! everything has just fallen into place!

    one other thing though when you view them its shows \" and \ at the ends of the inputs, is there any way to get rid of these?

    thank you,
    craig.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •