Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 12th, 2012  |  syntax: PHP  |  size: 1.15 KB  |  views: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. $name=$_POST['name'];
  3. $subject=$_POST['subject'];
  4. $message=$_POST['message'];
  5. $emailAddress=$_POST['emailAddress'];
  6. //It's receiving the variables correctly, I've checked by printing the variables.
  7. $errors=array(); //Creates empty array with 0 indexes. This will now be filled with error messages (if there are any errors).
  8. if($name=="" || $subject=="" || $message=="" || $emailAddress=""){
  9.         if($name==""){
  10.                 $errors[0]="You did not supply a name.";
  11.         }
  12.         if($subject==""){
  13.                 $errors[count($errors)]="You did not supply a subject."; //I'm using count($errors) so it will create a new index at the end of the array, regardless of how many indexes it currently has (if that makes sense, it's hard to explain)
  14.         }
  15.         if($message==""){
  16.                 $errors[count($errors)]="You did not supply a message.";
  17.         }
  18.         if($emailAddress==""){
  19.                 $errors[count($errors)]="You did not supply an email address.";
  20.         }
  21. }
  22. //Were there any errors?
  23. if(!count($errors)==0){
  24.         print "The following errors were found:<br />";
  25.         for($i=0; $i<count($errors); $i++){
  26.                 print $errors[$i]."<br />";
  27.         }
  28.         die ();
  29. }
  30. //Rest of email script, which I'll write when the stupid bug is fixed. :(
  31. ?>
clone this paste RAW Paste Data