how to make a php form action do 2 things?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • webandwe
    New Member
    • Oct 2006
    • 142

    how to make a php form action do 2 things?

    Hi,

    I got a database contact form that I build, it lists all the details and questions etc.

    I want to make it also send as an e-mail. I have a script that sorts out everything for you when you create a contact from namly "mymail.php "

    How can I go about to make the from go to mymail.php after it run $self for example:

    $form = "<form action=\"$self and do mymail.php\" method=\"post\" >";

    Thank-you for you help!!!!!!

    Kind Regards
    Louwrens
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    use
    [PHP]include 'mymail.php';[/PHP]
    under you main page.

    Or

    write the mymail.php related data on the same page where you putting Form.

    NOTE: you have to make sure the way of executing the mail function. only on a successful data entry to the form you can make it fire.

    Comment

    • webandwe
      New Member
      • Oct 2006
      • 142

      #3
      sorry I probably did not write cleary, sorry (english not my lang)

      I want to do exacly what your are saying, that I can do, the probem is excuting the form to do 2 thing at once on submit.

      run $self to send details to DB and run mymail.php to send out an e-mail.

      see I now have form action=$self it must be action=$self and mymail.php.

      I don't know how to write the and for PHP -- $self,mymail.ph p or $self","mymail. php

      Thanks

      Kind Regards
      Louwrens
      Last edited by webandwe; May 28 '07, 01:48 PM. Reason: spelling

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Originally posted by webandwe
        run $self to send details to DB and run mymail.php to send out an e-mail.
        So you want to send the form results to the same page and then send the data to mymail.php. E.g., if the page with the form were called form.php, you'd want to send the form results to form.php and then mymail.php. Is this correct?

        If which case, all you'd have to do would be to include these lines at the bottom of (e.g.) form.php:

        [code=php]
        if(/* some kind of validation check to make sure $_POST is valid> */)
        include('mymail .php');
        [/code]

        By including mymail.php directly in your form page, you are giving it access to the POST variables available to your form page.

        As a general rule, I've found that it's not a good idea to submit form values to the same page as the form (what if the User refreshes the page?).

        The way I would handle it would be to have the form send its values to a separate page that validates and saves the data into the session, then redirects back to the form page if further information/action is necessary, or else calls the mailer script and then redirects to a 'success' page when finished.

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          That is exactly not a good idea to execute the script in the same page.I am also agree with pbmods.

          Still you didn't post your script that you made so far. this is really not a good idea to find the solution for your problem.

          As per your post check whether, is this the thing that you are looking for?

          [PHP]<?php
          if($_POST['sub'])//To Avoid executing the script once page loaded.
          {
          //Scripts for database related tasks.
          $dbScript = @mysql_query(/*Other stuffs goes here*/);
          if($dbScript)//If successfully executed run the mail
          {
          include 'mymail.php';
          }
          //You Have to do something Here to Avoid Page refresh
          //And executing the script again
          }
          ?>
          <html>
          <body>
          <form action="<? $PHP_SELF ?>" method="post">
          <input name="sub" type="submit" value="Submit" />
          </form>
          </body>
          </html>[/PHP]

          Comment

          • webandwe
            New Member
            • Oct 2006
            • 142

            #6
            Hi,

            Yes it is not a good Idea to just run a code.

            My coding first check if there was something inserted and then checks and do.

            I did not thought the include will work since mymail.php has to run on it's own.

            I tweaked the coding a bit of the mymail.php a bit ,inserted the, include the mymail.php next to my DB execution and boom!!! ?It works!

            Thank-you all for your time and HELP!!!!!!!

            Kind Regards
            Webandwe

            Comment

            • pbmods
              Recognized Expert Expert
              • Apr 2007
              • 5821

              #7
              A pleasure to be of service.

              Good luck with the rest of your project. Post back if you ever need anything.

              Comment

              Working...