Field Validation Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Field Validation Question

Post by Celauran »

Oh, I see. That's normal behaviour because you're just echoing it out. Instead, assign it to a variable and echo that variable (when it exists) somewhere inside the HTML.
Pavilion
Forum Contributor
Posts: 301
Joined: Thu Feb 23, 2012 6:51 am

Re: Field Validation Question

Post by Pavilion »

Celauran - Thank you for your help on all of this. I did as you suggested and things are functioning now.

In addition to your suggestion, I also took it upon myself to move all error handling messages to the bottom of the table within a separate <td></td> block. Now the messages display beneath the input elements.

Before posting my html code, I really do want to thank you. I know this is a php forum, so html/css questions are out of scope. I did try posting my questions on other forums - geared more towards html/css. But the guidance wasn't adequate. If you know of a good html/css forum, please refer me. Following is the html portion of my register.php - your input is welcome. I want to learn to do this right.

Code: Select all

<!DOCTYPE html>
<html>
<body>
<div class="header"><head>
<a><IMG SRC="/schedule/images/banner3.jpg" ALT="" WIDTH=98% HEIGHT=120"></a>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<title>Contact Form</title>
</head></div>
<form action="" method="post">
<div class="borderbx">
	<h1 style="text-align:left; padding-left:50px;"><i>Register Here .... </i></h1>
</div>
	<table align="left" style = "width=25%; margin-left: 30px;">
		<tr>
		<td align="right">
		<label for="fname">First Name</label>
		</td>
		<td align="left">
			<input tabindex="1" type="text" name="fname" />
		</td>
		<td align="right">
			<label for="password">Password</label>
		</td>
		<td align="left">
			<input tabindex="4" type = "password" name="password" />
		</td>
		</tr>
		<tr>
		<td align="right">
			<label for="lname">Last Name</label>
		</td>
		<td align="left">
            <input tabindex="2" type="text" name="lname" />
		</td>
		<td align="right">
			<label for="password2">Verify Password</label>		
		</td>
		<td align="left">
			<input tabindex="5" type = "password" name="password2" />
		</td>
		</tr>
		<tr>
		<td align="right">
            <label for="email">Email Address</label>
		</td>
		<td align="left">
            <input tabindex="3" type="email" name="email" />
		</td>
		<td align="right">
            <input style="font-weight:bold;" tabindex="6"type="submit" value="Submit" />
		</td>
		</tr>
		<tr>
		<td></td> <!-- This block was added simply as a spacer. Without this spacer, the error text in the next block throws the entire table out of alignment. -->
		<td align="left"> <!-- This block of code/script does the error reporting. Nothing is vislbe until there is an error. -->
            <?php if (isset($errors['fname'])): ?>
            <span class="error"><?php echo $errors['fname']; ?><br /></span>
            <?php endif; // See an explanation of this coding at devnetwork.net forums - topic "Field Validation Question": http://forums.devnetwork.net/viewtopic.php?p=672372#p672372?		
		
			<?php if (isset($errors['password'])): ?>
			<span class="error"><?php echo $errors['password'];?><br /></span>
			<?php endif; ?>
			
            <?php if (isset($errors['lname'])): ?>
            <span class="error"><?php echo $errors['lname']; ?><br /></span>
            <?php endif; ?>
			
			<?php if (isset($errors['password2'])): ?>
			<span class="error"><?php echo $errors['password2'];?><br /></span>
			<?php endif;?>
			
			<?php if (isset($errors['email'])): ?>
			<span class="error"><?php echo $errors['email'];?><br /></span>
			<?php endif; ?>
		</td></tr>
	</table>
	
	<div class="borderbx" style="margin-top: 25%; margin-left: 30px; margin-right: 50%">
	<p style="text-align: center;"><?php echo $confirmation; ?></p></div>
</form>
</body>
</html>
Moving the error messages to one block of code (at the bottom of the table) "fit" the way I like to do things. Not only is it "cleaner" on the page, when error messages show up. But, for me anyway, it's cleaner in the php file. The table is more streamlined when reading the script, it's easier for me to grasp what is happening, and where it is happening.

Thanks again for all your patience:

Pavilion
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Field Validation Question

Post by Celauran »

Pavilion wrote:I know this is a php forum, so html/css questions are out of scope. I did try posting my questions on other forums - geared more towards html/css. But the guidance wasn't adequate. If you know of a good html/css forum, please refer me.
Have you tried the HTML/CSS forum right here?
Pavilion
Forum Contributor
Posts: 301
Joined: Thu Feb 23, 2012 6:51 am

Re: Field Validation Question

Post by Pavilion »

Celauran wrote:
Pavilion wrote:I know this is a php forum, so html/css questions are out of scope. I did try posting my questions on other forums - geared more towards html/css. But the guidance wasn't adequate. If you know of a good html/css forum, please refer me.
Have you tried the HTML/CSS forum right here?
:lol: :D :lol: OMG .... no... I hadn't. My book mark takes right to the programming forum and I must confess, the PHP Developers Network name threw me. I just assumed (never assume - but I did) that the forum was all php. Well now I know better.

I will post a new topic there in a minute. I did some more cleaning of my html code this morning, after a fresh night of sleep and it's now even more streamlined. I'll post it in a new topic at the forum you suggested, and I look forward to your feedback.

Thanks again: Pavilion
Post Reply