Advertisement

07.14.2008 at 07:50AM PDT, ID: 23562760
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Form validation - error/success message placement

Asked by digitalPencil in PHP Scripting Language, Cascading Style Sheets (CSS), Macromedia Dreamweaver

Tags: , ,

Hi,

I've got a php mail form which uses a combination of javascript and php to validate form data.
The javascript traps errors using livevalidation and displays an asterix next to any empty fields and php traps any other errors like invalid email format, spamwords etc.

The problem is that, the asterix that should be displayed next to the message textarea, is displayed below it, and i would like to move the php success/error messages so they are center aligned instead of at the top of the page which is where they currently display.

I'm pretty new to php, so how would I center align the success/error messages? and, why does the textarea asterix display beneath it instead of displaying at the side?

The form's at davegrant.info/contact.php
and code is attached to this post.

Thanks
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
<?php
if (isset($_POST['submit'])) 
{
        $error = '';
        $msg = '';
        $exploits = "/(content-type|bcc:|cc:|document.cookie|onclick|onload|javascript|alert)/i";
        $profanity = "/(beastial|bestial|blowjob|clit|cock|cum|cunilingus|cunillingus|cunnilingus|cunt|ejaculate|fag|felatio|fellatio|fuck|fuk|fuks|gangbang|gangbanged|gangbangs|hotsex|jism|jiz|kock|kondum|kum|kunilingus|orgasim|orgasims|orgasm|orgasms|phonesex|phuk|phuq|porn|pussies|pussy|spunk|xxx)/i";
        $spamwords = "/(viagra|phentermine|tramadol|adipex|advai|alprazolam|ambien|ambian|amoxicillin|antivert|blackjack|backgammon|texas|holdem|poker|carisoprodol|ciara|ciprofloxacin|debt|dating|porn)/i";
        $bots = "/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|PycURL|AlphaServer)/i";
        
        if (preg_match($bots, $_SERVER['HTTP_USER_AGENT'])) 
        {
        $error .= 'Known spam bots are not allowed.';
        }
        else
        {
                foreach ($_POST as $key => $value) 
                {
                $value = trim($value);
                
                        if (empty($value)) 
                        {
                        $msg .= 'Validation Error: Empty fields<br />';
                        } 
                        elseif (preg_match($exploits, $value)) 
                        {
                        $msg .= 'Validation Error: Malicious scripting attributes found!<br />';
                        } 
                        elseif (preg_match($profanity, $value) || preg_match($spamwords, $value)) 
                        {
                        $msg .= 'Validation Error: Profanity and/or spamwords found!<br />';
                        }
                        
                        $_POST[$key] = stripslashes(strip_tags($value));
                        }
                
                        if (!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,6})$",strtolower($_POST['email']))) 
                        {
                        $msg .= 'Validation Error: Invalid email format<br />';
                        }
                        
                        if($msg == '')
                        {
        
                        $recipient = "davegrant85@gmail.com";
                        $subject = "davegrant.info Contact Form";
                        
                        $message = "Contact form mail from davegrant.info: \n";
                        $message .= "Name: {$_POST['name']} \n";
                        $message .= "E-mail: {$_POST['email']} \n";
                        $message .= "Website: {$_POST['website']} \n";
                        $message .= "Feedback: {$_POST['comments']} \n";
                        
                        $headers = "From: davegrant.info <$recipient> \n";
                        $headers .= "Reply-To: <{$_POST['email']}>";
                        
                                if (mail($recipient,$subject,$message,$headers)) 
                                {
                                $msg .= 'Thank you! Your mail was successfully sent to the webmaster. Thank you for your time.';
                                } 
                                else 
                                {
                                $error .= 'Sorry, there was an error and your mail was not sent. Please find an alternative method of contacting the webmaster.';
                                }
                        }
                }
}
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>davegrant - web &amp; graphic designer</title>
<link rel="stylesheet" href="style_con.css" type="text/css" media="screen" />
<script type="text/javascript" src="livevalidation.js"></script>
<style type="text/css">
<!--
.style4 {
	font-size: 13px
}
.button {
	color: #fff;
	background: transparent;
	border: 1px solid #501936;
	padding:4px 15px 4px 15px;
}
input {
	background:none;
	background-color:transparent;
	border:1px solid #501936;
	padding:4px;
	margin-top:3px;
	font-family:"Lucida Grande", "Lucida Sans Unicode", Arial, Sans-serif;
	font-size:11px;
	color:#fff;
}
textarea {
	background:none;
	background-color:transparent;
	border:1px solid #501936;
	padding:4px;
	margin-top:3px;
	font-family:"Lucida Grande", "Lucida Sans Unicode", Arial, Sans-serif;
	font-size:11px;
	color:#fff;
	width:350px;
}
/* Validation Styles - Tweak as needed */
.LV_validation_message{
    font-weight:normal;
    margin:0 0 0 5px;
}
 
