?
Solved

Disabled controls don't pass CGI values?

Posted on 2011-04-30
4
Medium Priority
?
326 Views
Last Modified: 2013-12-25
Hi Experts,

I've been working on some perl & HTML code, and it's been working fine, passing a value from its field, back into itself after submission.  However, if the field ever gets disabled during the run, the value of the field seems to not get passed back as a parameter.  Here's a simplified version of the code to demonstrate the problem:
#!/usr/bin/perl

use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);

my $cgi = CGI->new;
my $test1 = $cgi->param('test1');
$test1 *= 2 if $test1;

$disabled = "disabled" if ...some condition...;

print <<EOF;
Content-Type: text/html; charset=utf-8\n
<html>
<body>
  <form method="post" name="main">
    <input name="test1" value="$test1" $disabled>
    <input type="submit" name="submit" value="Submit">
  </form>
</body>
</html>
EOF

Open in new window

Questions:

1. Why does the value not get passed when the field is disabled?  (I don't get this problem if I use "readonly" for example, but I'm not keen on using readonly, for other reasons.)

2. How can I get around this (i.e. make it so the value is still passed when the control is disabled)?

3. By the way, when should I use 'disabled="disabled"' and when should I use just 'disabled'?

Thanks.
Tel2
0
Comment
Question by:tel2
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
mwochnick earned 2000 total points
ID: 35497025
when you disable an input field it is not sent as part of the form - if you want to pass a value on a form post in this case you probably need to use a hidden input item - wouldn't show to the user but it would be on the form
<input type="hidden" ....
http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_HIDDEN.html

here's an article on READONLY and DISABLED
http://www.htmlcodetutorial.com/forms/_INPUT_DISABLED.html
0
 
LVL 12

Author Comment

by:tel2
ID: 35499480
Hi mwochnick,

Thanks for your response.

Yes, I had started trying using a hidden field (having guessed that might be the work around) before posting this, but was hoping there was a more elegant option.  Maybe there isn't.

Are you able to answer question 3?  Is the longer form to do with XHTML compatibility, as a website I saw seemed to indicate?

Thanks.
0
 
LVL 12

Assisted Solution

by:mwochnick
mwochnick earned 2000 total points
ID: 35501709
question 3 - you are correct - XHTML has much stricter syntax rules than HTML

Here's a tutorial on XHTML that is a pretty quick read
http://www.w3schools.com/xhtml/default.asp
it includes the following chapter on syntax
http://www.w3schools.com/xhtml/xhtml_syntax.asp
and the following chapter on the differences between html and xhtml
http://www.w3schools.com/xhtml/xhtml_html.asp
0
 
LVL 12

Author Closing Comment

by:tel2
ID: 35502223
Thanks for all that, mwochnick.

Good to have you on the EE team.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question