• home
  • forum
  • my
  • kt
  • download
  • Building Feedback Form with php

    Author: 2008-08-24 10:15:56 From:

    Here we are going to create a feedback form for you site to allow users contact you.
    The script is very simple and this article is for php begginers. we have to follow following steps for that.

    Design a Feedback Form
    The first thing we need to do is to design the feedback form. following piece code will build a form for you. here i am going to save it in html file say, feedback.html.

    <form  name=“frmFeedback” method=“post” action=“sendmail.php”>
    <fieldset class=“repeat”>
    <legend>Feedback…</legend>
    <label class=“preField”>
    Name:
    <input name=“name” type=“text” />
    </label>
    <label class=“preField”>Email:
    <input name=“email” type=“text” />
    </label>
    <label class=“preField”>Message:<br />
    <textarea name=“message” rows=“8″ cols=“40″>
    </textarea></label>
    <input type=“button” value=“Submit” onClick=“return vldFrm_Feedback();”/>
    </fieldset>
    </form>

    Basically the form asks a visitor for his Name, email address and message, and presents him with a button which he can click to submit the contents of the form.
    When the form is submitted, it is “posted” (see the “method” attribute of the tag) to “sendmail.php”.

    Improve look of feedback form
    i have apply CSS on above code to improve its look. See look of form below…

    You can get greate ideas to apply CSS on forms at http://www.formassembly.com/
    and the CSS code is as followes…

    <style type=“text/css” media=“all” >
    form {
            padding: 10px;
            font-family: ‘Trebuchet MS’, ‘Lucida Grande’, Verdana, Arial, Sans-Serif;
            background-color:#F8F8F6;
            background-image: url(formBg.png);
            border: 1px dotted #878177;     
    }
    fieldset {
            margin: 20px 0;
            padding: 15px 10px;
            background-color:#F4F4F2;
            border: 3px double #878177;     
    }
    legend {
            padding: 2px 5px;
            color: #1C1C1C;
            background-color: #FFD;
            border: 1px solid #878177;
    }
    label.preField {
            display: block;
            padding: 2px;
            margin: 0.4em 4px 0 0;
            font-weight: bold;
    }

    </style>

    Validating form Input
    As user fill form and send it, we are going to validate input to confirm that user not sending a blank form.
    on onClick event of submit button we are going to call Javascript function vldFrm_Feedback() to validate our feedback form.
    following code will do it for you…

    <script type=“text/javascript”>
    function vldFrm_Feedback(){
            var result = true;
            var msg=“”;
           
            if (document.frmFeedback.name.value==“”) {
                            msg+=“Your Name please !\n;
                            result = false;
                            }
            if (document.frmFeedback.email.value==“”) {
                            msg+=“Your Email please !\n;
                            result = false;
                            }
            if (document.frmFeedback.message.value==“”) {
                            msg+=“Your Message is Required !”;
                            result = false;
                            }
           
            if(msg==“”){
            return result;
            }{
            alert(msg)
            return result;
            }
    }
    </script>

    Process the form using PHP
    Now all that remains is to code “sendmail.php”. This is made extremely easy by the facilities available in PHP. Type the following code into a file named “sendmail.php”.

    <?php
    $Name = $_POST[‘name’] ;
    $email = $_POST[‘email’] ;
    $message = $_POST[‘message’] ;

    $message1=“You have new feedback from”.$Name.“<br /><br />”.$message.“”;

    mail( “youremail@example.com”, “Feedback Form…”, $message1, “From: $email” );
    echo‘Thanks You for your feedback…<a href="feedback.html" title="Back to Feedback form…">Back</a>’
    ?>

    Here you change youremail@example.com with email on which you want to get user feedback…

    Source code
    Download Source code for ‘building Feedback Form with php’
    Download

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (6)
      Discussion Boards (7)
      E Commerce (6)
      Email Systems (9)
      Error Handling (5)
      File Manipulation (10)
      Flash and PHP (4)
      Form Processing (13)
      Guestbooks (12)
      Image Manipulation (21)
      Installing PHP (7)
      Introduction to PHP (24)
      Link Indexing (8)
      Mailing List Management (9)
      Miscellaneous (54)
      Networking (8)
      News Publishing (9)
      OOP (24)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (6)
      Postcards (1)
      Randomizing (14)
      Redirection (11)
      Searching (9)
      Security (29)
      Site Navigation (16)
      User Authentication (14)
      WAP and WML (7)
      Web Fetching (8)
      Web Traffic Analysis (15)
      XML and PHP (16)

    New

    Hot