June 20, 201214 yr I've amended someone else's website to make some form fields sticky. When I tested it locally it worked fine, but now that he has uploaded the files its not working. The checkbox, select options and file attachment fields are not retaining the user-input values when the form is submitted for CAPTCHA validation. I know I can't retain the value inside the file attachment field, but I was hoping to display the name of the file adjacent to the input field. The site is pretty old school with bits of flash and the whole layout is table based. His host provider is running version 5.something PHP. Below are the code snippets I've used <div class="field"><input name="Upload_File" type="file" /><?php echo $_SESSION['CSAFORM']['Upload_File'];?></div> <input name="Fax" type="checkbox" title="Fax" value="I am faxing a copy of my bill" label="I am faxing a copy of my bill" <?php if (isset($_POST['Fax']) && $_POST['Fax'] == "I am faxing a copy of my bill") {echo "checked";}?> /> <select name="Product_Type"> <option>Choose an Option</option> <option value="New Products" <?php if (!empty($_POST['Product_Type']) && $_POST['Product_Type'] == "New Products") {echo 'selected';}?>>New Products</option> <option value="Upgrades"<?php if (!empty($_POST['Product_Type']) && $_POST['Product_Type'] == "Upgrades") {echo 'selected';}?>>Upgrades</option> </select> and below is the code snippet that the original developer is using for an input type text field <input name="Postcode" type="text" id="Postcode" label="Postcode" style="width:250px;" value="<?=$_SESSION['CSAFORM']['Postcode']?>"/> Please could you suggest where I'm going wrong - presumably there is no code conflict? Thanks for any help as I was hoping to get some work or at least a decent reference on the back of this!
June 20, 201214 yr Author I guess I needed to use session data as the $_POST data was getting lost when the script went off to do CAPTCHA validation. I changed $_POST to $_SESSION['CSAFORM'] and its working except the file name isn't being displayed next to the file upload input field. Any suggestions?
June 20, 201214 yr You will need to use $_FILE superglobal. I cant give you the exact syntax because I cant see all of the form but it will probably be: $_FILES['Upload_File']['name']; If you cant figure that out then print_r($_FILES) to get the correct array notation.
June 21, 201214 yr Author Thanks Jock $_FILES['Upload_File']['name']; worked a treat. Just to confirm my understanding... when uploading a file within a form, is it only accessible via the $_FILES superglobal and not $_POST? In this instance the form data was sent to 2 other scripts for validation where a session was started and captcha processing before returning to the calling script with the results of validation, so would the file name be accessible in $_SESSION or only ever in $_FILES?
June 21, 201214 yr Thanks Jock $_FILES['Upload_File']['name']; worked a treat. Just to confirm my understanding... when uploading a file within a form, is it only accessible via the $_FILES superglobal and not $_POST? In this instance the form data was sent to 2 other scripts for validation where a session was started and captcha processing before returning to the calling script with the results of validation, so would the file name be accessible in $_SESSION or only ever in $_FILES? Yes you can only acccess using $_FILES superglobal i mean you always could store the name of a file in a session like this $_SESSION['file'] = $_FILES['UploadedFile']['name']; but yea normally just accessable using the files superglobal
Create an account or sign in to comment