Forum Home
Press F1
 
Thread ID: 55701 2005-03-17 07:13:00 PHP textarea validation help Morgenmuffel (187) Press F1
Post ID Timestamp Content User
335049 2005-03-17 07:13:00 Greetings all
I am having a problem with some server side validation for a form using php
The problem is specifically related to textareas .

What i want to happen is . . .
the user enters the information in the various fields, then clicks the submit button, this validates the contents of the text fields and textareas and If a field does not validate properly, the original form will be displayed again with all the submitted values in it, and the incorrect field highlighted in red .

What is happening is that this works for text fields, but not properly for textareas with textareas the submitted values aren't being put back in, it validates correctly ie if I put something too long in a textarea and hit submit, the textarea is highlighted in red but it is empty

The textarea values are available, I can grab them with an echo statement but I want to know why the code below doesn't work, is it not possible to set the value of a textarea to a string?



?>
<!--THIS BIT WORKS-->
<tr valign="top"><!-- Job Title -->
<td align="right" bgcolor="#00CC00"<?php if(!$jn) echo 'class="error"'; ?>>
Job Title</td>
<td bgcolor="#00CC00">&nbsp;</td>
<td bgcolor="#FFFFCC"><input type="text" name="job_name" size="50" value="<?= $job_name ?>"></td>
</tr>
<!--THIS BIT DOESN'T WORK PROPERLY-->
<tr valign="top"><!-- Job Description -->
<td align="right" bgcolor="#00CC00"<?php if(!$jd) echo 'class="error"'; ?>>
Job Description</td>
<td bgcolor="#00CC00">&nbsp;</td>
<td bgcolor="#FFFFCC">
<TEXTAREA name="job_description" rows="5" cols="50" value="<?= $job_description ?>">
</TEXTAREA>
</td>
</tr>




Basically the problem seems to be how to insert a string into a textarea
this is what happens to the text after it is submitted it should come out as a string


$job_name =trim($job_name);//this works
$valid = $jn = checkLength($job_name, 1, 50);
$job_description =trim($job_description);//this doesn't
$job_description =nl2br($job_description);
$jd = checkLength($job_description, 1, 5);
$valid = $valid && $jd;



anyhelp would be much appreciated

Thanks Nigel
Morgenmuffel (187)
335050 2005-03-17 10:49:00 Er, I don't believe textarea has a value option . IF you want to show the value in a textarea you stick it between the opening and closing tag e . g . <textarea name="some_name"><?php echo $my_submitted_value; ?></textarea>

textarea ref ( . htmlhelp . com/reference/html40/forms/textarea . html" target="_blank">www . htmlhelp . com)

Maybe I'm wrong here . . :2cents:

You want to guard a wee bit more against people trying to insert html or possibly values to try and manipulate sql queries . .
gibler (49)
335051 2005-03-17 19:14:00 Er, I don't believe textarea has a value option . IF you want to show the value in a textarea you stick it between the opening and closing tag e . g . <textarea name="some_name"><?php echo $my_submitted_value; ?></textarea>

textarea ref ( . htmlhelp . com/reference/html40/forms/textarea . html" target="_blank">www . htmlhelp . com)

Maybe I'm wrong here . . :2cents:

You want to guard a wee bit more against people trying to insert html or possibly values to try and manipulate sql queries . .

Thanks somehow i missed that, I feel stupid now, especially after having read similar pages and not even noticed

as to the second bit I will be doing that but I have been focusing on this one problem to the exclusion of everything else
Morgenmuffel (187)
1