• Welcome to The Cave of Dragonflies forums, where the smallest bugs live alongside the strongest dragons.

    Guests are not able to post messages or even read certain areas of the forums. Now, that's boring, don't you think? Registration, on the other hand, is simple, completely free of charge, and does not require you to give out any personal information at all. As soon as you register, you can take part in some of the happy fun things at the forums such as posting messages, voting in polls, sending private messages to people and being told that this is where we drink tea and eat cod.

    Of course I'm not forcing you to do anything if you don't want to, but seriously, what have you got to lose? Five seconds of your life?

Feedback forms: done correctly?

Sandstone-Shadow

A chickadee in love with the sky
Pronoun
she/her
So I tried making a feedback form that will send a message to my email address. I used this site and the following pages on it to put it together, but I'm having a tough time understanding it.

First, about the thing so that the error messages, etc. aren't cached: is the date set to December of 1998 so that the message is always expired, and therefore won't save and appear before someone's submitted the form?

Second, I'm not sure if I did the email injection prevention part right, the first part. I pretty much copied that straight from the tutorial and left it because I wasn't sure what to do with it.

And third, I'm not sure what I did, but the form doesn't work right now. I think it had something to do with adding the "name" and "version" fields in the sending part, but I don't know what I did wrong.

Here's my code:

Code:
<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;
  $name = $_REQUEST['name'] ;
  $version = $_REQUEST['version'] ;

if ( preg_match( "/[\r\n]/", $name ) || preg_match( "/[\r\n]/", $email ) ) {

    header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
    header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
    header( "Cache-Control: no-cache, must-revalidate" );
    header( "Pragma: no-cache" );

    ?>

    <?PHP include('top.txt');?>
    <h1>Error</h1>
    <p>
    There is a problem with the content of the "name" or "email" field. Please make sure that this information is formatted correctly. Please press the BACK
    button in your browser and try again.
    </p>
    <?PHP include('bottom.txt');?>

    <?php
   
    }



if (!isset($_REQUEST['email']))  {

    ?>

    <?PHP include('top.txt');?>
    <h1>Ask a Question about a Pokémon Game</h1>
    <p>Have a question about a Pokémon game? Ask any sort of game question here! I'll find the answer and post a response here.</p>
    <p>Please specify what game the question is about.</p>

    <form method="post" action="sendmail.php">
      Name: <input name="name" type="text" /><br />
      Email: <input name="email" type="text" /><br />
      Version: <input name="version" type="text" /><br />
      Message:<br />
      <textarea name="message" rows="15" cols="40">
      </textarea><br />
      <input type="submit" />
    </form>
    <?PHP include('bottom.txt');?>

    <?php

    }





  elseif (empty($email) || empty($message)) {
    
    header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
    header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
    header( "Cache-Control: no-cache, must-revalidate" );
    header( "Pragma: no-cache" );



   ?>

   <?PHP include('top.txt');?>
    <h1>Error</h1>
    <p>
    Oops, it appears you forgot to enter either your
    email address or your message. Please press the BACK
    button in your browser and try again.
    </p>
    <?PHP include('bottom.txt');?>

    <?php
  }



  else {
  mail( "absolsmoonlitcave@gmail.com", "New Gaming Question",
    "$version\n\n$message", "From: $name <$email>" );
  
?>

    <?PHP include('top.txt');?>
    <h1>thanks</h1>
    <p>
    it worked! thanks.
    </p>
    <?PHP include('bottom.txt');?>

    <?php
  }



?>

What do you think?
 
I'm not one to say "yeah, this is perectly fine" or such and such, but the code seems fine...uh...
 
Back
Top Bottom