Jump to content

Create a survey that is emailed via PHP


callie212

Recommended Posts

I am new to PHP. I am trying to create a survey for the website for my school magazine. I created the survey and the PHP file, but it doesn't seem to be working. I have tested it on 2 different servers. On the first server, I just get a blank page when it is submitted. On the second server, I get errors about the "header".

 

I really am so lost at this point and am about to give up on putting the survey on  the page. I set up a couple contact forms, which work, but this seems hard. The way I tried to do it is to call up a new HTML file with a thank you message rather than just an echo statement with a thank you. Then I have an error HTML file. The PHP code is in a separate file named processsurvey.php. Here is my code:

 

HTML CODE:

 

<table width="200" id="bodybox" name="bodybox" cellpadding="0" cellspacing="0">

    <tr>

    <td><p><em>How Are We Doing?</em></p>

      <p>Please answer these few questions so that we can better suit the needs of you, our valued readership.</p></td>

    <td> </td>

  </tr>

 

<tr>

      <td>

 

 

<form action="processsurvey.php" method="post" enctype="text/plain" name="survey" id="survey">

  <table width="603" border="0" cellspacing="5" cellpadding="5">

  <tr>

    <td><p>How often do you read the Factory Times?</p>

<p>

        <label>

          <input type="radio" name="howoften" value="radio" />

          Never</label>

        <br />

        <label>

          <input type="radio" name="howoften" value="radio" />

          Rarely</label>

        <br />

        <label>

          <input type="radio" name="howoften" value="radio" />

          Sometimes</label>

        <br />

        <label>

          <input type="radio" name="howoften" value="radio" />

          Often</label>

          </p></td>

    </tr>

  <tr>

    <td>Where do you get the Factory Times?

      <p>

        <label>

          <input type="checkbox" name="whereget" value="checkbox" />

          Donovan Hall</label>

        <br />

        <label>

          <input type="checkbox" name="whereget" value="checkbox" />

          Kunsela Hall</label>

        <br />

        <label>

          <input type="checkbox" name="whereget" value="checkbox" />

          Peter J. Cayan Library</label>

        <br />

        <label>

          <input type="checkbox" name="whereget" value="checkbox" />

          Campus Center</label>

        <br />

        <label>

          <input type="checkbox" name="whereget" value="checkbox" />

          Other <input name="whereget" type="text" id="whereget" />

          </label>

        <br />

        </p></td>

    </tr>

  <tr>

    <td>Where do you read the Factory Times most often?

      <p>

        <label>

          <input type="checkbox" name="whereread" value="checkbox" />

          Dining Hall</label>

        <br />

        <label>

          <input type="checkbox" name="whereread" value="checkbox" />

          In Class</label>

        <br />

        <label>

          <input type="checkbox" name="whereread" value="checkbox" />

          In Your Dorm</label>

        <br />

        <label>

          <input type="checkbox" name="whereread" value="checkbox" />

          At Home</label>

        <br />

        <label>

          <input type="checkbox" name="whereread" value="checkbox" />

          Other <input name="whereread" type="text" id="whereread" />

          </label>

        <br />

        </p></td>

    </tr>

  <tr>

    <td>What topics covered by the Factory Times interest you the most?

      <p>

        <label>

          <input type="checkbox" name="topicenjoy" value="checkbox" />

          Entertainment Reviews (music, movies ,video games)</label>

        <br />

        <label>

          <input type="checkbox" name="topicenjoy" value="checkbox" />

          Sharing with Sharon</label>

        <br />

        <label>

          <input type="checkbox" name="topicenjoy" value="checkbox" />

          Creative Writing</label>

        <br />

        <label>

          <input type="checkbox" name="topicenjoy" value="checkbox" />

          Sidebars ("Top 10's", quotes, jokes)</label>

        <br />

        <label>

          <input type="checkbox" name="topicenjoy" value="checkbox" />

          Informative Articles</label>

        <br />

        <label>

          <input type="checkbox" name="topicenjoy" value="checkbox" />

          Other <input name="topicenjoy" type="text" id="topics" />

          </label>

        <br />

        </p></td>

    </tr>

  <tr>

    <td><p>What is your least favorite type of content in the Factory Times?</p>      <p>

        <label>

          <input type="checkbox" name="leastfav" value="checkbox" />

          Entertainment Reviews (music, movies, video games)</label>

        <br />

        <label>

          <input type="checkbox" name="leastfav" value="checkbox" />

          Sharing with Sharon</label>

        <br />

        <label>

          <input type="checkbox" name="leastfav" value="checkbox" />

          Creative Writing</label>

        <br />

        <label>

          <input type="checkbox" name="leastfav" value="checkbox" />

          Sidebars ("Top 10's", qoutes, jokes)</label>

        <br />

        <label>

          <input type="checkbox" name="leastfav" value="checkbox" />

          Informative Articles</label>

        <br />

        <label>

          <input type="checkbox" name="leastfav" value="checkbox" />

          Other

          <input name="leastfav" type="text" id="leastfav" />

          </label>

        <br />

        </p></td>

    </tr>

  <tr>

    <td><p>What about the average layout and design of the issues?</p>      <p>

        <label>

          <input type="radio" name="design" value="radio" />

          Poor</label>

        <br />

        <label>

          <input type="radio" name="design" value="radio" />

          Mediocre</label>

        <br />

        <label>

          <input type="radio" name="design" value="radio" />

          Good</label>

        <br />

        <label>

          <input type="radio" name="design" value="radio" />

          Excellent</label>

        <br />

        </p></td>

    </tr>

  <tr>

    <td>Please tell us how we can improve.

      <p>

        <textarea name="howimprove" cols="30" rows="5" id="howimprove"> </textarea>

        <br />

        </p></td>

    </tr>

  <tr>

    <td><label>

      <input type="reset" name="Reset" value="Reset" />

      <input name="Submit" type="submit" id="Submit" value="Submit" />

    </label></td>

    </tr>

