Hello people,
Right now i been creating a form for a comment section, a Login section, and sending email for a site i'm doing. The code I using was from a tutorial I learned and has too much HTML in it. It was the only way I knew how to create a form and valid the data. I wanted to ask if there was a better way to create forms and if there was a way to create a form in OOP PHP? I want learn to go beyond basic stuff to OOP.
Here's an example of the code I using for the moment:
<?php include 'includes/validation.php' ?>
<!-- START CONTENT -->
<div id="mainContent">
<div class="portContentTop"><img src="graphx/image.gif" alt="" border="0" /></div>
<div class="portContent">
<img src="graphx/image.gif" alt="Contact Me" border="0" /><h1 class="hidden">Contact</h1><br />
If you wish to contact me, please fill out the form or send me an email at <a href="mailto:[email protected]">[email protected]</a>.
<br />
<? if( isset($_POST['send'])&& (!validateName($_POST['name']) || !validateEmail($_POST['email']) || !validateMessage($_POST['message']) ) ):?>
<div id="errorMessage">
<ul>
<? if(!validateName($_POST['name'])):?>
<li>Your name must be 4 characters long.</li>
<? endif ?>
<? if(!validateEmail($_POST['email'])):?>
<li>Your email address has an error.</li>
<? endif ?>
<? if(!validateMessage($_POST['message'])):?>
<li>Your comment must be 10 characters long.</li>
<? endif ?>
</ul>
</div>
<?php elseif(isset($_POST['send'])):?>
<?php
$name=strip_tags($_POST['name']);
$email=strip_tags($_POST['email']);
$message=strip_tags($_POST['message']);
$subject= "A message from me was submitted by ".$name." ";
$sentto= "[email protected]";
$contents = "Name: ".$name. "\n".
"Email: ".$email. "\n".
"Message: ".$message. "\n";
mail($sentto, $subject, $contents);
?>
<div id="errorMessage">
<ul class="errorValid">
<li>Your message has been sent.</li>
</ul>
</div>
<? endif?>
<form method="post" id="customForm" name="customForm" action="" >
<table border="0" align="center" cellpadding="0" cellspacing="0" style="padding:0px; margin:0px;">
<tr valign="top">
<td align="center"><img src="graphx/h_name.gif" border="0" alt="Name:" /></td>
<td><input class="contactInput" id="name" name="name" type="text" size="30" /></td>
</tr>
<tr valign="top">
<td align="center"><img src="graphx/h_email.gif" border="0" alt="Email:" /></td>
<td><input class="contactInput" id="email" name="email" type="text" size="30" /></td>
</tr>
<tr valign="top">
<td align="center"><img src="graphx/h_comments.gif" border="0" alt="Comments:" /></td>
<td><textarea id="message" name="message" cols="30" rows="15" wrap="off" class="contactInput2"></textarea></td>
</tr>
<tr valign="top">
<td></td>
<td align="left"><input id="send" name="send" type="submit" value="Submit" ></td>
</tr>
</table>
</form>
</div>
<!-- END CONTENT -->