...

View Full Version : Form Help!



Jittor
12-06-2005, 04:42 PM
Hello,

I have created a form in DW and have it set up so the submit button will email me all the info but I would also like it to redirect them to another page after that. How do I make the submit button perform 2 actions with out using php because I don't know php? Thanks

mark87
12-06-2005, 04:48 PM
Using a server side language would be the best solution because (I guess from what you've told us) you are relying on the end users' current email client.

You could do something like this -


<script type="text/javascript">
function email() {
document.formname.action="mailto:you@somewhere.com";
document.location.href="thanks.html";
}
</script>


<form method="post" onsubmit="javascript:email();" name="formname">

Jittor
12-06-2005, 04:55 PM
So the first part:

<script type="text/javascript">
function email() {
document.formname.action="mailto:you@somewhere.com";
document.location.href="thanks.html";
}
</script>

Goes inbetween the head tags right?

Then the second part got at the top of the form. Am I missing anything?

mark87
12-06-2005, 04:57 PM
That's correct, should be all.

JamieR
12-06-2005, 05:02 PM
What I do with my php mail form I just use:



header("Location: thanks.php");


after the mail function. However what worked for me when I had my old script was to use a hidden field called "redirect" then in the value box I had the url of the page I wanted the user to be redirected to. I don't know why that worked 'cause I didn't have any redirect or anything in my script and didn't call the redirect.

Jittor
12-06-2005, 05:04 PM
You Rock! It worked great! Everyone else was trying to say I should use php (which I don't know) but I knew there was another way! That was Javascript...how could I learn that?

Also, since I don't have a database like mySQL I have to use the basic sent email function which opens the users default email program - is there a way to have the subject line what I want it to be, like "Coupon request"

Jittor
12-06-2005, 05:08 PM
Weazle - I don't know php. Would like to but dont even know where to start. What was your old script in - something other than php. Do you use a program like Dreamweaver or do you just straight code.

JamieR
12-06-2005, 05:15 PM
My old script was a basic script written in CGI (Perl) which I got off someone. My new one I wrote myself in PHP. I use DW but I hand code in it. Javascript can be disabled, whilst PHP can't be disabled by the end user (the person browsing your site) so I say use that. Does your server support PHP by any chance? I can give you my script if you want then you can modify it to your requirements if I tell you how.

mark87
12-06-2005, 05:16 PM
That was Javascript...how could I learn that?

http://www.w3schools.com/js/default.asp :)


Also, since I don't have a database like mySQL I have to use the basic sent email function which opens the users default email program - is there a way to have the subject line what I want it to be, like "Coupon request" ?

document.formname.action="mailto:you@somewhere.com?subject=Coupon%20Request";

Jittor
12-06-2005, 05:20 PM
Weazel - That would be awesome - post away

Mark87 - I use that site all the time. It's a great site to learn from. So that's where you recomend learning - Awesome thanks

mark87
12-06-2005, 05:53 PM
Jittor I think you may have missed my edit above showing how to add in a subject?

Weazel, the hidden redirect field does not seem to be a standard HTML feature. Were you using FormMail.pl ? That seems to use the redirect field.

JamieR
12-06-2005, 06:00 PM
Nah I wasn't, I was using some other one I got from somewhere, can't remember what it was called but I got the old code lying around here somewhere.

Anyway, Jittor - Some of the more experienced PHP devs will probably say this is crap, but I'll post it:



<?php

error_reporting('E_ALL');

/*
JMailer version 1.7
http://www.jamierees.co.uk
Author: Jamie Rees - www.jamierees.co.uk
Licence: Creative Commons Sharealike licence. You may share it and modify it as long as you honour the original
author (read: me)
*/

/*variables - change these to match your requirements*/

$name = trim(rtrim(str_replace(array("/", ";", ":", "="), '', $name))); //I didn't want people putting in whitespace or other
$email = trim(rtrim(str_replace(array("/", ";", ":", "="), '', $email))); //characters in their name etc.
$subject = trim(rtrim(str_replace(array("/", ";", ":", "="), '', $subject)));
$message = trim(rtrim(str_replace(array("/", ";", ":", "="), '', $message)));


/*Variables*/

$emailTo = '"Your name" <name@domain.co.uk>'; //<Your name and email address
$emailSubject = "Message from $name at domain.co.uk"; //<The subject line
$forbidden = 'Invalid Referer'; //<The message that people get when they try and send mail from another domain via your form
$your_site = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; //<Your site
$main_url = "http://www.domain.co.uk/contact.php"; //<The page that your contact form is located on
$date = date("D M Y"); //<The date

/*don't change anything under here unless you know what you're doing*/

$ip = $_SERVER['REMOTE_ADDR']; //<The IP of the person who is sending the message
$browser = $_SERVER['HTTP_USER_AGENT']; //<The browser of the person who is sending the email
$host = gethostbyaddr($_SERVER['REMOTE_ADDR']); //<The ISP host of the person who is sending the email
$referer = $_SERVER['HTTP_REFERER']; //<The url of the refering page

$emailBody = "name: $name\n"
. "email: $email\n"
. "subject: $subject\n"
. "IP Address: $ip\n"
. "Browser: $browser\n"
. "Host: $host\n"
. "Date mail sent: $date\n"
. "\n"
. "Message: $message\n"
. "\n"
. "\n"
. "JMailer.php Mail Script v1.7 by Jamie Rees - www.jamierees.co.uk"; //Free advertisment :)

$emailHeader = "From: $email\n"
. "Reply-To: $email\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
. "Content-transfer-encoding: quoted-printable\n";

if (empty($name) || empty($email) || empty($subject) || empty($message)) {
//If any of the fields are empty, the script echos with this message
die("All fields must be filled in. Please go back and try again");


}

if (strlen($message) <= 10) { //Basically checks to see whether the message is or is over 10 characters in length.
die("The message field must contain over 10 characters");
}

if ($_SERVER['HTTP_REFERER'] !== $main_url) {
//if the refering page is not the page specified above it dies
echo $forbidden;
exit;
}

//Checks to see whether the email address is complete.

function CheckEmail($email) {
if (ereg("(.*)+@(.*)+\.[[:alnum:]]+", $email)) {
return true;
} else {
return false;
}
}
if (!(CheckEmail($email))) {
die("Invalid email address");
}


//I needed this because people were sending me dodgy emails with my site as part of the fake email address, so what I did was
//to check every email address then make the script die if the email address contains "jamierees.co.uk"
if(stristr($email, 'domain.co.uk')) {
die("Invalid email address");
}

else {

mail($emailTo, $emailSubject, $emailBody, $emailHeader);

header("Location: thanks.php"); //the page that the script will redirect to once it's been sent

exit;
}
?>


Hope this helps.

All you change is the domain references, your name and any error message etc if you want.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum