Forum Moderators: coopster

Message Too Old, No Replies

Form Mailing Issues

Multiple Submit Buttons

         

briesm

3:21 pm on Jun 2, 2005 (gmt 0)

10+ Year Member



Hey all, I want to have a seperate form submit button that has a different "action" which would point to the mailing script. But I want it to be able to Post all form fields from the other form that is on the same page. Can I just create a new form at the very bottom with a submit button and it will still pass all fields on the page from the other form that ends before it on the very same page?

jatar_k

4:34 pm on Jun 2, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the nature of submit buttons is that they submit the information contained in the form they are in only, would be a big mess if they didn't.

To have a form do different actions you need a way to, either, tell the form before hand what it is going to do then maybe write this into a hidden form variable or have a way for the user to select the action.

What are your 2 actions?

also you could use a regular button and then use javascript to send it to different scripts for processing but that isn't really the greatest idea depending on what you actually want to do.

briesm

4:50 pm on Jun 2, 2005 (gmt 0)

10+ Year Member



Hmmm...well I suppose I could have them both point to the same php file.
1.)
I have a calculate button which reproduces the form with all session variables passed on, and does a few calculations, displaying data and adding a few more form fields.
Then
2.) A reset button which clears all forms and terminates the session.
Now what I need to have:
3.) A button that actually gathers all form info and sends it as an email.

So I'm thinking I have to make reference to whether this sendEmail button isSet and then execute code that will send an email with this info?
I know normally the "action" will point to say a mailParse script but I think I'll have to do all these 3 buttons in the same script? Though, another problem becomes how do I redirect it to a different page saying form completed or something...if-elsing the entire script and using echos to display the info would be dreadful.

jatar_k

5:04 pm on Jun 2, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



my thoughts

calculate - could just be javascript and not submit the form at all

reset - seperate form on same page that just nukes the session

submit - actually sending of email and true processing

briesm

5:21 pm on Jun 2, 2005 (gmt 0)

10+ Year Member



The calculate is a bit more complicated than that, it retrieves information from a database via SQL commands and the calculates based on certain form field info being passed and the info that was retrieved. I also put an if($_POST['clearAll']) and then it will destroy session. I do the same check on each form field as well which will effectively set the field blank if clearALL posted. All of this is working. THough, now I must figure out how to properly send this data.

I checked an online script, made some adjustments, but it isn't working. Basically, i'm checking if my submit button, named sendEmail was clicked, then it would execute the rest of this stuff.

<?php
if(isset($_POST['sendEmail'])){

$my_email = "Brian_Esmail@yahoo.com";

// This line prevents values being entered in a URL

if ($_SERVER['REQUEST_METHOD']!= "POST"){exit;}

$message = "";

// This line prevents a blank form being sent

while(list($key,$value) = each($_POST)){if(!(empty($value))){$set=1;}$message = $message . "$key: $value\n\n";} if($set!==1){header("location: $_SERVER[HTTP_REFERER]");exit;}

$message = stripslashes($message);

$subject = "Sales Order";
$headers = "From: " . $_POST['email'] . "\n" . "Return-Path: " . $_POST['email'] . "\n" . "Reply-To: " . $_POST['email'] . "\n";

mail($my_email,$subject,$message,$headers);

}

?>