473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to make a php form action do 2 things?

142 100+
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
6 4978
ak1dnar
1,584 Expert 1GB
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
webandwe
142 100+
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
5,821 Expert 4TB
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
1,584 Expert 1GB
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
webandwe
142 100+
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
5,821 Expert 4TB
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

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

Similar topics

9
by: Dave Martin | last post by:
I've successfully used CURL to maneuver around and through sites but a new site I've been trying to work with has got me stumped. To retrieve the data I'm trying to get a login is required. If...
2
by: jason | last post by:
Is it possible to POST a FORM to multiple URLS at the same time....OR.... Is the only workaround for this scenario to use response.redirect in the called ASP page and do a multi processing? -...
5
by: Rob Meade | last post by:
Hi all, Ok - I have a bit of a problem with a login page. Originally it was written in normal asp - the page displayed the form, the user entered their details, it posted back to itself,...
3
by: Martin | last post by:
I have a form tag in my page (Metadata.aspx) as belo <form id="Form1" method="post" runat="server" action="Metadata.aspx" My problem is that when this page is accessed from other pages which...
4
by: Lee Chapman | last post by:
Hi, Can anyone tell me why in the code below, the call to ClearChildViewState() has no effect? To paraphrase the code: I'm using view state. I have a textbox and a submit button (and a label...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
16
by: whyyyy | last post by:
The script below works fine if the form is filled out and submitted. But a (blank) e-mail is sent whenever the page loads, even when the form is not submitted. I would like to receive the e-mail...
19
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
2
by: Ellie | last post by:
I am just starting to develop in asp.net and I have somewhat of a familiarity with asp 3.0. I am comfortable with asp 3.0 for my server side processing and javascript for client side. I also like...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.