</table>

 

  </form>

 

      </td>

    </tr>

  </table> 

 

 

 

PHP CODE:

 

<?php

 

$mailto = 'email@factorytimes.com' ;

 

$subject = "Survey Form" ;

 

$formurl = "http://www.factorytimes.com/survey.html" ;

$errorurl = "http://www.factorytimes.com/error.html" ;

$thankyouurl = "http://www.factorytimes.com/thankyou.html" ;

 

$uself = 0;

 

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;

$howoften = $_POST['howoften'] ;

$whereget = $_POST['whereget'] ;

$whereread = $_POST['whereread'] ;

$topicenjoy = $_POST['topicenjoy'] ;

$leastfav = $_POST['leastfav'] ;

$design = $_POST['design'] ;

$howimprove = $_POST['howimprove'] ;

 

 

$http_referrer = getenv( "HTTP_REFERER" );

 

if (!isset($_POST['submit'])) {

header( "Location: $formurl" );

exit ;

}

if (empty($howoften) || empty($howoften) || empty($whereget) || empty($whereread) || empty($topicenjoy) || empty($leastfav) || empty($design)) {

  header( "Location: $errorurl" );

  exit ;

}

if (get_magic_quotes_gpc()) {

$howimprove = stripslashes( $howimprove );

}

 

$message =

 

"This message was sent from:\n" .

"$http_referrer\n" .

"------------------------------------------------------------\n" .

"How often do you read the Factory Times?:\n$howoften\n" .

"Where do you get the Factory Times?:\n$whereget\n" .

"Where do you read the Factory Times most often?:\n$whereread\n" .

"What topics covered by the Factory Times interest you the most? :\n$topicsenjoy\n" .

"What is your least favorite type of content in the Factory Times?:\n$leastfav\n" .

"What about the average layout and design of the issues?:\n$design\n" .

"------------------------------------------------------------\n\n" .

"Please tell us how we can improve.:\n$howimprove\n" .

"\n\n------------------------------------------------------------\n" ;

 

mail( $mailto, $subject, $message );

header( "Location: $thankyouurl" );

exit ;

 

?>

 

 

Link to comment
Share on other sites

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.

 

Try this..

Remove the line header( "Location: $thankyouurl" );

 

Replace it with...

echo "<meta http-equiv=\"REFRESH\" content=\"0;url=".$thankyouurl."\">";

Link to comment
Share on other sites

Ok.  Try doing a little trouble shooting to see if the information is even being passed to your page properly.

 

At the very bottom of you page comment out this line like this...

 

//echo "<meta http-equiv=\"REFRESH\" content=\"0;url=".$thankyouurl."\">";

 

Then on your page look for the line that says "$http_referrer = getenv( "HTTP_REFERER" );"

 

RIGHT ABOVE THAT ADD all of this code so you can see what the variable values are...

 

