Jump to content
Sign in to follow this  
sandesh.acharya

prevent blank field submission

Recommended Posts

i have a website with simple contact form that asks

 

1. Name

2. E-mail

3. Tel

4. Subject

5. Comments

 

the simple form is in .htm format and uses .php file for data submission.

 

now, problem is that someone stupid submits the contact form without any text (so i receive hundreds of blank e-mals everyday).

 

can you please suggest some script that prevents blank field from being submitted?

 

i searched around the net too but couldn't get exact solution.

 

for your info i have copied scripts of 'submit.htm' file and 'sendmail.php' files

 

 

CODE FROM MY submit.htm FILE that has contact form

 

 

 

 

CODE FROM MY submit.php FILE that receives data from submit.htm file and processes e-mail

 

 

<?php

/////////////////////////////////////////////////////////////

 

 

if (!empty($_POST)){

$redirect = "thanks.htm";

$subject = $_POST['Subj'];

$to = "my@emailaddress.com";

$from = $_POST['UserEmail'];

$message = "Information submitted on " . date( "l, F d, Y") . "\n

------------------------------------------------\n

Name: {$_POST['Name']}\n

E-mail: {$_POST['UserEmail']}\n

Tel: {$_POST['Tel']}\n

Subject: {$_POST['Subj']}\n

Comments:\n\n{$_POST['Comments']}\n\n";

 

mailIt($to, $from, "", "", $subject, $message);

echo " message received - thank you";

 

if ($redirect != "thanks.htm") header("Location: {$redirect}");

}

 

 

////////////////////////////////////////////////////////////

// The actual mail function.

 

function mailIt($to, $from, $cc, $bcc, $subject, $message){

if (!is_array($to)){

$to = "{$to}";

}

else{

foreach($to as $to_nick=>$to_mail){

$to_arr[] = "{$to_mail}";

}

$to = implode(', ', $to_arr);

}

 

if (!is_array($from)){

$from = "{$from}";

}

else{

$from = key($from[0]);

}

 

 

 

/* To send HTML mail, you can set the Content-type header. */

//$headers = "MIME-Version: 1.0\r\n";

//$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

 

/* additional headers */

$headers .= "To: {$to}\r\n";

$headers .= "From: {$from}\r\n";

if ($cc != "") $headers .= "Cc: {$cc}\r\n";

if ($bcc !="") $headers .= "Bcc: {$bcc}\r\n";

 

/* and now mail it */

echo mail($to, $subject, $message, $headers);

 

 

}

 

?>

Share this post


Link to post
Share on other sites

 

 

the simple form is in .htm format and uses .php file for data submission.

 

 

it uses either .htm /or .php, it cann't use both file extension, convert your .htm file into .php and make all the files extension same.

 

or just download fresh copy of scripts from hotscripts.

Share this post


Link to post
Share on other sites

Sandesh,

it's been ages since i've did programming,

n if i'm not wrong,

u need 2 have a $_REQUEST Variable 2 get the result from

form data sent with POST methods.

 

Name: <?php echo $_REQUEST["name"]; ?>.<br />

E-mail <?php echo $_REQUEST["email"]; ?>

 

Pardon me if i got it all wrong... :blink::huh:

Share this post


Link to post
Share on other sites
Name: <?php echo $_REQUEST["name"]; ?>

 

E-mail <?php echo $_REQUEST["email"]; ?>

 

echo $_wonderful coding.

 

I am delighted with our very own Tara's programming skills, long time no see Tara. How's your baby :)

Share this post


Link to post
Share on other sites

You can use Form Validations Java Script code like:

 

<script language="JavaScript" type="text/javascript">

var frmvalidator = new Validator("myform");

frmvalidator.addValidation("Name","req","Please enter your Name");

frmvalidator.addValidation("Name","maxlen=20",

"Max length for FirstName is 20");

frmvalidator.addValidation("Name","alpha");

 

frmvalidator.addValidation("UserEmail","maxlen=50");

frmvalidator.addValidation("UserEmail","req");

frmvalidator.addValidation("UserEmail","email");

 

 

For details, You can see on: http://www.javascript-coder.com/html-form/...alidation.phtml

 

thank you,

 

 

 

i have a website with simple contact form that asks

 

1. Name

2. E-mail

3. Tel

4. Subject

5. Comments

 

the simple form is in .htm format and uses .php file for data submission.

 

now, problem is that someone stupid submits the contact form without any text (so i receive hundreds of blank e-mals everyday).

 

can you please suggest some script that prevents blank field from being submitted?

 

i searched around the net too but couldn't get exact solution.

 

for your info i have copied scripts of 'submit.htm' file and 'sendmail.php' files

 

 

CODE FROM MY submit.htm FILE that has contact form

 

 

 

 

CODE FROM MY submit.php FILE that receives data from submit.htm file and processes e-mail

 

 

<?php

/////////////////////////////////////////////////////////////

 

 

if (!empty($_POST)){

$redirect = "thanks.htm";

$subject = $_POST['Subj'];

$to = "my@emailaddress.com";

$from = $_POST['UserEmail'];

$message = "Information submitted on " . date( "l, F d, Y") . "\n

------------------------------------------------\n

Name: {$_POST['Name']}\n

E-mail: {$_POST['UserEmail']}\n

Tel: {$_POST['Tel']}\n

Subject: {$_POST['Subj']}\n

Comments:\n\n{$_POST['Comments']}\n\n";

 

mailIt($to, $from, "", "", $subject, $message);

echo " message received - thank you";

 

if ($redirect != "thanks.htm") header("Location: {$redirect}");

}

 

 

////////////////////////////////////////////////////////////

// The actual mail function.

 

function mailIt($to, $from, $cc, $bcc, $subject, $message){

if (!is_array($to)){

$to = "{$to}";

}

else{

foreach($to as $to_nick=>$to_mail){

$to_arr[] = "{$to_mail}";

}

$to = implode(', ', $to_arr);

}

 

if (!is_array($from)){

$from = "{$from}";

}

else{

$from = key($from[0]);

}

 

 

 

/* To send HTML mail, you can set the Content-type header. */

//$headers = "MIME-Version: 1.0\r\n";

//$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

 

/* additional headers */

$headers .= "To: {$to}\r\n";

$headers .= "From: {$from}\r\n";

if ($cc != "") $headers .= "Cc: {$cc}\r\n";

if ($bcc !="") $headers .= "Bcc: {$bcc}\r\n";

 

/* and now mail it */

echo mail($to, $subject, $message, $headers);

 

 

}

 

?>

 

Share this post


Link to post
Share on other sites

As kbroka said,

validator can be also used.

 

 

Hi Limitation//Moon

I'm doing good.

My Baby Brian Jay's fast asleep..

**it's midnight out here** Ssshhhhh.....

Howdy?? How's life out there?...:)

Hope it's treating u pretty well,

aside from the weather..

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.