I tried making a contact form with quite a bit of success, until i started playing around with my "access.php" (form processing script). I never actually got a single email though.
first question: can you guys help me "fix" this code (make it simpler, more "valid", WORK lol)
second:when the form is submitted, is it possible so that instead of the browser going to the "action.php", it stays at the "contact.php", only it doesn't show the original form, but it shows either the forum with error messages, or a success note? this is important to me because i will later "include" the form.php in my contact.php which containts layout etc.
3: specificalities of my form: "last name/name/email/message/at least one checkbox" must be all set.
4: how i made the error messages: i put a "print "$variable" as the (value="<php print...>") in each text finput. if any value is "!", or all of the checks are "!", my script "requires" the form, and sets a variable for "$variable".
5: additional note: if at least one box was checked, but there was an error, i want the box that was checked checked="checked" when it "require"s the form.
I do not expect anyone here to write me a contact form and processing script. I want to learn php on this example. form.php is in xhtml1.0s. i'm sorry the code is so cluttered.
finaly the codes:
relevant code of form.php=
<div style="text-align:center;">
<form action="action.php" method="post">
<div><input type="hidden" name="form" /></div>
<table width="599" border="0" cellpadding="5" cellspacing="5">
<tr>
<td><div style="text-align:left;">First name:
<input type="text" name="name" <?php print "value=\"$name\"";?> /><span style="color:red; font-size:18px; font-weight:bold;"> <?php echo "$nam"; ?></span>
</div></td>
</tr><tr>
<td><div style="text-align:left;">Last name:
<input type="text" name="lastName" <?php print "value=\"$lastName\"";?> /><span style="color:red; font-size:18px; font-weight:bold;"> <?php echo "$lnam"; ?></span>
</div>
</td>
</tr>
<tr>
<td><div style="text-align:left;">E-mail address:
<input type="text" name="email" <?php print "value=\"$email\"";?> /><span style="color:red; font-size:18px; font-weight:bold;"> <?php echo "$em"; ?></span>
</div></td>
</tr>
</table>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td><div style="text-align:left;"><input type="checkbox" name="des" /> Web (re)design</div></td>
<td><div style="text-align:left;"><input type="checkbox" name="dev" /> Web (re)development</div></td>
</tr>
<tr>
<td><div style="text-align:left;"><input type="checkbox" name="seo" /> SEO (Search Engine Optimization)</div></td>
<td><div style="text-align:left;"><input type="checkbox" name="graph" /> Graphics (re)design</div></td>
</tr>
<tr>
<td><div style="text-align:left;"><input type="checkbox" name="logo" /> Logo design</div></td>
<td><div style="text-align:left;"><input type="checkbox" name="banner" /> Banner design</div></td>
</tr>
<tr>
<td><div style="text-align:left;"><input type="checkbox" name="write" />
Content/copy writing</div></td>
<td><div style="text-align:left;"><input type="checkbox" name="maint" /> Site maintenance</div></td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><span style="color:red; font-size:18px; font-weight:bold;"><?php print "$check";?></span>
</td>
</tr>
</table>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td><div style="text-align:right;">
<textarea name="message" cols="50" rows="5">Your Message. Please be as thorough as possible, so that we can best understand your idea and vision!</textarea>
</div></td>
</tr>
</table>
<table width="300" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><input name="reset" type="reset" value="Reset" /></td>
<td><input name="submit" type="submit" value="Send Mail" /></td>
</tr>
</table>
</form>
</div>
here's the action.php
<?PHP
if (form)
{if (!($email))
{
$em="Please enter a valid email address!";
}
if (!($name))
{
$nam="Please enter your name!";
}
if (!($lastName))
{
$lnam="Please enter your last name!";
}
if (!($des) && !($dev) && !($seo) && !($graph) && !($logo) && !($banner) && !($write) && !($maint))
{
$check="Please check at least one checkbox!";
}
if (!($email) || !($name) || !($lastName) || (!($des) && !($dev) && !($seo) && !($graph) && !($logo) && !($banner) && !($write) && !($maint)))
{
require("form.php");
}
}
$body = "$name $lastName has just sent you the following:\n $message\n web design is $des\n web development is $dev\n SEO is $seo\n graphic design is $graph\n logo design is $logo\n banner design is $banner\n content writing is $write\n site maintenance is $maint";
if (($email) && ($name) && ($lastName) && ($message) && (($des) || ($dev) || ($seo) || ($graph) || ($logo) || ($banner) || ($write) || ($maint)))
{
mail("croatiankid@hotmail.com","inquirey","$body","From:$email");
if (mail==true)
{echo "Your message was successfully sent!");
}
}
?>
thanks in advance to people that want to help