Re: [PHP] validating textarea using php

[email protected] (Thijs Lensselink)
Newsgroups php.general
Message-ID <[email protected]>
Quoting Sudhakar <[email protected]>:

> hi
>
> i need to validate textarea of a html form using php
>
> <textarea name="comments" cols="26" rows="3" id="comments"><?php
> echo($comments);?></textarea>
>
> presently my php code to validate the text area is
>
> if($comments == "" )
> {
> $error.="<br>Please enter your comments";
> }
>
> with this code if a user hits the space bar once or couple of times as a
> matter of fact there are no characters entered by the user i do not want
> this to happen, if a user simply hits the spacebar and does not type
> anything i should be able to display an alert message.
>
> please advice how i can change the above php code.

PHP is sevrer sided. So if you want to check if a user provided the
textarea with input. You have to submit the page. and let PHP do the magic.
If the textarea is not filled. You could send the user back to the form.
With an apropriat warning message.

It's probably easier to do it with client side javascript.
Check the contents of the textarea on submit and preform some actions  
from there.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.