Page 1 of 1

Validation and error checking help

Posted: Fri May 07, 2010 1:37 pm
by MiniMonty
Hi all,

I have a form for users to upload images and comments on those images.
The whole form is held in a variable called (wait for it...) $form :D

I'd really appreciate some help coding a check to see that they have chosen 5 images and
written 5 comments when they hit "Upload" because all my attempts have failed dismally.

Here's the bad boy in question (the actual upload is handled by a separate page quoted in the form action).

All and any help much appreciated
best wishes
Monty

Code: Select all

{ $bodyCopy ='<span class="greyText">Upload your pictures and text.</span><br><br><br><br>' . $errorMsg;
	$form = '<form enctype="multipart/form-data" action="coursework_insert.php?courseName='.$courseName.'"  method="post">
<table width="59%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><div align="center"><span class="orangeText"><?php print "$error_msg"; ?></span></div></td>
  </tr>
</table>
  <br>
  <table width="59%"  border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td height="33"><span class="orangeText">Choose your images </span></td>
      <td height="33"><span class="orangeText">Comment on each one (max 2000 characters) </span></td>
    </tr>
    <tr>
      <td width="46%">Image 1:
        <input name="userfile[]" type="file" id="userfile[]" size="0" maxlength="0">      </td>
      <td width="54%"><textarea name="textarea[]" cols="40" rows="2" wrap="VIRTUAL" id="textarea[]" onKeyUp="EnforceMaximumLength(this,2000)"></textarea></td>
    </tr>
    <tr>
      <td>Image 2:
        <input name="userfile[]" type="file" id="userfile[]" size="0" maxlength="0">      </td>
      <td><textarea name="textarea[]" cols="40" rows="2" wrap="VIRTUAL" id="textarea[]" onKeyUp="EnforceMaximumLength(this,2000)"></textarea></td>
    </tr>
    <tr>
      <td>Image 3: 
      <input name="userfile[]" type="file" id="userfile[]" size="0" maxlength="0">      </td>
      <td><textarea name="textarea[]" cols="40" rows="2" wrap="VIRTUAL" id="textarea[]" onKeyUp="EnforceMaximumLength(this,2000)"></textarea></td>
    </tr>
    <tr>
      <td>Image 4: 
      <input name="userfile[]" type="file" id="userfile[]" size="0" maxlength="0">      </td>
      <td><textarea name="textarea[]" cols="40" rows="2" wrap="VIRTUAL" id="textarea[]" onKeyUp="EnforceMaximumLength(this,2000)"></textarea></td>
    </tr>
    <tr>
      <td>Image 5: 
      <input name="userfile[]" type="file" id="userfile[]" size="0" maxlength="0">      </td>
      <td><textarea name="textarea[]" cols="40" rows="2" wrap="VIRTUAL" id="textarea[]" onKeyUp="EnforceMaximumLength(this,2000)"></textarea></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center"><br>        
          <input name="submit" type="submit" id="submit" value="Upload" />
      </div></td>
    </tr>
  </table>
</form>';

Re: Validation and error checking help

Posted: Fri May 07, 2010 5:46 pm
by yacahuma
be careful with images. Someone could upload a php sccript as an image and then execute whatever php code they wanted.

Re: Validation and error checking help

Posted: Sat May 08, 2010 9:04 pm
by MiniMonty
Thanks for that warning - anyone got any advice on how to validate the form ????

Re: Validation and error checking help

Posted: Sun May 09, 2010 1:46 pm
by MiniMonty
Small Bump...