Dotable - the home of "No worries" hosting!  
 
Home About Products F.A.Q Network Status Affiliates Support Contact Search Terms
 
Dotable currently hosts more than 20,000 domains for clients from all parts of the planet. Dotable is an owner operated hosting company, with Dotable's owner's Bob and Steve having 15 years of combined hosting experience between them, going back to 2001.

Dotable offers a wide but focused range of hosting products. So if you're looking to purchase a domain, or host 1 domain, or need to host multiple domains, or need a reseller account, or a VPS account or a dedicated server, at Dotable we've got you covered.

Dotable mascot! Welcome to Dotable
Go Back   Dotable - Dot your Domains™ > Dotable Lounge
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11th March 2008, 05:46 AM   #1 (permalink)
Cross Hare
 
Join Date: Jul 2006
Location: Scotland
Posts: 441
Default PHP / HTML problem

Hey all,

I've been banging my head off a brick-wall for the last hour or so; I'm running through some PHP code to create a custom HTML form (depending on records in database). The form itself acts as a sign-up for sessions / classes. Certain sessions require all classes to be taken whereas other sessions have classes where the user can pick or choose.

On form submission, I was having difficulties processing the data. In the instance where sessions required all classes to be taken, I was showing the checkboxes but with both DISABLED and CHECKED properties. I've now realised that even with CHECKED being supplied, the checkbox is ignored (I'm guessing due to DISABLED)

Anyone know a way around this? I obviously don't want to have the checkbox user-alterable as... well, some users will uncheck 'em! Hope someone has expertise in this area


Cheers,
andy
waldo is offline   Reply With Quote
Old 11th March 2008, 08:54 AM   #2 (permalink)
Member
 
Join Date: Jun 2006
Posts: 61
Default

So a checkbox that's checked and disabled doesn't show up in the form submission? I never noticed that before. How strange...

Still, since you can't trust user input anyway, you really need to use the same logic in form processing / validation as you did for form generation - ie. if the session requires all classes to be taken (and the form has these checked and disabled) then you can safely ignore the lack of user input and set all true.

Alternatively you could just change the form generation so for checked and disabled it displays a dummy checkbox under a different name and a hidden field in the name you want. You'd still need validation as above anyway.

HTH
foobic is offline   Reply With Quote
Old 12th March 2008, 01:29 PM   #3 (permalink)
New Dotable member
 
Join Date: Feb 2006
Location: Brazil
Posts: 8
Post Disable means "do not submit"

When a form element is disabled it will not be submited with the form. If you want it disabled by default, then handcode its value in your response script.

If you need to script this checkbox behaviour and don't want your user to interact directly, use a hidden field to accept the values this script will set before your user submit the form.
Ricardo is offline   Reply With Quote
Old 14th March 2008, 08:18 AM   #4 (permalink)
Cross Hare
 
Join Date: Jul 2006
Location: Scotland
Posts: 441
Default

I think I'll go down the hidden field route so that, even if a user does uncheck a check box, the correct response will still be taken (beats extraneous coding in the submission / validation stage of the code).

Thanks for the replies
waldo is offline   Reply With Quote
Old 14th March 2008, 09:32 AM   #5 (permalink)
Member
 
Join Date: Jun 2006
Posts: 61
Default

I wouldn't ever call server-side validation "extraneous coding". There's a simple principle here: trust nothing you get from the user.

Hidden fields can be changed too - not quite as easily as clicking a checkbox but it's not hard to do.
foobic is offline   Reply With Quote
Old 14th March 2008, 11:16 AM   #6 (permalink)
New Dotable member
 
Join Date: Feb 2006
Location: Brazil
Posts: 8
Default

If you know the variable will not be changed, then you do not even need to use a hidden field, because there is no meaning in sending to the server this fixed information. Then, just use the checkbox as a visual clue for the user. And if the checkbox is disabled, the user will not be able to uncheck it.

I do agree with foobic, validation is never extraneous. It is absolutely necessary.
Ricardo is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Go Back   Dotable - Dot your Domains™ > Dotable Lounge


All times are GMT +10. The time now is 04:38 AM.


Home About Products F.A.Q Network Status Reasons Support Contact Search Terms

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0