Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12

Thread: Form Help!

  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Help!

    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

  • #2
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 -

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

  • #3
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's correct, should be all.

  • #5
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    What I do with my php mail form I just use:

    PHP Code:
    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.

  • #6
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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"

  • #7
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    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.

  • #9
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Jittor
    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";
    Last edited by mark87; 12-06-2005 at 04:18 PM.

  • #10
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #11
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #12
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    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 Code:
    <?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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •