1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Simple form advice for holding page

Discussion in 'HTML, Graphics & Programming' started by simisker, 10 Mar 2010.

  1. simisker

    Mobster

    Joined: 27 Oct 2002

    Posts: 3,534

    Location: At the fulcrum of humdrum

    'lo all!

    Right, I'm preparing a holding page for someone's new business venture:

    http://www.plasticle.co.uk/

    You'll see that there's a little form to collect email addresses of interested viewers. Obviously, when the site eventually goes live, those who've submitted their email addresses will receive an email informing them such.

    Currently it's just a POST with a mailto, which is barely acceptable on lots of levels.

    So what's the best way of getting this email capturing implemented?

    As ever: ta in advance :)
     
  2. Pho

    Sgarrista

    Joined: 18 Oct 2002

    Posts: 9,207

    Location: Derbyshire

    A site that designs emails which needs help with email? :p.

    At a very simple level, something like this (untested):

    Change your form action to a subscribe page:
    PHP:
    <form autocomplete="off" method="post" action="subscribe.php">
    On that subscribe.php have something like this:
    PHP:
    <?php
    // No email so just bounce back to the main site
    If (!isset($_REQUEST['contact-form-email'])) {
            
    header'Location: http://www.plasticle.co.uk/') ;
    }

    // Do some email validation here
    $email_address $_REQUEST['contact-form-email'];

    if(
    mail("[email protected]""Let me know when Plasticle goes live!"$email_address)) {
        
    $result "Email address accepted, thank you.";
    } else {
        
    $result "An error occurred, please try again.";
    }
    ?>

    <html>
    <p>Wrap this inside your normal template</p>
    <?php echo $result ?>
    </html>

    A better way would be to dump their email into a database though.
     
    Last edited: 10 Mar 2010
  3. simisker

    Mobster

    Joined: 27 Oct 2002

    Posts: 3,534

    Location: At the fulcrum of humdrum

    Aw, come on - it's a web page! The irony isn't lost on me, though, don't worry :D

    I was hoping to do without the need for several pages. I'm sure Typekit, for instance, managed it when they pre-launched their service. Probably some whizzbang AJAXy stuff that I need to look into.

    Ta for the comprehensive reply, though, Pho :)
     
  4. Russinating

    Capodecina

    Joined: 27 Dec 2005

    Posts: 16,487

    Location: Bristol

    Do you have PHP/MySQL access? I could knock something up in 5 minutes if you do.
     
  5. Pho

    Sgarrista

    Joined: 18 Oct 2002

    Posts: 9,207

    Location: Derbyshire

    :D

    If you set your form's action to action="" the form will post back to the same page, you can then include that mail code at the top of the page without the need for more pages.

    You can use jQuery to submit the email via AJAX (using what I've already written) without too much effort. Have a look at this plugin for jQuery which will do just that - http://malsup.com/jquery/form/
     
  6. simisker

    Mobster

    Joined: 27 Oct 2002

    Posts: 3,534

    Location: At the fulcrum of humdrum

    Thanks for the offer, Russ, but I've just implemented a simple form from EmailMeForm, which has done the trick for now :)

    EDIT: And thanks again, Pho - that link may just come in handy down the line :)

    I do have an even simpler follow-up noob question:

    For future work, am I right in thinking that PHP will be set up by default without me having to do a cpanel-based install or anything? It's hosted on TSOHost.
     
    Last edited: 11 Mar 2010
  7. Tripnologist

    Mobster

    Joined: 12 May 2007

    Posts: 3,894

    Location: Bristol

    PHP is installed on most servers by default. The only time it may not be is if you're on Windows Server where you're expected to use .net.
     
  8. simisker

    Mobster

    Joined: 27 Oct 2002

    Posts: 3,534

    Location: At the fulcrum of humdrum

    Smashing. Cheers, Trip :)