+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: php form

  1. #1
    garrensilverwing's Avatar
    garrensilverwing is offline x10 Sophmore garrensilverwing is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    148

    php form

    After reading a few tutorials I wanted to give PHP a try. I want to write a php code that will verify the contents of a form submited (http://www.brianwallchess.x10hosting.com/advertise.htm)
    and then mail them to me at my email address. I do not want the form emailed to me if it is not valid however here is the code that I have already but all I get is a blank page when I run it.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Advertising Application Validation</title>
    </head>
    <body>
    <p style="color: red;">
    <?php
    $firstname = $_REQUEST['firstname'] ;
    $lastname = $_REQUEST['lastname'] ;
    $email = $_REQUEST['email'] ;
    $emailchk = $_REQUEST['verifyemail'] ;
    $business = $_REQUEST['business'] ;
    $text = $_REQUEST['text'] ;
    $graphic = $_REQUEST['graphic'] ;
    $yes = $_REQUEST['yes'] ;
    $no = $_REQUEST['no'] ;
    $dlink = $_REQUEST['dlink'] ;
    $impress = $_REQUEST['impress'] ;
    
    if ($firstname == "")
    {echo("Please enter your first name.");}
    if ($lastname == "")
    {echo ("Please enter your last name.");}
    if ($email == "")
    {echo ("Please enter your email address.");}
    if ($isValid == "false")
    {echo ("The email address you have entered is not valid.");}
    if ($email ==! $emailchk)
    {echo ("The email addresses you have entered do not match.");}
    if ($business == "")
    {echo ("Please enter the name of your business or website.");}
    if ($yes == "0")
    {echo ("Only authorized people may submit this application.");}
    else{
    mail( "garrensilverwing@yahoo.com", "$business Advertising Application",
    "Name: $firstname $lastname Email: $email Website or Business: $business Authorized: $yes $no Text: $text Graphic: $graphic Type: $dlink $impress", "From: $email" );
    echo ("Thank you for submitting your application");}
    ?>
    </p>
    </body>
    </html>
    Last edited by garrensilverwing; 04-27-2009 at 02:30 PM.

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: php form

    you can use the [ code ]code goes here[ /code ] (remove spaces to use)

    the very last curly brace } doesn't match up with anything.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    garrensilverwing's Avatar
    garrensilverwing is offline x10 Sophmore garrensilverwing is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    148

    Re: php form

    i added an else at the end but still only get a blank page. I want it to display the error message for whichever if statement comes back false but just a blank page i think i am missing something important

  4. #4
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: php form

    It's your mail function.

    http://w3schools.com/php/php_mail.asp

    I don't really know how you would fix it. haha. too complicated of a form.
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  5. #5
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: php form

    it works for me on my test server:

    Please enter your first name.Please enter your last name.Please enter your email address.Please enter the name of your business or website.
    Thank you for submitting your application
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  6. #6
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    Re: php form

    I just thought i would add my two cents. I personally use javascript to verify the contents of the form before submission is sent.

    Example

    Code:
    function checkForm(frm){
    msg = "";
       if(!frm.Name.value){
          msg += "- Please fill in your full name\n";
       }
       if(!frm.Email.value){
          msg += "- Please fill in your email address\n";\
       }
       if(msg != ""){
          alert(msg);
          return false;
       }
    }
    add this to form tag
    Code:
    onsubmit='return checkForm(this)'

  7. #7
    jhilldesigns is offline x10Hosting Member jhilldesigns is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    1

    Re: php form

    Yeah I would also do java validation - no page reload saves server load

  8. #8
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: php form

    pure html page reload adds very little to server load, but it is much faster for the user if javascript pops up an error right away. It's not that easy to learn another programming language though, especially one as tricky as JS DOM.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  9. #9
    garrensilverwing's Avatar
    garrensilverwing is offline x10 Sophmore garrensilverwing is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    148

    Re: php form

    well the main reason why i am doing it with php is so i can get some hands-on experience with it because i want to evolve my website into one that uses php for log in and stuff like that
    anyway -- i put it onto my webserver and it works by showing the text that i put in however it still isnt mailing :'( i put in the new mail to code leafypiggy suggested so i will see if it mails to me now
    Code:
    <p style="color: red;">
    <?php
    $firstname = $_REQUEST['firstname'] ;
    $lastname = $_REQUEST['lastname'] ;
    $email = $_REQUEST['email'] ;
    $emailchk = $_REQUEST['verifyemail'] ;
    $business = $_REQUEST['business'] ;
    $text = $_REQUEST['text'] ;
    $graphic = $_REQUEST['graphic'] ;
    $yes = $_REQUEST['yes'] ;
    $no = $_REQUEST['no'] ;
    $dlink = $_REQUEST['dlink'] ;
    $impress = $_REQUEST['impress'] ;
    if ($firstname == "")
    {echo("Please enter your first name.");}
    if ($lastname == "")
    {echo ("Please enter your last name.");}
    if ($email == "")
    {echo ("Please enter your email address.");}
    if ($isValid == "false")
    {echo ("The email address you have entered is not valid.");}
    if ($email ==! $emailchk)
    {echo ("The email addresses you have entered do not match.");}
    if ($business == "")
    {echo ("Please enter the name of your business or website.");}
    if ($yes == "1")
     {$to = "garrensilverwing@yahoo.com";
     $subject = "$business Advertising Application";
     $message = "$firstname $lastname from $business: $text, $graphic, $dlink, $impress";
     $from = "$email";
     $headers = "From: $from";
     mail($to,$subject,$message,$headers);
     echo "Thank you for submitted your applicatoin.";}
     else{echo ("Only authorized people may submit this application.");}
    ?>
    </p>

  10. #10
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: php form

    You can also use filter_var_array to validate and sanitize user input. A loop (such as a for or foreach loop) will help cut down on repeated code (all the "if" branches).

    The return value of mail() might be helpful. If mail() returns false, the message was never accepted for delivery. Be aware that if it returns true, the mail won't necessarily be received. Others have been having problems with spam filters; it appears x10 was exploited in the past by spammers.

    A well designed form will be validated both client- and server-side: client side so the user gets immediate feedback and server side to protect your site. The best forms use inline validation feedback on the client side (the link doesn't cover changing the error message or choosing where to place the message; accessibility requirements might make you put the message in the <label> element).

    A note about field names: there is no 'no' input in your form ($_REQUEST['no'] won't be defined), and the 'dlink' and 'impress' fields are named 'directlink' and 'impression' in the form.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Javascript form to PHP
    By driveflexfuel in forum Programming Help
    Replies: 2
    Last Post: 10-16-2008, 06:25 PM
  2. currently have an application pending php
    By biomasti in forum Free Hosting
    Replies: 1
    Last Post: 09-03-2008, 01:58 PM
  3. php contact form in flash not working.
    By eddbrown in forum Free Hosting
    Replies: 2
    Last Post: 08-13-2008, 03:16 PM
  4. Easy XHTML form validation using PHP
    By Xemnas in forum Tutorials
    Replies: 0
    Last Post: 01-08-2008, 04:29 AM
  5. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers