PDA

View Full Version : Make form field not required


colindunn
05-08-2007, 06:55 AM
Hi everyone,

I have a PHP form that mails me the context of some text fields, radios, etc., but I would like to set some of them to be required while others not. Right now they are all required and I am not really sure why. (I'm still new to this) Also, I would like to send the form to multiple email addresses. Thanks in advance. :thumbsup:

<?php

@$title = addslashes($_POST['title']);
@$first = addslashes($_POST['first']);
@$last = addslashes($_POST['last']);
@$business = addslashes($_POST['business']);
@$site = addslashes($_POST['site']);
@$phone = addslashes($_POST['phone']);
@$email = addslashes($_POST['email']);
@$category = addslashes($_POST['category']);
@$month = addslashes($_POST['month']);
@$year = addslashes($_POST['year']);

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
header("Location: contact-error.html");
exit;
}

$pfw_header = "From: $email";
$pfw_subject = "Customer Contact";
$pfw_email_to = "email@address.com";
$pfw_message = "Name: $title $first $last\n"
. "\n"
. "$business\n"
. "$site\n"
. "P: $phone\n"
. "E: $email\n"
. "\n"
. "Category: $category\n"
. "Deadline: $month $year\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

$pfw_header = "From: autoreply@url.com";
$pfw_subject = "Auto-Reply";
$pfw_email_to = "$email";
$pfw_message = "$title $last,\n"
. "Thank you for taking the time to contact us. We will review the information you provided and get in touch with you as soon as possible.\n"
. "\n"
. "Regards,\n"
. "Management\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

header("Location: contact-success.html");

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta name="Description" content="Creadev Studios is a graphic and web design firm committed to providing both professional and affordable services." />
<meta name="Keywords" content=" Web, Graphic, Multimedia, Design, Site, Services, Professional, Portfolio, Affordable, Creadev Studios, Creative" />
<title>Creadev Studios - Design Redefined</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="images/favicon_yellow.png" type="image/x-icon" />
</head>
<body class="contact">

<div id="header">
</div>

<div id="navigation">
<table cellpadding="0" cellspacing="0" class="navigation">
<tr>
<td class="spacer">&nbsp;</td>
<td class="navactive" onclick="location='index.html'" onmouseout="className='navactive'" onmouseover="className='lobbyhover'">Lobby</td>
<td class="navactive" onclick="location='services.html'" onmouseout="className='navactive'" onmouseover="className='serviceshover'">Services</td>
<td class="navactive" onclick="location='portfolio.html'" onmouseout="className='navactive'" onmouseover="className='portfoliohover'">Portfolio</td>
<td class="contactstatic">Contact</td>
<td class="spacer">&nbsp;</td>
</tr>
</table>
</div>

<div id="main">

<div id="contentheader">
</div>

<div id="content">
<h1>Contact Us</h1>
<p style="margin-bottom: 25px">If you would like an estimate on your project, please complete the form below.</p>
<form action="mail.php" method="post">
<table cellpadding="5" cellspacing="0" style="margin-left: auto; margin-right: auto">
<tr>
<td style="text-align: right">Title</td>
<td><input name="title" type="radio" value="Mr." />&nbsp;Mr.
<input name="title" type="radio" value="Mrs." />&nbsp;Mrs.
<input name="title" type="radio" value="Ms." />&nbsp;Ms.
<input name="title" type="radio" value="Miss." />&nbsp;Miss</td>
</tr>
<tr>
<td style="text-align: right">First Name</td>
<td><input class="formobject" maxlength="99" name="first" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Last Name</td>
<td><input class="formobject" maxlength="99" name="last" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Business Name</td>
<td><input class="formobject" maxlength="99" name="business" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Web Site</td>
<td><input class="formobject" maxlength="99" name="site" size="24" type="text" value="http://" /></td>
</tr>
<tr>
<td style="text-align: right">Phone Number</td>
<td><input class="formobject" maxlength="99" name="phone" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Email Address</td>
<td><input class="formobject" maxlength="99" name="email" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Project Category</td>
<td><select name="category">
<option selected="selected">Please Select...</option>
<option value="Commercial">Commercial</option>
<option value="Graphic">Graphic Design</option>
<option value="Logo">Logo Design</option>
<option value="Multimedia">Multimedia</option>
<option value="Scripting">Programming</option>
<option value="Web">Web Design</option>
</select></td>
</tr>
<tr>
<td style="text-align: right">Project Deadline</td>
<td><select name="month">
<option selected="selected">Month</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
<select name="year">
<option selected="selected">Year</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<div id="submit">
<a href="#"><input name="send" type="image" id="send" value="send" src="images/spacer.gif"></a>
</div>
</td>
</tr>
</table>
</form>
</div>

<div id="contentfooter">
</div>

</div>

<div id="footer">
</div>

</body>
</html>

mr e
05-08-2007, 08:06 AM
I'm not sure what you mean by required, by the looks of it, I could submit a form with everything blank except the email and it would work just fine.

PappaJohn
05-08-2007, 08:08 AM
I don't see anything in the code that makes the fields required.

oops: mr_e got there first

_Dan
05-08-2007, 03:17 PM
For sending to multiple emails, replace the first

@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

with something like



$mail_list = array("email1@address.com", "email2@address.com"); // as many as you like

foreach ($mail_list as $pfw_email_to)
{
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
}


(alternatively you could probably use CC or BCC headers instead of the loop but I don't know the exact mechanics off the top of my head...)

colindunn
05-08-2007, 05:26 PM
Thanks a lot Dan. :-D

Hmm. It seems you guys are right. My mistake. So how do I make some fields required?

Bill Posters
05-08-2007, 05:36 PM
$mail_list = array("email1@address.com", "email2@address.com"); // as many as you like…


I recall reading something in the past couple of days which suggested that many mail servers could potentially mark the mails as spam if the numbers sent in one cycle are high enough.
I can't recall where I read it, and may even be slightly off the mark, but I guess my point is that "as many as you want" might not be entirely accurate in practice - with alternative mechanisms being recommended for genuine mass mailings.

Perhaps the possible risks and limitations of pumping out multiple emails this way is something to be dealt with in its own thread/query.

whizard
05-08-2007, 07:29 PM
To make a field required:

(in the file that the form points to:

if(!isset($_POST['my_field']))
{
//show error page or whatever to tell the user that he needs to fill in the field
}


HTH
Dan

colindunn
05-08-2007, 08:25 PM
To make a field required:

(in the file that the form points to:

if(!isset($_POST['my_field']))
{
//show error page or whatever to tell the user that he needs to fill in the field
}


HTH
Dan


So I am doing something wrong...

<?php

@$title = addslashes($_POST['title']);
@$first = addslashes($_POST['first']);
@$last = addslashes($_POST['last']);
@$business = addslashes($_POST['business']);
@$site = addslashes($_POST['site']);
@$phone = addslashes($_POST['phone']);
@$email = addslashes($_POST['email']);
@$category = addslashes($_POST['category']);
@$month = addslashes($_POST['month']);
@$year = addslashes($_POST['year']);

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
header("Location: contact-error.html");
exit;
}

if(!isset($_POST['last']))
{
header("Location: contact-error.html");
exit;
}

$pfw_header = "From: $email";
$pfw_subject = "Customer Contact";
$pfw_email_to = "email@address.com";
$pfw_message = "Name: $title $first $last\n"
. "\n"
. "$business\n"
. "$site\n"
. "P: $phone\n"
. "E: $email\n"
. "\n"
. "Category: $category\n"
. "Deadline: $month $year\n";
$mail_list = array("email@address.com", "email2@address.com");

foreach ($mail_list as $pfw_email_to)
{
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
}

$pfw_header = "From: autoreply@address.com";
$pfw_subject = "Auto-Reply";
$pfw_email_to = "$email";
$pfw_message = "$title $last,\n"
. "Thank you for taking the time to contact us. We will review the information you provided and get in touch with you as soon as possible.\n"
. "\n"
. "Regards,\n"
. "Management\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

header("Location: contact-success.html");

?>

JohnDubya
05-08-2007, 10:50 PM
You probably wouldn't want to throw the user to a different page if they don't fill out one of the fields. If you do that, how will the user get back to the contact form? And remember that all the input he had used will be deleted if he's sent to another page.

Here's what I do for errors. Take it or leave it. :)

I set a variable called $error_stat to 0 at the very top of the page. Then, if there is an error (if a field is blank or whatever), I set $error_stat to 1. I also insert an error message into a variable called $message and echo that at the top of the page. Then, for each step through the form handler, I have it check to make sure that $error_stat is still equal to 0. If it doesn't, the handler won't continue.

Let me know if you need more specific code for that. Good luck! :)

colindunn
05-08-2007, 10:53 PM
You probably wouldn't want to throw the user to a different page if they don't fill out one of the fields. If you do that, how will the user get back to the contact form? And remember that all the input he had used will be deleted if he's sent to another page.

Here's what I do for errors. Take it or leave it. :)

I set a variable called $error_stat to 0 at the very top of the page. Then, if there is an error (if a field is blank or whatever), I set $error_stat to 1. I also insert an error message into a variable called $message and echo that at the top of the page. Then, for each step through the form handler, I have it check to make sure that $error_stat is still equal to 0. If it doesn't, the handler won't continue.

Let me know if you need more specific code for that. Good luck! :)

That's a good point. If you would be interested in providing the code, I would be most gratified. Please remember though, I am not a programmer and am guessing and checking my way through this. So it would be helpful if you could give me very specific instructions or possibly a modified version of my code, if it is not to much trouble.

Thanks for all the help, you guys are awesome! :)

JohnDubya
05-08-2007, 11:50 PM
That's a good point. If you would be interested in providing the code, I would be most gratified. Please remember though, I am not a programmer and am guessing and checking my way through this. So it would be helpful if you could give me very specific instructions or possibly a modified version of my code, if it is not to much trouble.

Thanks for all the help, you guys are awesome!

Will do. :) The people here are pretty amazing. They've helped me so much, it makes me want to help others too. It's a recurring cycle...a good one. Kinda like...

while ($people == 'helpful') {
help($others);
}

haha Ok, here's the fun stuff:


<?php
//Let's pretend we're at the very top of the page, and we set $error_stat
$error_stat = 0;


//Ok, now we're checking the e-mail address
if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
//so, if the email address is invalid, set $error_stat to 1 and put the detailed error message into the $message variable
$error_stat = 1;
$message = 'Your e-mail address is invalid.';
}


//If I require a field, I always check it with empty() because empty() checks for NULL, "", FALSE, 0, integer 0, etc. (in other words, it makes for sure that the user actually input _something_
if (!empty($_POST['last']))
{
//if variable $_POST['last'] is empty, set $error_stat to 1 and do the $message thing again
$error_stat = 1;
$message = 'Please enter your last name.';
}


//Now, we will execute the handling of the user's input, ONLY if the $error_stat still equals 0
if ($error_stat == 0) {
//all your code to handle the user's input
}
?>


<!-- Now, let's pretend we're at the top of the HTML of the page. We'll echo the $message variable there by using the shortcut to echo a variable, = -->

<html>
<body>

<?=$message?>

<!-- The cool thing is that if $message is blank, it won't output anything. It will only echo something if $message isn't blank, so don't worry about it echoing a space or anything. -->


If you need more explanation, just let me know!

crunkbbfe
05-09-2007, 02:18 AM
To make a field required:

(in the file that the form points to:

if(!isset($_POST['my_field']))
{
//show error page or whatever to tell the user that he needs to fill in the field
}


HTH
Dan

I think another way that may be more simple to check whether or not a field has information submitted into it is with


if(!$tag || !$othertag || !$more){
echo "Fill in everything";
}else{


both of these ways will only check to see if information has been submitted, if you have like a phone number and you use the isset script someone could enter in 1 and it would work so i would suggest doing a string length check


if(strlen($tag) < 10){
echo "You must enter in a valid number";
}else{


where the number 10 is the number of characters

colindunn
05-09-2007, 06:54 AM
Thank you all so much for your help, you inspire me :cool: Espically you JohnDubya. So I have worked what you said into the code, but I am doing something wrong. Probably really obvious...

<?php
$error_stat = 0;

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
$error_stat = 1;
$message = 'Your e-mail address is invalid.';
}

if (!empty($_POST['last']))
{
$error_stat = 1;
$message = 'Please enter your last name.';
}

if ($error_stat == 0) {
@$title = addslashes($_POST['title']);
@$first = addslashes($_POST['first']);
@$last = addslashes($_POST['last']);
@$business = addslashes($_POST['business']);
@$site = addslashes($_POST['site']);
@$phone = addslashes($_POST['phone']);
@$email = addslashes($_POST['email']);
@$category = addslashes($_POST['category']);
@$month = addslashes($_POST['month']);
@$year = addslashes($_POST['year']);
}

$pfw_header = "From: $email";
$pfw_subject = "Customer Contact";
$pfw_message = "Name: $title $first $last\n"
. "\n"
. "$business\n"
. "$site\n"
. "P: $phone\n"
. "E: $email\n"
. "\n"
. "Category: $category\n"
. "Deadline: $month $year\n";
$mail_list = array("email1@address.com", "email2@address.com");

foreach ($mail_list as $pfw_email_to)
{
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
}

$pfw_header = "From: autoreply@address.com";
$pfw_subject = "Auto-Reply";
$pfw_email_to = "$email";
$pfw_message = "$title $last,\n"
. "Thank you for taking the time to contact us. We will review the information you provided and get in touch with you as soon as possible.\n"
. "\n"
. "Regards,\n"
. "Management\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

header("Location: success.html");

?>

and on the html...
<head><body>...<p style="margin-bottom: 25px">If you would like an estimate on your project, please complete the form below.</p>
<h3><?=$message?></h3>
<form action="mail.php" method="post">...</body></head>

_Dan
05-09-2007, 12:17 PM
"the html" must be saved with the extension .php not html.

And then you need to include it in the PHP, for example:


if ($error_stat == 0) {
// blah...
}
else
{
include("the_html.php");
}


I would suggest merging it all into one file named "contact.php":


<?
if (!empty($_POST)) // if something has been submitted
{
@$title = addslashes($_POST['title']);
@$first = addslashes($_POST['first']);
@$last = addslashes($_POST['last']);
@$business = addslashes($_POST['business']);
@$site = addslashes($_POST['site']);
@$phone = addslashes($_POST['phone']);
@$email = addslashes($_POST['email']);
@$category = addslashes($_POST['category']);
@$month = addslashes($_POST['month']);
@$year = addslashes($_POST['year']);

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
$message .= 'Your e-mail address is invalid.<br>';
}

if (empty($_POST['last']))
{
$message .= 'Please enter your last name.<br>';
}

if (!$message)
{

$pfw_header = "From: $email";
$pfw_subject = "Customer Contact";
$pfw_message = "Name: $title $first $last\n"
. "\n"
. "$business\n"
. "$site\n"
. "P: $phone\n"
. "E: $email\n"
. "\n"
. "Category: $category\n"
. "Deadline: $month $year\n";
$mail_list = array("email1@address.com", "email2@address.com");

foreach ($mail_list as $pfw_email_to)
{
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
}

$pfw_header = "From: autoreply@address.com";
$pfw_subject = "Auto-Reply";
$pfw_email_to = "$email";
$pfw_message = "$title $last,\n"
. "Thank you for taking the time to contact us. We will review the information you provided and get in touch with you as soon as possible.\n"
. "\n"
. "Regards,\n"
. "Management\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

header("Location: success.html");
die();
}
}


// if nothing was submitted or an error message was given the code continues here
// and displays the html
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta name="Description" content="Creadev Studios is a graphic and web design firm committed to providing both professional and affordable services." />
<meta name="Keywords" content=" Web, Graphic, Multimedia, Design, Site, Services, Professional, Portfolio, Affordable, Creadev Studios, Creative" />
<title>Creadev Studios - Design Redefined</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="images/favicon_yellow.png" type="image/x-icon" />
</head>
<body class="contact">

<div id="header">
</div>

<div id="navigation">
<table cellpadding="0" cellspacing="0" class="navigation">
<tr>
<td class="spacer">&nbsp;</td>
<td class="navactive" onclick="location='index.html'" onmouseout="className='navactive'" onmouseover="className='lobbyhover'">Lobby</td>
<td class="navactive" onclick="location='services.html'" onmouseout="className='navactive'" onmouseover="className='serviceshover'">Services</td>
<td class="navactive" onclick="location='portfolio.html'" onmouseout="className='navactive'" onmouseover="className='portfoliohover'">Portfolio</td>
<td class="contactstatic">Contact</td>
<td class="spacer">&nbsp;</td>
</tr>
</table>
</div>

<div id="main">

<div id="contentheader">
</div>

<div id="content">
<h1>Contact Us</h1>
<p style="margin-bottom: 25px">If you would like an estimate on your project, please complete the form below.</p>

<h3><?=$message?></h3>

<form action="contact.php" method="post">
<table cellpadding="5" cellspacing="0" style="margin-left: auto; margin-right: auto">
<tr>
<td style="text-align: right">Title</td>
<td><input name="title" type="radio" value="Mr." />&nbsp;Mr.
<input name="title" type="radio" value="Mrs." />&nbsp;Mrs.
<input name="title" type="radio" value="Ms." />&nbsp;Ms.
<input name="title" type="radio" value="Miss." />&nbsp;Miss</td>
</tr>
<tr>
<td style="text-align: right">First Name</td>
<td><input class="formobject" maxlength="99" name="first" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Last Name</td>
<td><input class="formobject" maxlength="99" name="last" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Business Name</td>
<td><input class="formobject" maxlength="99" name="business" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Web Site</td>
<td><input class="formobject" maxlength="99" name="site" size="24" type="text" value="http://" /></td>
</tr>
<tr>
<td style="text-align: right">Phone Number</td>
<td><input class="formobject" maxlength="99" name="phone" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Email Address</td>
<td><input class="formobject" maxlength="99" name="email" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Project Category</td>
<td><select name="category">
<option selected="selected">Please Select...</option>
<option value="Commercial">Commercial</option>
<option value="Graphic">Graphic Design</option>
<option value="Logo">Logo Design</option>
<option value="Multimedia">Multimedia</option>
<option value="Scripting">Programming</option>
<option value="Web">Web Design</option>
</select></td>
</tr>
<tr>
<td style="text-align: right">Project Deadline</td>
<td><select name="month">
<option selected="selected">Month</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
<select name="year">
<option selected="selected">Year</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<div id="submit">
<input name="send" type="image" id="send" value="send" src="images/spacer.gif">
</div>
</td>
</tr>
</table>
</form>
</div>

<div id="contentfooter">
</div>

</div>

<div id="footer">
</div>

</body>
</html>

colindunn
05-10-2007, 01:07 AM
OK, I am making progress but am still not quite there.

Right now the form will recognize if the required fields are filled (except the category drop-down) but when it loads the error messages, it does not retain the users inputed data. How do I make sure the data is carried over if they do not fill in the required fields?

I do not think I am using the '$error_stat' right, because it works the same regardless if it is in there. Thanks to everyone who is bearing in there with me.

<?

$error_stat = 0;

if (!empty($_POST))
{
@$title = addslashes($_POST['title']);
@$first = addslashes($_POST['first']);
@$last = addslashes($_POST['last']);
@$business = addslashes($_POST['business']);
@$site = addslashes($_POST['site']);
@$phone = addslashes($_POST['phone']);
@$email = addslashes($_POST['email']);
@$category = addslashes($_POST['category']);
@$month = addslashes($_POST['month']);
@$year = addslashes($_POST['year']);

if (empty($_POST['title']))
{
$error_stat = 1;
$message .= 'Select a title.<br>';
}

if (empty($_POST['last']))
{
$error_stat = 1;
$message .= 'Input a last name.<br>';
}

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
$error_stat = 1;
$message .= 'Input a valid email address.<br>';
}

if (empty($_POST['category']))
{
$error_stat = 1;
$message .= 'Select a project category.<br>';
}

if ($error_stat == 0)
{

$pfw_header = "From: $email";
$pfw_subject = "Customer Contact";
$pfw_message = "Name: $title $first $last\n"
. "\n"
. "$business\n"
. "$site\n"
. "P: $phone\n"
. "E: $email\n"
. "\n"
. "Category: $category\n"
. "Deadline: $month $year\n";
$mail_list = array("email1@address.com", "email2@address.com");

foreach ($mail_list as $pfw_email_to)
{
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
}

$pfw_header = "From: autoreply@address.com";
$pfw_subject = "Auto-Reply";
$pfw_email_to = "$email";
$pfw_message = "$title $last,\n"
. "Thank you for taking the time to contact us. We will review the information you provided and get in touch with you as soon as possible.\n"
. "\n"
. "Regards,\n"
. "Management\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

header("Location: success.html");
die();
}
}


