Results 1 to 3 of 3
  1. #1
    morgenmuffel
    Join Date
    Dec 2004
    Location
    Putaruru
    Posts
    2,904

    Default PHP textarea validation help

    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?


    PHP Code:
    ?>
    <!--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
    Code:
        $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 - This word needs to be a part of the english language, in fact you should use it in everyday conversation

  2. #2
    Elite
    Join Date
    Feb 2005
    Location
    Dunedin
    Posts
    1,597

    Default Re: PHP textarea validation help

    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

    Maybe I'm wrong here..

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

  3. #3
    morgenmuffel
    Join Date
    Dec 2004
    Location
    Putaruru
    Posts
    2,904

    Default Re: PHP textarea validation help

    Quote Originally Posted by gibler
    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

    Maybe I'm wrong here..

    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 - This word needs to be a part of the english language, in fact you should use it in everyday conversation

Similar Threads

  1. HTML validation for the tag iframe
    By Narmie in forum PressF1
    Replies: 3
    Last Post: 14-06-2007, 02:46 AM
  2. Joining - re the validation string
    By Evolbob in forum PressF1
    Replies: 13
    Last Post: 20-11-2006, 05:00 AM
  3. Site validation problems
    By Morgenmuffel in forum PressF1
    Replies: 5
    Last Post: 13-04-2006, 01:00 PM
  4. Validation failed?
    By Apteryx in forum PressF1
    Replies: 3
    Last Post: 20-02-2005, 03:12 PM
  5. Sounds with data validation
    By in forum PressF1
    Replies: 0
    Last Post: 15-11-1998, 11:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •