Jump to content


Photo

FormToEmail Required Fields


  • Please log in to reply
3 replies to this topic

#1 jcastle

jcastle
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • LocationBrooklyn, NY

Posted 26 July 2006 - 09:23 PM

Noobie ...

Is there anyway to add required fields to the script below ... I have about 5 fields on the form and I want the first 3 to be required before the form is submitted.

Using FormToEmail Script ... below ... any help is appriciated

James


<?php

/*

Thank you for choosing FormToEmail by FormToEmail.com

Version 1.5 May 27th 2006

COPYRIGHT FormToEmail.com 2003 - 2006

Step 1:

To put the form on your webpage, copy the code below as it is, and paste it into your webpage:

<form action="FormToEmail.php" method="post">
<table border="0" bgcolor="#ececec" cellspacing="5">
<tr><td><font face="arial" size="2">Name</font></td><td><input type="text" size="30" name="Name"></td></tr>
<tr><td><font face="arial" size="2">Email address</font></td><td><input type="text" size="30" name="Email"></td></tr>
<tr><td valign="top"><font face="arial" size="2">Comments</font></td><td><textarea name="Comments" rows="6" cols="30"></textarea></td></tr>
<tr><td>&nbsp;</td><td><input type="submit" value="Send"><font face="arial" size="1">&nbsp;&nbsp;FormToEmail by <a href="http://FormToEmail.c...font></td></tr>
</table>
</form>

Step 2:

Enter the email address below to send the form to:

*/

$my_email = "mysite.com";

/*

Enter the continue link to offer the user after the form is sent.  If you do not change this, your visitor will be given a continue link to your homepage:

If you do change it, remove the "/" symbol below and replace with the name of the page to link to, eg: "mypage.htm" or "http://www.elsewhere...e.com/page.htm"

*/

$continue = "/";

/*


Step 3:

Save this file (FormToEmail.php) and upload it together with your webpage to your webspace.  IMPORTANT - The file name is case sensitive!  You must save it exactly as it is named above!  Do not put this script in your cgi-bin directory (folder) it may not work from there.

THAT'S IT, FINISHED!

You do not need to make any changes below this line.

*/

// This line prevents values being entered in a URL

if ($_SERVER['REQUEST_METHOD'] != "POST"){exit;}

// Describe function to check for new lines.

function new_line_check($a)
{

if(preg_match('`[\r\n]`',$a)){header("location: $_SERVER[HTTP_REFERER]");exit;}

}

new_line_check($_POST['Name']);

// Check for disallowed characters in the Name and Email fields.

$disallowed_name = array(':',';','"','=','(',')','{','}','@');

foreach($disallowed_name as $value)
{

if(stristr($_POST['Name'],$value)){header("location: $_SERVER[HTTP_REFERER]");exit;}

}

new_line_check($_POST['Email']);

$disallowed_email = array(':',';',"'",'"','=','(',')','{','}');

foreach($disallowed_email as $value)
{

if(stristr($_POST['Email'],$value)){header("location: $_SERVER[HTTP_REFERER]");exit;}

}

$message = "";

// This line prevents a blank form being sent, and builds the message.

foreach($_POST as $key => $value){if(!(empty($value))){$set=1;}$message = $message . "$key: $value\n\n";} if($set!==1){header("location: $_SERVER[HTTP_REFERER]");exit;}

$message = $message . "\n";
$message = stripslashes($message);
$subject = "helenekidary.com form";
$headers = "From: info@helenekidary.com " . $_POST['Email'] . "\n" . "Return-Path: " . $_POST['Email'] . "\n" . "Reply-To: " . $_POST['Email'] . "\n";

mail($my_email,$subject,$message,$headers);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>Helene Kidary Form</title>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-uk">

</head>

<body bgcolor="#ffffff" text="#000000">

<font face="arial">

<object><center>
<h1>Thank You</h1>
<h2>Your form has been sent</h2>
<h3><a href="<?php print "index.html"; ?>">Return to Helene Kidary</a></h3>
</center></object>

</font>

</body>
</html>

#2 jcastle

jcastle
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • LocationBrooklyn, NY

Posted 26 July 2006 - 09:54 PM

Thanks ... but this project was due yesterday ... looking for a quick fix.

James

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 26 July 2006 - 10:14 PM

just check the ones you need to check
if ($_POST['formfield1'] == "") {
echo "Form Field 1 was left blank";
}
and so forth, or you can put them in a variable and repeat them back
or you can exit the script, or however you want to do it.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 26 July 2006 - 10:16 PM

Thanks ... but this project was due yesterday ... looking for a quick fix.

Those kinds of comments will get you knowhere. If you dont know how to code simple validations, dont take on projects. Simple.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users