// if nothing was submitted or an error message was given the code continues here
// and displays the html
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta name="Description" content="Creadev Studios is a graphic and web design firm committed to providing both professional and affordable services." />
<meta name="Keywords" content=" Web, Graphic, Multimedia, Design, Site, Services, Professional, Portfolio, Affordable, Creadev Studios, Creative" />
<title>Creadev Studios - Design Redefined</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="images/favicon_yellow.png" type="image/x-icon" />
</head>
<body class="contact">

<div id="header">
</div>

<div id="navigation">
<table cellpadding="0" cellspacing="0" class="navigation">
<tr>
<td class="spacer">&nbsp;</td>
<td class="navactive" onclick="location='index.html'" onmouseout="className='navactive'" onmouseover="className='lobbyhover'">Lobby</td>
<td class="navactive" onclick="location='services.html'" onmouseout="className='navactive'" onmouseover="className='serviceshover'">Services</td>
<td class="navactive" onclick="location='portfolio.html'" onmouseout="className='navactive'" onmouseover="className='portfoliohover'">Portfolio</td>
<td class="contactstatic">Contact</td>
<td class="spacer">&nbsp;</td>
</tr>
</table>
</div>

<div id="main">

<div id="contentheader">
</div>

<div id="content">
<h1>Contact Us</h1>
<p style="margin-bottom: 25px">If you would like an estimate on your project, please complete the form below.</p>

