Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Making forms sticky

Featured Replies

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!

  • 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?

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.

  • 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?

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.