By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

how to make a php form action do 2 things?

100+
P: 142
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
May 28 '07 #1
Share this Question
Share on Google+
6 Replies


ak1dnar
Expert 100+
P: 1,584
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.
May 28 '07 #2

100+
P: 142
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.php or $self","mymail.php

Thanks

Kind Regards
Louwrens
May 28 '07 #3

pbmods
Expert 5K+
P: 5,821
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:

Expand|Select|Wrap|Line Numbers
  1. if(/* some kind of validation check to make sure $_POST is valid> */)
  2.     include('mymail.php');
  3.  
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.
May 28 '07 #4

ak1dnar
Expert 100+
P: 1,584
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]
May 29 '07 #5

100+
P: 142
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
May 29 '07 #6

pbmods
Expert 5K+
P: 5,821
A pleasure to be of service.

Good luck with the rest of your project. Post back if you ever need anything.
May 29 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.