echo "<b>Just doing a little testing</b><br />\n";
echo "<b>How often: </b>".$howoften."<br />\n";
echo "<b>Where Get: </b>".$whereget."<br />\n";
echo "<b>Where Read: </b>".$whereread."<br />\n";
echo "<b>Topic Enjoy: </b>".$topicenjoy."<br />\n";
echo "<b>Least Fav: </b>".$leastfav."<br />\n";
echo "<b>Design: </b>".$design."<br />\n";
echo "<b>How Improve: </b>".$howimprove."<br />\n";

The above will then show you at that point on your page what is going on with the variables.  IF they have nothing then there is an issue with variable names and/or how they are being passed.  If they have something then there is an error in your code after that that is causing them not to be mailed out.

 

Echoing items to the screen is often a good way to see how the code is actually working.  In some cases I'll even put them inside of if statements so that I can tell what is going on.  EXAMPLE...

 

if ($a > $b)

{

  echo "It went to part ONE if statement";

}

 

else

{

  echo "It went to part TWO of the if statement";

}

Link to comment
Share on other sites

You need to change your html form.  There appear to be some errors in there in terms of the "value" variable.

 

Change these...

 

<label>
<input type="radio" name="howoften" value="radio" />
Never</label>
<label>
<input type="radio" name="howoften" value="radio" />
Rarely</label>
<label>
<input type="radio" name="howoften" value="radio" />
Sometimes</label>
<label>

 

To this...

<label>
<input type="radio" name="howoften" value="never" />
Never</label>
<label>
<input type="radio" name="howoften" value="rarely" />
Rarely</label>
<label>
<input type="radio" name="howoften" value="sometimes" />
Sometimes</label>
<label>

 

Note that you will have to do this with your ENTIRE form.  Not just this one section.  ALL of your "value" variables need to be set to something.

Link to comment
Share on other sites

I noticed that just a few minutes ago. I think it was a result of me attempting to build the form in Dreamweaver and not knowing what the heck Dreamweaver was trying to make me do.

 

So I changed the values in the entire form to read the correct value instead of just "radiobutton" or whatever it was. I still get the same blank answers.

Link to comment
Share on other sites

Ok.  Got it partially working.  There are lots of errors with your html coding...

 

1.  There seemed to be an issue with the (name="survey" id="survey") part of your form.  I removed that part and then started getting some of the values to come through.

 

Also for ALL of your check boxes...

 

You need to rename them.  You cannot have more than one check box with the same name.  You have 5 called "whereget" and 5 called "whereread" when each CHECKBOX needs to have a different name.  In the 1st section you have "radio" boxes (How often do you read the Factory Times?) and that is ok.  But when you have multi check boxes they need to have different names or the form will not be able to differ them.

 

ALSO you need to get rid of OR modify all of those "<label>" tags.

 

Change ALL of these...

<label>
        <input type="radio" name="howoften" value="never">
          Never</label>

 

OPTION #1 (remove them all)

completely REMOVE all "<label>" and "</label>" tags..
        <input type="radio" name="howoften" value="never">
          Never

 

OPTION #2 (id each one)

Put a seperate ID next to each item and make sure label tag does NOT surround input tag.
        <input type="radio" name="howoften" value="never" id="never_howoften">
          <label for="never_howoften">Never</label>

 

Link to comment
Share on other sites

Ok, I removed the form name and ID. I removed all label tags and renamed the names of each checkbox (and radio button to keep consistent).

 

I am not seeing any different results. Do I need to add all the new names to the PHP script now?

 

Here is the location: http://www.factorytimes.com/survey.php

 

Here is my new 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=ISO-8859-1" />

<title>Factory Times Survey</title>

<link href="stylesheet.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
.style2 {font-style: italic; font-size: 18px;}
-->
</style>
</head>

<body>
<div id="logoimg">"<img src="images/bgTOPforweb2.jpg" alt="background" width="1500" height="533" align="left" /></div>
<table width="200" id="menubox" name="menubox">
<tr>
<td colspan="3">
<ul id="nav">
<li><a href="index3.html">Home</a></li>
<li><a href="issues.html">Issues</a></li>
<li><a href="staff.html">Staff</a></li>
<li><a href="sharon.php">Sharon</a></li>
<li><a href="https://milo.cs.sunyit.edu/ftimes/index.php">Forum</a></li>
<li><a href="contact.php">Contact</a></li>
</ul></td>
</tr>
</table>
<form action="processsurvey.php" method="post" enctype="text/plain">
  <table width="603" id="bodybox" border="0" cellspacing="5" cellpadding="10">
  <tr>
    <td><p class="style2">How Are We Doing?</p> 
  <p>Please answer these few questions so that we can better suit the needs of you, our valued readership.</p></td>
    </tr>
  <tr>
    <td>
