• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

Disabled controls don't pass CGI values?

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
tel2
Asked:
tel2
  • 2
  • 2
2 Solutions
 
mwochnickCommented:
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
 
tel2Author Commented:
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
 
mwochnickCommented:
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
 
tel2Author Commented:
Thanks for all that, mwochnick.

Good to have you on the EE team.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now