.LV_valid {
    color:#501936;
}
	
.LV_invalid {
    color:#7d3370;
}
    
.LV_valid_field,
input.LV_valid_field:hover, 
input.LV_valid_field:active,
textarea.LV_valid_field:hover, 
textarea.LV_valid_field:active {
    border: 1px solid #501936;
}
    
.LV_invalid_field, 
input.LV_invalid_field:hover, 
input.LV_invalid_field:active,
textarea.LV_invalid_field:hover, 
textarea.LV_invalid_field:active {
    border: 1px solid #7d3370;
}
-->
</style>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>
<body>
<div id="outside_container">
	<div id="container"> <a href="http://www.davegrant.info/"><img src="images/logo.jpg" width="286" height="50" id="logo" /></a>
		<ul id="menu">
			<li><a href="index.html">HOME</a></li>
			<li><a href="folio.html">PORTFOLIO</a></li>
			<li><a href="contact.php">CONTACT</a></li>
		</ul>
		<div id="content">
			<div class="column1">
				<h2>contact</h2>
				<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus non ligula nec sem posuere consectetuer. Proin sagittis diam sed sapien. Aliquam sem turpis, semper at, rhoncus in, aliquam at, lorem. Maecenas purus metus.</p>
			</div>
			<div class="column2">
				<p> name<br />
					address<br />
					address<br />
					address<br />
					address<br />
				</p>
			</div>
			<div class="column3">
				<p> email[at]email.com
					[00]00000001 </p>
			</div>
			<div class="column4">
				<?php 
				if((isset($msg)) && ($msg != ''))
				{
				echo '<p>' . $msg . '</p>' . "\n";
				}
				else
				{
					if((isset($error)) && ($error != '')) 
					{
					echo '<p>' . $error . '</p>' . "\n";
					}
					?>
					<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                                                Name:<br>
                                                <input type="text" id="name" name="name"<?php if(isset($_POST['name'])){echo ' value="' . $_POST['name'] . '"';} ?> class="required">
                                                <br>
                                                <script type="text/javascript">
                                                var name = new LiveValidation('name');
                                                name.add( Validate.Presence );
                                                </script>
                                                <br />
                                                
												Email:<br>
                                                <input type="text" id="email" name="email"<?php if(isset($_POST['name'])){echo ' value="' . $_POST['email'] . '"';} ?> class="required">
                                                <br>
                                                <script type="text/javascript">
                                                var name = new LiveValidation('email');
                                                name.add( Validate.Presence );
                                                </script>
                                                <br />
												
                                                Website:<br>
                                                <input type="text" id="website" name="website"<?php if(isset($_POST['website'])){echo ' value="' . $_POST['website'] . '"';} ?> class="required">
                                                <br>
                                                <script type="text/javascript">
                                                var website = new LiveValidation('website');
                                                website.add( Validate.Presence );
                                                </script>
                                                <br />
                                                Message:<br>
                                                <textarea id="comments" name="comments" rows="10" cols="30"><?php if(isset($_POST['comments'])){echo $_POST['comments'];} ?></textarea>
                                                <br>
                                                <script type="text/javascript">
                                                var comments = new LiveValidation('comments');
                                                comments.add( Validate.Presence );
                                                </script>
                                                <br />
                                                <input type="submit" name="submit" value="Send" class="button">
                                        </form>
				<?php } ?>
			</div>
			<div style="clear:both"></div>
		</div>
	</div>
</div>
<div id="footer"> <img src="images/footer_logo.png" width="124" height="24" /> <span id="footer_text"> Portfolio for web and graphic designer, Dave Grant.<br />
	To find out more, <a href="folio.html">See my Work</a>, 
	or <a href="contact.html">Contact</a> me</span> </div>
</body>
</html>
[+][-]07.14.2008 at 08:06AM PDT, ID: 21998690

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 08:09AM PDT, ID: 21998721

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 08:28AM PDT, ID: 21998948

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 08:35AM PDT, ID: 21999015

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 08:48AM PDT, ID: 21999169

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 08:54AM PDT, ID: 21999224

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 07:22PM PDT, ID: 22003736

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 07:26PM PDT, ID: 22003745

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.15.2008 at 06:18AM PDT, ID: 22006623

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, Cascading Style Sheets (CSS), Macromedia Dreamweaver
Tags: php javascript css, all, davegrant.info/contact.php
Sign Up Now!
Solution Provided By: logicalinsanity
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.15.2008 at 06:21AM PDT, ID: 22006659

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628