Help making a Q&A form?

Discussion in 'Programming/Html' started by sava700, May 24, 2012.

  1. sava700

    sava700 Ancient Guru

    Messages:
    4,862
    Likes Received:
    0
    GPU:
    EVGA 1080GTX FWT
    I'm looking for someone that knows how to setup a basic HTML layout that will use a php file or not in which there will be 10 Questions. The boxes for text will be of enough to put in a few sentences as needed to place answers in and once these answers are all filled in click Submit and it sends the questions along side the results to an email of my choice.

    I've set up a few feedback forms from templates I've found online but editing them so far has drove me nuts as the form doesn't seem to be sending. If you know how to do this please PM me...you can just put in temp questions and a temp email I'll edit them later.
    I only need a total of 10 Question slots

    This is basically going to be used on a site that has full up to date php versions etc etc..so don't worry about that.
    Thanks
     
    Last edited: May 24, 2012
  2. Tat3

    Tat3 Ancient Guru

    Messages:
    11,487
    Likes Received:
    0
    GPU:
    HIS R9 380 4gb
  3. sava700

    sava700 Ancient Guru

    Messages:
    4,862
    Likes Received:
    0
    GPU:
    EVGA 1080GTX FWT
    yeah, no not what I had in mind. I mean I can make a site that's not an issue. I'm having trouble with this form is the problem. I've made the form and the php file to process or email it to me but its not sending so I figured either 1) someone knew how to quickly make one or had one I could just edit to work for my needs or knew of a place with a free example of both files I could also edit to work for my needs.

    I don't need to learn it I'm just having trouble with it and I'm beyond frustrated so I've come to my fellow guru's for a quick solution.
     
  4. Anarion

    Anarion Ancient Guru

    Messages:
    12,940
    Likes Received:
    9
    GPU:
    EVGA GeForce GTX 1070 ACX
    HTML:
    <form action="controller.php" method="post">
    <p>First question?</p>
    <textarea name="text1"></textarea>
    <p>Second question?</p>
    <textarea name="text2"></textarea>
    ...
    <p>Tenth question?</p>
    <textarea name="text10"></textarea>
    <button type="submit" name="sendbtn" >Send</button>
    </form>
     

  5. Tat3

    Tat3 Ancient Guru

    Messages:
    11,487
    Likes Received:
    0
    GPU:
    HIS R9 380 4gb
    Post the problematic code here from both files so we can have a look.
     
  6. sava700

    sava700 Ancient Guru

    Messages:
    4,862
    Likes Received:
    0
    GPU:
    EVGA 1080GTX FWT
    sure here ya go:

    This is the html file named - Tier2Application.html

    Code:
    <form name="htmlform" method="post" action="html_form_send.php">
    <table width="450px">
    </tr>
    <tr>
     <td valign="top">
      <label for="age">What is your age? </label>
     </td>
     <td valign="top">
      <input  type="text" name="age" maxlength="50" size="30">
     </td>
    </tr>
     
    <tr>
     <td valign="top"">
      <label for="Time_Zone">What Time Zone/Country do you live in? </label>
     </td>
     <td valign="top">
      <input  type="text" name="Time_Zone" maxlength="50" size="30">
     </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="Extra_abilities">What other servers do you currently have extra abilities with ie: VIP, Donator, Admin etc etc? </label>
     </td>
     <td valign="top">
      <textarea  type="text" name="Extra_abilities" maxlength="1000" cols="25" rows="6"></textarea>
     </td>
     
    </tr>
    <tr>
     <td valign="top">
      <label for="position">Tell us why you think you should hold this position.</label>
     </td>
     <td valign="top">
      <textarea  type="text" name="position" maxlength="1000" cols="30" rows="6"></textarea>
     </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="dedicate">How much time do you dedicate to our Servers in a week?</label>
     </td>
     <td valign="top">
      <input  name="dedicate" maxlength="70" size="30">
     </td>
     <tr>
     <td valign="top">
      <label for="improve">Tell us how you could help us to improve our community and servers.</label>
     </td>
     <td valign="top">
      <textarea  type="text" name="improve" maxlength="1000" cols="30" rows="6"></textarea>
     </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="Opinion">What do you think of the servers at this time?</label>
     </td>
     <td valign="top">
      <textarea  type="text" name="Opinion" maxlength="1000" cols="30" rows="6"></textarea>
     </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="Duration">How long have you been a part of this function?</label>
     </td>
     <td valign="top">
      <textarea  type="text" name="Duration" maxlength="1000" cols="30" rows="6"></textarea>
     </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="Rep_Thread">Do you have a site? If so please provide URL.</label>
     </td>
     <td valign="top">
      <textarea  type="text" name="Rep_Thread" maxlength="1000" cols="30" rows="6"></textarea>
     </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="populate">What suggestions would you give to enhance the servers to help populate them more?</label>
     </td>
     <td valign="top">
      <textarea  type="text" name="populate" maxlength="1000" cols="30" rows="6"></textarea>
     </td>
    </tr>
     
    </tr>
    <tr>
     <td colspan="2" style="text-align:center">
      <input type="submit" value="Submit">   ( <a href="http://www.none.com">none</a> )
     </td>
    </tr>
    </table>
    </form>
    here is the php file named html_form_send.php

    Code:
    <?php
    if(isset($_POST['email'])) {
         
        // CHANGE THE TWO LINES BELOW
        $webmaster_email = "Mysite@mysite.com";
         
        $email_subject = "Tier2 Application";
         
         
        function died($error) {
            // your error code can go here
            echo "We are very sorry, but there were error(s) found with the form you submitted. ";
            echo "These errors appear below.<br /><br />";
            echo $error."<br /><br />";
            echo "Please go back and fix these errors.<br /><br />";
            die();
        }
         
        // validation expected data exists
        if(!isset($_POST['age']) ||
            !isset($_POST['Time_Zone']) ||
            !isset($_POST['Extra_abilities']) ||
            !isset($_POST['position']) ||
            !isset($_POST['dedicate']) ||
    		!isset($_POST['improve']) ||
    		!isset($_POST['Opinion']) ||
    		!isset($_POST['Duration']) ||
    		!isset($_POST['Rep_Thread']) ||
    		!isset($_POST['populate'])) {
            died('We are sorry, but there appears to be a problem with the form you submitted.');      
        }
         
        $age = $_POST['age']; // required
        $Time_Zone = $_POST['Time_Zone']; // required
        $Extra_abilities = $_POST['Extra_abilities']; // required
        $position = $_POST['position']; // required
        $dedicate = $_POST['dedicate']; // required
    	$improve = $_POST['improve']; // required
    	$Opinion = $_POST['Opinion']; // required
    	$Duration = $_POST['Duration']; // required
    	$Rep_Thread = $_POST['Rep_Thread']; // required
    	$populate = $_POST['populate']; // required
         
        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    
      }
      if(strlen($error_message) > 0) {
        died($error_message);
      }
        $email_message = "Form details below.\n\n";
         
        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        }
         
        $email_message .= "First Name: ".clean_string($first_name)."\n";
        $email_message .= "Last Name: ".clean_string($Time_Zone)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "position: ".clean_string($position)."\n";
        $email_message .= "dedicate: ".clean_string($dedicate)."\n";
    	$email_message .= "improve: ".clean_string($improve)."\n";
        $email_message .= "Opinion: ".clean_string($Opinion)."\n";
    	$email_message .= "Duration: ".clean_string($Duration)."\n";
    	$email_message .= "Rep_Thread: ".clean_string($Rep_Thread)."\n";
    	$email_message .= "populate: ".clean_string($populate)."\n";
         
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers); 
    ?>
     
    <!-- place your own success html below -->
     
    Thank you for the application. We will be in touch with you very soon.
     
    <?php
    
    die();
    ?>
     
  7. sava700

    sava700 Ancient Guru

    Messages:
    4,862
    Likes Received:
    0
    GPU:
    EVGA 1080GTX FWT
    anyone figure out the error here?
     
  8. sava700

    sava700 Ancient Guru

    Messages:
    4,862
    Likes Received:
    0
    GPU:
    EVGA 1080GTX FWT
    Well this got moved I hope someone here sees it
     
  9. Nato.dbnz

    Nato.dbnz Ancient Guru

    Messages:
    3,264
    Likes Received:
    0
    GPU:
    5870 Crossfire
    There were errors all over the place but your main one is that your first line of php is checking POST for a variable that doesn't exist. You also set up the variable for $webmaster_email and then use the variable $email_to to try and send. These files now work.

    Code:
    <?php
    if(isset($_POST['age'])) {
         
        // CHANGE THE TWO LINES BELOW
        $email_to = "";
         
        $email_subject = "Tier2 Application";
         
         
        function died($error) {
            // your error code can go here
            echo "We are very sorry, but there were error(s) found with the form you submitted. ";
            echo "These errors appear below.<br /><br />";
            echo $error."<br /><br />";
            echo "Please go back and fix these errors.<br /><br />";
            die();
        }
         
        // validation expected data exists
        if(!isset($_POST['age']) ||
            !isset($_POST['Time_Zone']) ||
            !isset($_POST['Extra_abilities']) ||
            !isset($_POST['position']) ||
            !isset($_POST['dedicate']) ||
    		!isset($_POST['improve']) ||
    		!isset($_POST['Opinion']) ||
    		!isset($_POST['Duration']) ||
    		!isset($_POST['Rep_Thread']) ||
    		!isset($_POST['populate'])) {
            died('We are sorry, but there appears to be a problem with the form you submitted.');      
        }
         
        $age = $_POST['age']; // required
        $Time_Zone = $_POST['Time_Zone']; // required
        $Extra_abilities = $_POST['Extra_abilities']; // required
        $position = $_POST['position']; // required
        $dedicate = $_POST['dedicate']; // required
    	$improve = $_POST['improve']; // required
    	$Opinion = $_POST['Opinion']; // required
    	$Duration = $_POST['Duration']; // required
    	$Rep_Thread = $_POST['Rep_Thread']; // required
    	$populate = $_POST['populate']; // required
         
        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    
      }
      if(strlen($error_message) > 0) {
        died($error_message);
      }
        $email_message = "Form details below.\n\n";
         
        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        }
         
        $email_message .= "First Name: ".clean_string($first_name)."\n";
        $email_message .= "Last Name: ".clean_string($Time_Zone)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "position: ".clean_string($position)."\n";
        $email_message .= "dedicate: ".clean_string($dedicate)."\n";
    	$email_message .= "improve: ".clean_string($improve)."\n";
        $email_message .= "Opinion: ".clean_string($Opinion)."\n";
    	$email_message .= "Duration: ".clean_string($Duration)."\n";
    	$email_message .= "Rep_Thread: ".clean_string($Rep_Thread)."\n";
    	$email_message .= "populate: ".clean_string($populate)."\n";
         
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers); 
    ?>
     
    <!-- place your own success html below -->
     
    Thank you for the application. We will be in touch with you very soon.
     
    <?php
    
    die();
    ?>
    
    Code:
    <html>
    <form name="htmlform" method="post" action="send_form.php">
    <table width="450px">
    <tr>
     <td valign="top">
      <label for="age">What is your age? </label>
     </td>
     <td valign="top">
      <input  type="text" name="age" maxlength="50" size="30">
     </td>
    </tr>
     
    <tr>
     <td valign="top">
      <label for="Time_Zone">What Time Zone/Country do you live in? </label>
     </td>
     <td valign="top">
      <input  type="text" name="Time_Zone" maxlength="50" size="30">
     </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="Extra_abilities">What other servers do you currently have extra abilities with ie: VIP, Donator, Admin etc etc? </label>
     </td>
     <td valign="top">
      <textarea  type="text" name="Extra_abilities" maxlength="1000" cols="25" rows="6"></textarea>
     </td>
     
    </tr>
    <tr>
     <td valign="top">
      <label for="position">Tell us why you think you should hold this position.</label>
     </td>
     <td valign="top">
      <textarea  type="text" name="position" maxlength="1000" cols="30" rows="6"></textarea>
     </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="dedicate">How much time do you dedicate to our Servers in a week?</label>
     </td>
     <td valign="top">
      <input  name="dedicate" maxlength="70" size="30">
     </td>
     <tr>
     <td valign="top">
      <label for="improve">Tell us how you could help us to improve our community and servers.</label>
     </td>
     <td valign="top">
      <textarea  type="text" name="improve" maxlength="1000" cols="30" rows="6"></textarea>
     </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="Opinion">What do you think of the servers at this time?</label>
     </td>
     <td valign="top">
      <textarea  type="text" name="Opinion" maxlength="1000" cols="30" rows="6"></textarea>
     </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="Duration">How long have you been a part of this function?</label>
     </td>
     <td valign="top">
      <textarea  type="text" name="Duration" maxlength="1000" cols="30" rows="6"></textarea>
     </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="Rep_Thread">Do you have a site? If so please provide URL.</label>
     </td>
     <td valign="top">
      <textarea  type="text" name="Rep_Thread" maxlength="1000" cols="30" rows="6"></textarea>
     </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="populate">What suggestions would you give to enhance the servers to help populate them more?</label>
     </td>
     <td valign="top">
      <textarea  type="text" name="populate" maxlength="1000" cols="30" rows="6"></textarea>
     </td>
    </tr>
     
    </tr>
    <tr>
     <td colspan="2" style="text-align:center">
      <input type="submit" value="submit">
     </td>
    </tr>
    </table>
    </form>
    </html>
    
    The php now checks for the POST variable age but you can change that to any variable that exists on the form.
     
  10. Nato.dbnz

    Nato.dbnz Ancient Guru

    Messages:
    3,264
    Likes Received:
    0
    GPU:
    5870 Crossfire
    Also this bit:

    Code:
     $email_message .= "First Name: ".clean_string($first_name)."\n";
        $email_message .= "Last Name: ".clean_string($Time_Zone)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "position: ".clean_string($position)."\n";
        $email_message .= "dedicate: ".clean_string($dedicate)."\n";
    	$email_message .= "improve: ".clean_string($improve)."\n";
        $email_message .= "Opinion: ".clean_string($Opinion)."\n";
    	$email_message .= "Duration: ".clean_string($Duration)."\n";
    	$email_message .= "Rep_Thread: ".clean_string($Rep_Thread)."\n";
    	$email_message .= "populate: ".clean_string($populate)."\n";
    Needs to be updated to reflect the variables in your form or else the info will come through mislabelled on the email. So you need to put age, timezone, extra abilities etc in here.
     

  11. kabusuti

    kabusuti Member

    Messages:
    11
    Likes Received:
    0
    GPU:
    ATI Radeon
    That's true.
     
  12. johnhendricks

    johnhendricks Member

    Messages:
    14
    Likes Received:
    0
    GPU:
    50
    Various sites are available online, refer this sites and find the actual solution.
     

Share This Page