FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


validating textarea...





zacky
I'm a novice level in PHP. I'm having trouble for this error that i got and i'm almost raising my white flag to it. I'm currently validating a form which includes a textarea. All things are okay except to my textarea.

This is the validation for my textarea:
NOTE: for meanwhile, i want just want to make sure that the textarea is not empty...
Code:


$errors = array();
$Comments = $_POST['Comments'];

if (empty($Comments)){

   $errors[] = "Comments";

   $i4 = "id='Ccbad'";

   $set = TRUE;
}


This is my textarea:
Code:


<label id="Clabel" for="Comments"> Comment:

<textarea cols="80" rows="15" name="Comments" title="Make sure your typing something"

<?php formColorChecker2( $errors, $i4 ); ?> id="textarea">

<?php valueChecker ($errors, $Comments); ?>

</textarea>
</label>



The formColorChecker() and valueChecker() is a function.


I figured it out what's the problem and it's all about a default couple of spaces when i'm typing in my textarea. When I remove white spaces of course, function empty will execute, but what if users just send the submit button without removing the default white spaces? that will cause an error to me.


All I want i to know is how to remove that default white extra spaces in my textarea. I will appreciate any form of ideas. Thank you so much.. Smile
zacky
YES i got it... even though no one has yet replying.. but anyway just for others who get some probs. here's the solution that i came up.

Code:


$errors = array();
$Comments = $_POST['Comments'];
$Comments = trim($Comments);
if (empty($Comments)){

   $errors[] = "Comments";

   $i4 = "id='Ccbad'";

   $set = TRUE;
}



All i do is just to trim the textarea before validating it if it is empty or not...

this line of code was really help me.. $Comments = trim($Comments);
Fire Boar
Alternatively you could have just deleted the new lines after the </textarea>:

Code:
<label id="Clabel" for="Comments"> Comment:

<textarea cols="80" rows="15" name="Comments" title="Make sure you type something"<?php formColorChecker2( $errors, $i4 ); ?> id="textarea"><?php valueChecker ($errors, $Comments); ?></textarea>
</label>
imagefree
zacky wrote:
YES i got it... even though no one has yet replying.. but anyway just for others who get some probs. here's the solution that i came up.

Code:


$errors = array();
$Comments = $_POST['Comments'];
$Comments = trim($Comments);
if (empty($Comments)){

   $errors[] = "Comments";

   $i4 = "id='Ccbad'";

   $set = TRUE;
}



All i do is just to trim the textarea before validating it if it is empty or not...

this line of code was really help me.. $Comments = trim($Comments);


you should be aware that in case user's comments contain spaces or new lines in the end or in the beginning of comments, thoses spaces etc will be removed by the trim() function. Although it will not cost you in most cases (infact it will help you strip extra characters from the comments). I just wanted to bring it to your knowledge. If you do not want to trim user's comments, just use the solution provided by the poster Fire Boar.
zacky
imagefree wrote:
zacky wrote:
YES i got it... even though no one has yet replying.. but anyway just for others who get some probs. here's the solution that i came up.

Code:


$errors = array();
$Comments = $_POST['Comments'];
$Comments = trim($Comments);
if (empty($Comments)){

   $errors[] = "Comments";

   $i4 = "id='Ccbad'";

   $set = TRUE;
}



All i do is just to trim the textarea before validating it if it is empty or not...

this line of code was really help me.. $Comments = trim($Comments);


you should be aware that in case user's comments contain spaces or new lines in the end or in the beginning of comments, thoses spaces etc will be removed by the trim() function. Although it will not cost you in most cases (infact it will help you strip extra characters from the comments). I just wanted to bring it to your knowledge. If you do not want to trim user's comments, just use the solution provided by the poster Fire Boar.


Okay thanks! I will that keep that in mind. I think i will post a lot of errors here that i encounter coz i think people here are very helpful and seriously, learn here than what my teacher thought.. LOL.. but of course not all of the things. Thanks again... Smile
imagefree
zacky wrote:
Okay thanks! I will that keep that in mind. I think i will post a lot of errors here that i encounter coz i think people here are very helpful and seriously, learn here than what my teacher thought.. LOL.. but of course not all of the things. Thanks again... Smile


You are welcome!!!
Related topics
script backup database
[ java scripts ] email service
Okay, I'm done trying to use CSS for layout.
text formatting inside of textarea adds white space
Validating
disable textarea without changing look
Rich Text in textarea?
i need a scroll box textarea please help
need a textarea with scrollbar please help
The information is not displayed in Textarea
Textarea onchange javascript
JS: get value each line in textarea and validate.
[SOLVED]textarea autosave
problem in validating signature of a pdf document
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.