Solved

I want to write validating error message to the right of textarea box

Posted on 2008-10-26
5
254 Views
Last Modified: 2010-04-21
There are 2 things I want to achieve on this web page:
1. Preserve visitor input on the form when the form is redisplayed.
2. I want to write validating messages on the right side of the form fields.
 
I need help to figure out how I can achieve both requirements for a textarea box.

<p><label for="emailAddr">Email Address</label> 

<input id="emailAddr" type="text" name="emailAddr" maxlength="51"

value="<?php echo $emailAddr; ?>" />

<?php

	if (array_key_exists('emailAddr', $fmErrors)) {

		echo '<span class="nobr">';

		echo ' ';

		echo $fmErrors['emailAddr'];

		echo '</span>';

		}

?>

</p>

<!-- prayer request --> 

<p><label for="prayerReq">Write Your Prayer Request</label>

<textarea id="prayerReq" name="prayerReq" rows="10" cols="51">

<?php echo $prayerReq; ?></textarea></p>

Open in new window

0
Comment
Question by:Abeam
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:denniscm20
ID: 22810024
Hi,

First, you have to tell the page to redirect to itself after submmiting the values.  You can do it using the action paprameter inthe Form tag.

Let's say that your file name is Contact.php.

Please, follow the example in the attached code.

I hope this will help you.


$errorMessage = "";

$error = false;

if (isset($_POST["submit"])) {

  // Insert here your validation code

  // if there is an error set the error variable $error = true

  // and the error Message variables $errorMessage = "My Error Message"

}
 

<form id="submitForm" action="Contact.php" method="POST">

<p><label for="emailAddr">Email Address</label> 

<input id="emailAddr" type="text" name="emailAddr" maxlength="51"

value="<?php echo isset($_POST["emailAddr"])?$_POST["emailAddr"]:""; ?>" />

<?php

        if (array_key_exists('emailAddr', $fmErrors)) {

                echo '<span class="nobr">';

                echo ' ';

                echo $fmErrors['emailAddr'];

                echo '</span>';

                }

?>

</p>

<!-- prayer request --> 

<p><label for="prayerReq">Write Your Prayer Request</label>

<textarea id="prayerReq" name="prayerReq" rows="10" cols="51">

<?php echo  isset($_POST["prayerReq"])?$_POST["prayerReq"]:""; ?></textarea><?php if ($error) { echo $errorMessage }?></p>

<p><input name="submit" type="submit" value="submit"></p>

</form>

Open in new window

0
 

Author Comment

by:Abeam
ID: 22818704
Thanks denniscm20. The error message is below the textarea. Is it possible to place the error message to the Right of the textarea? That is where I want it - to the right side of the textarea.
0
 
LVL 1

Accepted Solution

by:
denniscm20 earned 500 total points
ID: 22818718
Yeah, it is possible.

The simpliest way to do that is putting the textarea into a table tag
<table><tr><td><label for="prayerReq">Write Your Prayer Request</label></td><td>

<textarea id="prayerReq" name="prayerReq" rows="10" cols="51">

<?php echo  isset($_POST["prayerReq"])?$_POST["prayerReq"]:""; ?></textarea></td><td><?php if ($error) { echo $errorMessage }?></td></tr></table>

Open in new window

0
 

Author Comment

by:Abeam
ID: 22828154
denniscm20 thanks again. This is neat.
BTW I have 2 consecutive 14-hour shifts after that I will let you. Thanks for your help.
0
 

Author Closing Comment

by:Abeam
ID: 31510135
Thanks for the lead.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DotNetNuke Redirect 3 170
PHP OAuth Uncaught exception 'OAuthException' 3 53
Configure a website to disconnect/timeout after 30 minutes 1 448
Apple workstations and domain 5 55
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now