<h3><?=$message?></h3>

<form action="test.php" method="post">
<table cellpadding="5" cellspacing="0" style="margin-left: auto; margin-right: auto">
<tr>
<td style="text-align: right">Title</td>
<td><input name="title" type="radio" value="Mr." />&nbsp;Mr.
<input name="title" type="radio" value="Mrs." />&nbsp;Mrs.
<input name="title" type="radio" value="Ms." />&nbsp;Ms.
<input name="title" type="radio" value="Miss." />&nbsp;Miss</td>
</tr>
<tr>
<td style="text-align: right">First Name</td>
<td><input class="formobject" maxlength="99" name="first" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Last Name</td>
<td><input class="formobject" maxlength="99" name="last" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Business Name</td>
<td><input class="formobject" maxlength="99" name="business" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Web Site</td>
<td><input class="formobject" maxlength="99" name="site" size="24" type="text" value="http://" /></td>
</tr>
<tr>
<td style="text-align: right">Phone Number</td>
<td><input class="formobject" maxlength="99" name="phone" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Email Address</td>
<td><input class="formobject" maxlength="99" name="email" size="24" type="text" /></td>
</tr>
<tr>
<td style="text-align: right">Project Category</td>
<td><select name="category">
<option selected="selected">Please Select...</option>
<option value="Commercial">Commercial</option>
<option value="Graphic">Graphic Design</option>
<option value="Logo">Logo Design</option>
<option value="Multimedia">Multimedia</option>
<option value="Scripting">Programming</option>
<option value="Web">Web Design</option>
</select></td>
</tr>
<tr>
<td style="text-align: right">Project Deadline</td>
<td><select name="month">
<option selected="selected">Month</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
<select name="year">
<option selected="selected">Year</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<div id="submit">
<input name="send" type="image" id="send" value="send" src="images/spacer.gif">
</div>
</td>
</tr>
</table>
</form>
</div>

<div id="contentfooter">
</div>

</div>

<div id="footer">
</div>

</body>

mr e
05-10-2007, 01:25 AM
You would want to do something like this for each form element

Notice the new value="<?php ... ?>"

<input class="formobject" maxlength="99" name="business" size="24" type="text" value="<?php echo $business; ?>" />

JohnDubya
05-10-2007, 02:03 AM
Right now the form will recognize if the required fields are filled (except the category drop-down) but when it loads the error messages, it does not retain the users inputed data. How do I make sure the data is carried over if they do not fill in the required fields?

For text fields and textarea's, you need to echo the variable in the value.


//For text fields, echo the variable that you set at the top that contains the user's previously entered info
<input type="text" name="first" value="<?=$first?>" />


//For textareas, echo the variable in between the <textarea> tags
<textarea name="content"><?=$content?></textarea>


//For checkboxes, you need to do an if statement to see if the value of the checkbox matches what the user had selected
<input type="checkbox" name="category" value="cat1" <?php if($category=='cat1') {echo 'checked="checked"';}?> />

colindunn
05-10-2007, 03:17 AM
Thanks, that did the trick. So what if it is a drop down menu/list? Or a radio button?

mr e
05-10-2007, 03:28 AM
Radio buttons work just like checkboxes, and selects do too only you'd use selected="selected" instead of checked

colindunn
05-10-2007, 04:01 AM
I got it all to work except the radios. Am I doing something wrong?

<td style="text-align: right">Title</td>
<td><input name="title" type="radio" value="Mr." <?php if($title=='Mr.') {echo 'selected="selected"';}?> />&nbsp;Mr.
<input name="title" type="radio" value="Mrs." <?php if($title=='Mrs.') {echo 'selected="selected"';}?> />&nbsp;Mrs.
<input name="title" type="radio" value="Ms." <?php if($title=='Ms.') {echo 'selected="selected"';}?> />&nbsp;Ms.
<input name="title" type="radio" value="Miss." <?php if($title=='Miss.') {echo 'selected="selected"';}?> />&nbsp;Miss</td>

PappaJohn
05-10-2007, 04:26 AM
For radio buttons use checked="checked" not selected="selected"

colindunn
05-10-2007, 04:44 AM
I really cannot thank you all enough. You all have been very helpful and very patient. There really is not many places like this on the web. I am now going to try and continue the cycle of helping.