Current location: Hot Scripts Forums » Programming Languages » PHP » Simple question


Simple question

Reply
  #1 (permalink)  
Old 08-13-04, 09:02 AM
kashi kashi is offline
New Member
 
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Simple question

Hi. I am new to this forum and especially php.
I apologize for asking such a simple question,
but I've been working on this for an embarrassing
amount of time and still can't get it.

My question:
I have a very simple email form.
I would like to make all fields required.


Thank you in advance for your time.
Regards,

Kashi




----------------------------------------------------

<?
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$company = $_REQUEST['company'] ;
$product = $_REQUEST['product'] ;
$phone = $_REQUEST['phone'] ;
$message = $_REQUEST['message'] ;

if (!isset($_REQUEST['email'])) {
header( "Location: http://www.doubletakestudios.net/temp_sites/form/feedback.html" );
}
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" );

?>
<html>
<head><title>Error</title>
<link href="text.css" rel="stylesheet" type="text/css">
<link href="link.css" rel="stylesheet" type="text/css">
</head>
<body class="text">
<h1>Error</h1>
<p>
Invalid Entry. Please complete form.<br>
<br>
<a href="http://www.doubletakestudios.net/temp_sites/form/feedback.html" class="link"><
Return to MSDS Request Form</a>

</p>
</body>
</html>

<?

}
else {
mail( "akinnelly@doubletakestudios.net", "MSDS Request",
"Emergency Response MSDS Request:\n\nName: $name\nEmail: $email\nCompany: $company\nProduct: $product\nPhone: $phone\n\nRequest/Comments: $message",
"From: $name <$email>" );
header( "Location: http://www.doubletakestudios.net/temp_sites/form/thankyou.html" );
}
?>

---------------------------------------------------------------
Reply With Quote
  #2 (permalink)  
Old 08-13-04, 09:22 AM
MrOrange MrOrange is offline
Newbie Coder
 
Join Date: Jul 2004
Location: Oklahoma City
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Just expand where you already have it:
elseif (empty($email) || empty($message)) {

to

elseif (empty($email) || empty($message) || empty($company) || empty($product) || empty($name) || empty($phone)) {

This will check to see if each value is empty or not. If one is empty (meaning it has a value equal to boolean false, meaning it is either FALSE, 0, or not set at all), it gives them your error page.
Reply With Quote
  #3 (permalink)  
Old 08-13-04, 09:33 AM
kashi kashi is offline
New Member
 
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you very much for your help!
It's works great!
Reply With Quote
  #4 (permalink)  
Old 08-13-04, 08:29 PM
bugalyzer bugalyzer is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
script

Your better off using javascript to ensure all fields are valid ... it's not the best solution nor is it 100% - but it will minimize problems and the way you have it implmented now looks like if something was missed then it refreshes the form and wipes everything out .. this is the worse thing you want to happen -- nothing worse then filling out a form - submitting it and then having to fill it out again because you missed something.

the correct solution is to re-post all the data bank to the form if something is missing but that's a bit more complicated to explain here.

http://buildacom.com
Reply With Quote
  #5 (permalink)  
Old 08-13-04, 08:57 PM
MrOrange MrOrange is offline
Newbie Coder
 
Join Date: Jul 2004
Location: Oklahoma City
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
I strongly recommend to also use PHP to check the entries made in a form as a user can simply turn JavaScript support off in their browser.

He is correct though, there is nothing worse than losing all the data you entered. The usual protection against this is to say your page that they load is currently contact.html and the php script is contact.php simply stick the html code underneath the php block, meaning:

<?php
blah
?>
<html>
blah
</html>

and then have <form action="/contact.php" method="post"> and then for all the inputs, do:

<input name="namehere" type="text" value="<?=$name?>" />

be sure to replace namehere with the html name and the $name with the PHP variable. for textareas.....

<textarea><?=$name?></textarea>



Clear as mud?
Reply With Quote
  #6 (permalink)  
Old 08-13-04, 10:23 PM
kvnband kvnband is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 242
Thanks: 0
Thanked 0 Times in 0 Posts
Nevermind......
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple question Maniax JavaScript 4 08-31-04 01:08 PM
Simple PHP question about JPEG? snooky5 PHP 4 08-14-04 03:36 PM
Simple Question nullbox PHP 2 04-09-04 04:31 PM
simple array question jimcart JavaScript 1 03-19-04 05:38 PM
question about simple login system magsec4 PHP 5 02-23-04 03:35 AM


All times are GMT -5. The time now is 04:19 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.