Jump to content

Contact Form Help


X74SY

Recommended Posts

Hello,

I installed a php form script in my site a (contact form) It works but I get easily spammed because my visitors can submit the form without typing anything at all! can anyone here please edit the php code to not process the form if all the fields (username/email/subject) hasn't been filled yet?

Here's the script:

process.php
[code]<?php

include "config.php";

$ip=$_SERVER['REMOTE_ADDR'];
$day=date(d);
$month=date(m);
$year=date(Y);
$hour=date(H);
$minute=date(i);
$date="".$month."-".$day."-".$year.", ".$hour.":".$minute."";

$query="INSERT INTO logged_ips_contact_form (ip_id, ip, date) VALUES ('','$ip','$date')"; //Replace logged_ips_table with the name of the table where you installed IP Logger
mysql_query($query);


include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','Subject');
pt_register('POST','Username');
pt_register('POST','EmailAddress');
pt_register('POST','Message');
$Message=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Message);if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Subject: ".$Subject."
Username: ".$Username."
Email Address: ".$EmailAddress."
Message: ".$Message."
";
$message = stripslashes($message);
mail("EDITMYEMAIL@MYSITE.COM","Support Form",$message,"Support Page");

header("Refresh: 0;url=http://EDITMYSITE.COM");
?><?php
}
?>[/code]

global.inc.php

[code]<?php

function pt_register()
{
  $num_args = func_num_args();
  $vars = array();

  if ($num_args >= 2) {
      $method = strtoupper(func_get_arg(0));

      if (($method != 'SESSION') && ($method != 'GET') && ($method != 'POST') && ($method != 'SERVER') && ($method != 'COOKIE') && ($method != 'ENV')) {
          die('The first argument of pt_register must be one of the following: GET, POST, SESSION, SERVER, COOKIE, or ENV');
    }

      $varname = "HTTP_{$method}_VARS";
      global ${$varname};

      for ($i = 1; $i < $num_args; $i++) {
          $parameter = func_get_arg($i);

          if (isset(${$varname}[$parameter])) {
              global $$parameter;
              $$parameter = ${$varname}[$parameter];
          }

      }

  } else {
      die('You must specify at least two arguments');
  }

}

?>
[/code]

Sorry, I'm a php newbie :(

Any help would be very much appreciated,
Thank you!
Link to comment
Share on other sites

one example of something you could do is:
[code]<?php
//in these lines:
$message = stripslashes($message);
mail("EDITMYEMAIL@MYSITE.COM","Support Form",$message,"Support Page");

//add:
$message = stripslashes($message);

if($message == ""){
exit("ERROR, form not sent because there was no message");
}else{

mail("EDITMYEMAIL@MYSITE.COM","Support Form",$message,"Support Page");

}

// this way, if they leave the message field blank, the form wont be sent. its a start, but there's a lot more that you could (should) do.


?>[/code]
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.