Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: capture form data in database and email data simultaneously

  1. #1
    Join Date
    Feb 2007
    Posts
    1

    Default capture form data in database and email data simultaneously

    I am currently capturing data from a form in a sql server database from a jsp application running on solaris. Can I capture the data and email the data from the same form using formmail as an onclick instead of an action for the form? Thanks.

  2. #2
    Join Date
    Dec 2003
    Posts
    3,980

    Default Re: capture form data in database and email data simultaneously

    Hi,

    No. The way HTTP POST works, you must submit the form in order for the server to run FormMail to process the data.

    I can't think of any reason why you cannot process this way.

    If you're worried about disturbing the current document , then in the <form...> tag you can specify "target=_blank" and all the processing will be done in a new window.
    Last edited by russellr; 25-Feb-2007 at 09:55 PM.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  3. #3
    Join Date
    Aug 2009
    Posts
    10

    Default Re: capture form data in database and email data simultaneously

    True, however the way I would solve this is to write a PHP app which retrieves the $_POST data, stores it to a database, and then invokes formail afterwards. Works like a preprocessor.

    Ben Milander

  4. #4
    Join Date
    Sep 2009
    Posts
    2

    Default Re: capture form data in database and email data simultaneously

    How would you do that? I'm not great with PHP. I'm looking to do something similar.

    I want to store form data to a database and then email it as well.

    I can write the php app to store the data, but how do you invoke formmail from that php app after the database procedures complete?

  5. #5
    Join Date
    Sep 2009
    Posts
    2

    Default Re: capture form data in database and email data simultaneously

    for those of you looking for an answer to this one, this is how I did it. I'm using formmail.php as my mail handler, I added this sql connection string just above the mail function in formmail, it works beautifully

    Code:
    $con = mysql_connect("Host","Username","Password");
    if (!$con)
    {
      die('Could not connect: ' . mysql_error());
      }
    mysql_select_db("slanderman", $con);
    $sql="INSERT INTO performer (firstname, lastname, email, performername1, performername2)
    VALUES
    ('$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[performername1]','$_POST[performername2]')";
    if (!mysql_query($sql,$con))
      {
     die('Error: ' . mysql_error());
      }
    mysql_close($con);

  6. #6
    Join Date
    Aug 2009
    Posts
    10

    Default Re: capture form data in database and email data simultaneously

    You can do it by modifying formail as you did or you could create a new php file containing your database code to store the email and then add just one line

    include "pathto/formmail.php";

    This way you do not change the formmail code at all. You could also use the php header("Location:: $url"); function to redirect to formmail.

    Ben

    <?php

    $con = mysql_connect("Host","Username","Password");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("slanderman", $con);
    $sql="INSERT INTO performer (firstname, lastname, email, performername1, performername2)
    VALUES
    ('$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[performername1]','$_POST[performername2]')";
    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    mysql_close($con);

    // Add this
    include "pathto/formmail.php";
    ?>

  7. #7
    Join Date
    Aug 2007
    Posts
    24

    Default Re: capture form data in database and email data simultaneously

    bmiland,
    A question to make sure I understand your suggestion:
    That in my current form file (an html file) I should replace
    form method="post" action="http://www.mydomain.com/fbmail/formmail.php"
    with something like
    form method="post" action="newfile.php"
    where newfile.php contains your posted code and calls/invokes formmail.php using the include function per your example

    I am understanding you correctly?

  8. #8
    Join Date
    Aug 2009
    Posts
    10

    Default Re: capture form data in database and email data simultaneously

    Yes, your understanding is correct. You are just prepending your code to the formMail program and formMail processes the form normally. However, you do not have formMail checks against spam attacks so you might get some spam which formMail would not forward.

    Ben

  9. #9
    Join Date
    Aug 2007
    Posts
    24

    Default Re: capture form data in database and email data simultaneously

    Ben,
    Thanks a lot for your code.
    I moved the include up to the top of the page, just under the opening <?php tag and the form no longer submits incomplete, required fields. Everything gets processed through formail and if the form is incomplete (required fields) the fmbadhandler and error-tmpl page are called and no mysql record insertion happens.

    Once again, a tip of my hat for you help.

  10. #10
    Join Date
    Nov 2009
    Posts
    1

    Default Re: capture form data in database and email data simultaneously

    Ben
    Just came across this flow
    You mentioned a problem with spam maybe coming through

    Have you any suggestions how to avoid this?

    regards

    Andrew

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Sending form results in an HTML email
    By russellr in forum HOWTO Guides and Tips
    Replies: 26
    Last Post: 12-Jan-2006, 09:31 PM
  2. POST form data as well as email
    By zippy in forum FormMail Subscription Support
    Replies: 20
    Last Post: 24-Jan-2004, 05:29 PM
  3. autoresponder to email from form
    By rebirth in forum FormMail Subscription Support
    Replies: 2
    Last Post: 21-Jan-2004, 05:43 AM
  4. not seeing form data
    By brownie in forum FormMail Subscription Support
    Replies: 6
    Last Post: 19-Jan-2004, 02:37 AM
  5. Help trying to set up a form to email and send info to file
    By rridsdale in forum FormMail Subscription Support
    Replies: 1
    Last Post: 14-Jan-2004, 03:38 AM

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
  •