Jump to content

[SOLVED] Two actions on form submit


btr2007

Recommended Posts

Is there anyway for a form to have two actions?

 

Example:

Visitor selects a file to upload and when they click upload it calls the upload script and also sends an email to a recipient using a form-to-mail script.

 

Or is there some code that can be included in the upload script to send an email?

Link to comment
https://forums.phpfreaks.com/topic/82263-solved-two-actions-on-form-submit/
Share on other sites

You only need one form action. Here is an example

 

<?php

//check if they pressed the submit button
if (isset($_POST['submit'])){

//put upload code here

//put email code here

}

?>

 

If you don't understand that, post your code and we can help you put it together.

Will that still work when I'm using that Formmail script to send the email?

 

<?php
// Where the file is going to be placed 
$var1 = $_GET["leadon"];
//$path = mysql_real_escape_string('leadon');
$target_path = $var1;

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file " .  basename( $_FILES['uploadedfile']['name']) . 
    " has been uploaded";
   /*Add email code here? - can it be a call to formmail or could i use some other script?*/

} else{
echo $target_path;
    echo "There was an error uploading the file, please try again!";
}
?>

Yes, that should work. If you would rather keep the formmail script separate, you can just use an include.

 

so right where you have that comment, just put this code

include "formmail.php"; //or whatever that file is called

 

Ok I've decided to use some php code to send the email instead.

 

The script i was using is in a pl file and gets stored in the bin.

 

If i can get the php email code to work i will mark this topic as solved but if i don't i will use this topic for questions.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.