Disabled controls don't pass CGI values?

Posted on 2011-04-30
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:

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
  <form method="post" name="main">
    <input name="test1" value="$test1" $disabled>
    <input type="submit" name="submit" value="Submit">

Open in new window


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

Question by:tel2
    LVL 12

    Accepted Solution

    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" ....

    here's an article on READONLY and DISABLED
    LVL 11

    Author Comment

    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?

    LVL 12

    Assisted Solution

    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
    it includes the following chapter on syntax
    and the following chapter on the differences between html and xhtml
    LVL 11

    Author Closing Comment

    Thanks for all that, mwochnick.

    Good to have you on the EE team.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    Reason for High TTFB 1 20
    Javascript - getdate 5 32
    php session question (Code Igniter) 5 22
    inactive users 13 33
    This article will show, step by step, how to integrate R code into a R Sweave document
    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now