<p>How often do you read the Factory Times?</p>

     <p>
     <input type="radio" name="howoften_never" value="never">
          Never<br />
     <input type="radio" name="howoften_rarely" value="rarely" />
          Rarely<br />
     <input type="radio" name="howoften_sometimes" value="sometimes" />
          Sometimes<br />
     <input type="radio" name="howoften_often" value="often" />
          Often
     </p></td>
  </tr>
  <tr>
    <td>
<p>Where do you get the Factory Times?</p>

<p>
<input type="checkbox" name="whereget_donovan" value="donovan" />
          Donovan Hall<br />
    <input type="checkbox" name="whereget_kunsela" value="kunsela" />
          Kunsela Hall<br />
    <input type="checkbox" name="whereget_cayan" value="cayan" />
          Peter J. Cayan Library<br />
    <input type="checkbox" name="whereget_campusc" value="campusc" />
          Campus Center<br />
    <input type="checkbox" name="whereget_other" value="other" />
          Other <input name="whereget" type="text" id="whereget" /><br />
    </p></td>
    </tr>
  <tr>
    <td>
<p>Where do you read the Factory Times most often?</p>
      
  <p>
      <input type="checkbox" name="whereread_diningh" value="diningh" />
          Dining Hall<br />
      <input type="checkbox" name="whereread_class" value="class" />
          In Class<br />
      <input type="checkbox" name="whereread_dorm" value="dorm" />
          In Your Dorm<br />
      <input type="checkbox" name="whereread_home" value="home" />
          At Home<br />
      <input type="checkbox" name="whereread_other" value="other" />
          Other <input name="whereread" type="text" id="whereread" /><br />
      </p></td>
      </tr>
  <tr>
    <td> 
    <p>What topics covered by the Factory Times interest you the most?</p>
  
      <p>
  <input type="checkbox" name="topicenjoy_entertainment" value="entertainment" />
          Entertainment Reviews (music, movies ,video games)<<br />
      <input type="checkbox" name="topicenjoy_sharon" value="sharon" />
          Sharing with Sharon <br />
      <input type="checkbox" name="topicenjoy_creative" value="creative" />
          Creative Writing<br />
      <input type="checkbox" name="topicenjoy_sidebars" value="sidebars" />
          Sidebars ("Top 10's", quotes, jokes)<br />
      <input type="checkbox" name="topicenjoy_informative" value="informative" />
          Informative Articles<br />
      <input type="checkbox" name="topicenjoy_other" value="other" />
          Other <input name="topicenjoy" type="text" id="topics" /><br />
      </p></td>
    </tr>
  <tr>
    <td><p>What is your least favorite type of content in the Factory Times?</p>

	<p>
        <input type="checkbox" name="leastfav_entertainment" value="entertainment" />
          Entertainment Reviews (music, movies, video games)<br />
        <input type="checkbox" name="leastfav_sharon" value="sharon" />
          Sharing with Sharon<br />
        <input type="checkbox" name="leastfav_creative" value="creative" />
          Creative Writing<br />
        <input type="checkbox" name="leastfav_sidebars" value="sidebars" />
          Sidebars ("Top 10's", quotes, jokes)<br />
        <input type="checkbox" name="leastfav_informative" value="informative" />
          Informative Articles<br />
        <input type="checkbox" name="leastfav_other" value="other" />
          Other <input name="leastfav" type="text" id="leastfav" /><br />
        </p></td>
    </tr>
  <tr>
    <td><p>What about the average layout and design of the issues?</p>

	<p>
        <input type="radio" name="design_poor" value="poor" />
          Poor<br />
        <input type="radio" name="design_mediocre" value="mediocre" />
          Mediocre<br />
        <input type="radio" name="design_good" value="good" />
          Good<br />
        <input type="radio" name="design_excellent" value="excellent" />
          Excellent<br />
        </p></td>
    </tr>
  <tr>
    <td>Please tell us how we can improve.
      <p>
        <textarea name="howimprove" cols="50" rows="8" id="howimprove">	</textarea>
        <br />
        </p></td>
    </tr>
  <tr>
    <td><label>
      <input type="reset" name="Reset" value="Reset" />
      <input name="Submit" type="submit" id="Submit" value="Submit Survey" />
    </label></td>
    </tr>
</table>
  
  </form>
  
      </td>
    </tr>
  </table>  
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
</body>
</html>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.