SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard Blake Tallos's Avatar
    Join Date
    Jun 2008
    Location
    Cuyahoga Falls, Ohio.
    Posts
    1,510
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating a form in PHP

    Code HTML4Strict:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <style type="text/css">
    input {
        margin:5px;
        border:#6d84b4 solid 1px;
     
     
    }
    #website {
        float:left;
        margin-left:14px;
    }
    .clearer {
        clear:both;
    }
    textarea {
        margin-left:81px;
        width:500px;
        height:200px;
        border:#6d84b4 solid 1px;
    }
    #file {
        margin-left:81px;
    }
    .upload {
        margin-left:81px;
    }
     
    </style>
    </head>
    <body>
    Your Name:<input type="text" name="firstname" size="30" id="firstname"><span id="website">Website:</span><input type="text" name="firstname" size="50" id="website"><br>
    <div class="clearer"></div>
    <textarea id="form">Leave me a Message:</textarea><br>
    <p class="upload">Upload, dat file sonn!</p>
    <input type="file" id="file">
    </body>
    </html>

    Code PHP:
    <?php
     
    $firstname = $firstname';
    $website = '$website';
    $form = '$form';
    $to ='someone@somewhere.com'; 
    if($send_contact){
    echo "We've recived your contact information";
    }
    else {
    echo "ERROR";
    }
    ?>
    For some reason my script isnt working? Can anyone help me on this? What am I doing wrong?
    Blake Tallos - Software Engineer for Sanctuary
    Software Studio, Inc. C# - Fanatic!
    http://www.sancsoft.com/


  2. #2
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My php skills are fairly limited, but I have never seen anything like that before. Why don't you have a <form> wrapped around your, well, your form? With action set to GET or POST? Then I don't really see how you populate your php variables? the very first line seems to be incorrect already, just one single quote after $firstname. But it doesn't stop there, where is $send_contact coming from?

    Either this is a new form of php form-handling I've never seen before, or you need to be doing some php tutorials: http://www.tizag.com/phpT/forms.php

  3. #3
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. add name="form" to textarea
    2. add <input type="submit" value="Send" name="send_contact" />
    3. You need a <form method="post" action="link_to_file.php" />
    4. You have to have the form action link to the data where the php below is..
    5. and an </form> tag after the end of the form.

    PHP Code:
    <?php
     
    // Your settings
    $to 'someone@somewhere.com';
    $subject 'My Website Form';


    // Grab the Form Data
    $firstname $_POST['firstname'];
    $website $_POST['website'];
    $form $_POST['form'];

    // Put the Form Data into one String
    $body $firstname ."\r\n"$website ."\r\n"$form;

    if(isset(
    $_POST['send_contact'])) {

        
    mail($to$subject$body);
        echo 
    "We've recived your contact information";

        }

        else {
        echo 
    "ERROR";
        }
    ?>


Bookmarks

Posting Permissions

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