Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Email input box ( with proper email needed to be entered )

Options
  • 10-02-2010 9:29pm
    #1
    Registered Users Posts: 67 ✭✭


    i know how to make a form with a email input box and send button with html
    and i know how to make the send button send me to another page but i dont know how i can make it so that only and email address can be written in
    with php this works


    if (!eregi('^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-]+\.[a-zA-Z0-9_\-\.]+$', $email)){
    echo 'That is not a valid email address. Please return to the'.' previous page and try again.';
    }


    i just want to know how to make a email input box with a send or submit button thats sends you to a different page after a email address it written into the input box, ( only a proper email address can be written into like first part, @ sign and then the .com,.ie,.net...ect )

    this can be in html, php or both


Comments

  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Do you mean, once the email address is valid, to send you to a confirmation page or page saying you're email was successfully entered? Or else a page that says something wrong.

    You should do a POST with the page with the email address to something like "checkemail.php".

    In this file, something like this:

    [php]
    <?php
    if (isset($_POST))
    $email = $_POST;
    else
    die("Email address not posted!");
    if (eregi('^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-]+\.[a-zA-Z0-9_\-\.]+$', $email))
    {
    header('location: success.php');
    }
    else
    {
    header('location: fail.php');
    }

    ?>
    [/php]

    By the way, you can use code tags around your code to make it easier to read.

    I think I know who you are btw :pac:


  • Registered Users Posts: 67 ✭✭Fergaloc


    Webmonkey wrote: »
    Do you mean, once the email address is valid, to send you to a confirmation page or page saying you're email was successfully entered? Or else a page that says something wrong.

    You should do a POST with the page with the email address to something like "checkemail.php".

    In this file, something like this:

    [php]
    <?php
    if (isset($_POST))
    $email = $_POST;
    else
    die("Email address not posted!");
    if (eregi('^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-]+\.[a-zA-Z0-9_\-\.]+$', $email))
    {
    header('location: success.php');
    }
    else
    {
    header('location: fail.php');
    }

    ?>
    [/php]By the way, you can use code tags around your code to make it easier to read.

    I think I know who you are btw :pac:
    that code looks like it goin to work , thx very much

    who do u think i am?


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Fergaloc wrote: »
    that code looks like it goin to work , thx very much

    who do u think i am?
    I'm Donal :p


  • Registered Users Posts: 67 ✭✭Fergaloc


    Webmonkey wrote: »
    I'm Donal :p
    i thought so:D


  • Registered Users Posts: 67 ✭✭Fergaloc


    if i have the email box and submit button with this code

    [HTML]<form name="form1" method="POST" action="thankyou.php.php">
    <input type="text" name="email" />
    <input type="submit" value="Sign Up" />
    </form>[/HTML]and the php code

    [PHP]<?php
    if (isset($_POST))
    $email = $_POST;
    else
    die("Email address not posted!");
    if (eregi('^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-]+\.[a-zA-Z0-9_\-\.]+$', $email))
    {
    header('location: success.php');
    }
    else
    {
    header('location: fail.php');
    }

    ?>[/PHP]where does the php code go with the html code?


  • Advertisement
  • Registered Users Posts: 339 ✭✭spoonface


    Fergaloc wrote: »
    if i have the email box and submit button with this code

    [HTML]<form name="form1" method="POST" action="thankyou.php.php">
    <input type="text" name="email" />
    <input type="submit" value="Sign Up" />
    </form>[/HTML]and the php code

    [PHP]<?php
    if (isset($_POST))
    $email = $_POST;
    else
    die("Email address not posted!");
    if (eregi('^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-]+\.[a-zA-Z0-9_\-\.]+$', $email))
    {
    header('location: success.php');
    }
    else
    {
    header('location: fail.php');
    }

    ?>[/PHP]where does the php code go with the html code?

    The HTML is on your first page before they click submit and then the action page (thankyou.php.php in your case) will consist of nothing but the above PHP code (and make sure there's no spaces or blank lines at the very bottom or top of the page or the redirect won't work). It might be worth getting yourself a book on basic web protocols etc or even a basic PHP book (e.g. Programming PHP, O'Reilly press).


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Yes as said above...it will just be a php page and also as said above, you cannot print anything to browser using prints or even white space before the <?php or the HTTP headers will be sent and redirection won't occur :)

    So you have:

    htmlpage.php (with html above)
    confirmation.php (that contains the above php code, the form must POST to this file)
    success.php (can be a normal HTML page that says correct email)
    fail.php (can be a normal HTML page that lets the user know if the email they entered is incorrect.

    But you can place all this in confirmation.php and do a if else etc without headers.


  • Registered Users Posts: 67 ✭✭Fergaloc


    i tried it but every time i entered a non valid email like fdsfh and a valid one like dsaa@gmail.com , it just send confirmation.php and said "Email address not posted!" when any one of them was entered


Advertisement