main
side
curve
  1. In Memory of LAJ_FETT: Please share your remembrances and condolences HERE

Php Tutorial: Feedback form

Discussion in 'Archive: Fan Sites' started by Rox , Jan 31, 2003.

Thread Status:
Not open for further replies.
  1. Rox

    Rox Administrator Emeritus star 6 VIP - Former Mod/RSA

    Registered:
    Nov 24, 2000
    This is a short tutorial that may be very helpful to someone who has no idea on how to make simple custom feedback form for thier website.

    For this tutorial you will need 3 things:
    - Notepad (or your favorite HTML editor)
    - basic knowledge of HTML
    - Some web space to test this out.

    Ok, step number 1 is to create a new file. In that file paste this code:

    <form method=post action="redirect.php"><table width="300" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="100">Your Name:</td>
    <td width="200">
    <input type="text" name="name">
    </td>
    </tr>
    <tr>
    <td width="100">Your E-mail:</td>
    <td width="200">
    <input type="text" name="email">
    </td>
    </tr>
    <tr>
    <td width="100" valign="top">Your Message:</td>
    <td width="200">
    <textarea name="message"></textarea>
    </td>
    </tr>
    <tr>
    <td width="100">&nbsp;</td>
    <td width="200">
    <input type="submit" name="Submit" value="Send Form">
    </td>
    </tr>
    </table>
    </form>

    Save this file as anything you want, I named mine contact.php.

    The next step is to create the redirect.php file. This will redirect the user to your home page once the form has been sent.

    <?php
    if($sentemail == "2"){
    include("sorry.php");

    }else{

    $num = $sentmessage + 1;
    setcookie("sentemail","$num",time()+1000); //set the cookie

    $email = "Sender Name:\t$name\nSender E- Mail:\t$email\nMessage:\t$message\nIP:\t$RE
    MOTE_ADDR\n\n";
    $to = "your email address goes here";
    $subject = "Feedback For My Website";
    $mailheaders = "From: $email <> \n";
    $mailheaders .= "Reply-To: $thereemail\n\n";
    mail($to, $subject, $email, $mailheaders);
    include("http://url to_your_website");
    }
    ?>

    Save this file as redirect.php.

    In this file there is this bit of code:

    <?php
    if($sentemail == "2"){
    include("sorry.php");

    }else{

    $num = $sentmessage + 1;
    setcookie("sentemail","$num",time()+1000); //set the cookie

    The +1000 is the time in seconds of how long until the cookie expires. You can edit this to what you want. You can also edit the if($sentemail == "2") to the number of your choice. This changes how many emails the user is allowed to send before they are sent to sorry.php.

    Now onto your last file, sorry.php. It basically tells the person that the have used the up the amount of messages they can send you, it also helps stop spamming.

    You can put what ever you want here. Just remember to be polite and have a link to your homepage. A short explanation why they cannot use the form at the moment helps as well.
     
  2. Aanix_Durray

    Aanix_Durray Jedi Padawan star 4

    Registered:
    Dec 29, 2001
    This will be really helpful Rox, thanx :)





    -~Aanix~-
     
  3. Rox

    Rox Administrator Emeritus star 6 VIP - Former Mod/RSA

    Registered:
    Nov 24, 2000
    You are welcome. I am gonna try and do a tutorial a week for the month of febraury.

    Edit: Forgot to mention that this is a variation of a a script I got off of hot scripts.com
     
  4. AERYN_SUN

    AERYN_SUN Jedi Knight star 5

    Registered:
    Apr 1, 2001
    i've been trying to figure out the code for submission forms, (i have now) but this is great, incase i have a problem with mine.
     
  5. Valiowk

    Valiowk Chosen One star 6

    Registered:
    Apr 23, 2000
    Just a short question, Rox: How should the code for "sorry.php" be written? Can it be written like normal HTML code, or does it have to have a special form?
     
    Jedi Knight Fett likes this.
  6. AERYN_SUN

    AERYN_SUN Jedi Knight star 5

    Registered:
    Apr 1, 2001
    actually, i thought i had it figured out. but the only thing i figured was how to make it pretty. here's the new form. what i need to know now is where to put the 'redirct' code.

    <center>
    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    var submitcount=0;

    function reset() {
    document.emailform.name.value="";
    document.emailform.email.value="";
    document.emailform.comments.value="";
    }

    function checkFields() { // field validation -
    if ( (document.emailform.name.value=="") || // checks if fields are blank.
    (document.emailform.email.value=="") || // More validation scripts at
    (document.emailform.comments.value=="") ) // forms.javascriptsource.com
    {
    alert("Please enter your name, email, and comments then re-submit this form.");
    return false;
    }

    else
    {
    if (submitcount == 0)
    {
    submitcount++;
    return true;
    }
    else
    {
    alert("This form has already been submitted. Thanks!");
    return false;
    }
    }
    }
    // End -->
    </script>

    <TITLE></TITLE>
    </HEAD>
    <BODY>

    <BODY OnLoad="reset()">

    <form method=post action="http://cgi.freedback.com/mail.pl" name="emailform" onSubmit="return checkFields()">

    <input type=hidden name=to value="obikenobi_gurl@msn.com">
    <input type=hidden name=subject value="Fic/Poetry Submission Form">

    <pre>
    Pen Name: <input type=text name="pen">
    Email: <input type=text name="email">

    <textarea name="comments" wrap="virtual" rows="7" cols="45"></Textarea>

    <input type=submit value="Submit Form!">
    </center>
    </pre>
    </form>
    </BODY>
    </HTML>
     
Thread Status:
Not open for further replies.