plastik77 Posted November 28, 2007 Share Posted November 28, 2007 Hi, i'm having a strange problem when processing some form data. I just want to validate that required fields have been populated, then, if an image has been uploaded, i want to ensure that a description of the image has been provided (for alt tag purposes) before processing the data. For some reason, when a file hasn't been attached, my script interprets it otherwise and prompts the user for the alt tag. I've not come across this problem before, there's a good chance i've done something idiotic but i just can't see it - any help greatly appreciated. I've just used a simple test: if (isset($_FILES))....but this condition is always true, even when no file has been attached! // Check whether a form has been submitted. If so, carry on if (isset($_POST['Submit']){ // Validate the entries $validator = new Validator(); $validator->validateGeneral($_POST['title'],'Article Title'); $validator->validateGeneral($_POST['tagline'],'Tagline'); $validator->validateNumber($_POST['section'],'Section'); $validator->validateGeneral($_POST['thearticle'],'Article'); //if a file has been attached, check for the alt tag first, before processing if (isset($_FILES)) { echo "Test!"; $validator->validateGeneral($_POST['description'],'Description'); } // Check whether the validator found any problems if ($validator->foundErrors() ){ $error = "<h5>Error! There was a problem with the following fields: <br/>".$validator->listErrors('<br/>')."</h5>"; // Show the errors, with a line between each } else{....all the data processing code here is the html form info <form name="form1" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <h3><?php echo $error; echo $my_upload->show_error_string(); ?></h3> <fieldset> <legend>New Article</legend> <label>Title: <input name="title" type="text" id="title"/> </label> <label>Tagline: <input name="tagline" type="text" id="tagline"/> </label> <label>Section: <select name="section" id="section"> <?php // Generate a drop-down list of sections. $result = $connector->query('SELECT ID,name FROM cmssections ORDER BY name'); // Get an array containing the results. // Loop for each item in that array while ($row = $connector->fetchArray($result)){ echo '<option value="'.$row['ID'].'">'.$row['name'].'</option>'; } ?> </select> </label> <label>Article: <textarea name="thearticle" cols="50" rows="6" id="thearticle"></textarea> </label> <p>Max. filesize = <?php echo $max_size; ?> bytes.</p> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>"/> <label> Upload file: <input type = "file" name="upload" /> </label> <p>Please enter a description of the image, if attached:</p> <label>Description:<input type = "text" name = "description" size = "25"/> </label><br/><br/> <input type="submit" name="Submit" value="Submit"/> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.