Solved

PHP $_POST and Disabled Fields

Posted on 2010-08-16
13
1,843 Views
Last Modified: 2012-08-13
in PHP using $_POST, how do I retrieve data from html disabled readonly field?

Using form tags and method=post, which contain disabled fields change by ajax, javascripts from onchange events of other associated fields.

When user submits page, I want to retrieve values from the disabled and readonly fields.  How do I do this in PHP?
0
Comment
Question by:thewyzzard
  • 3
  • 2
  • 2
  • +4
13 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33450114
You can only get what the form or javascript submits.  PHP running on the server can't get anything from the web page any other way.  It just receives what is sent.
0
 
LVL 3

Expert Comment

by:mpvvee
ID: 33450118
just fill the value property for that input and you will get the info
0
 

Author Comment

by:thewyzzard
ID: 33454116
I have the following input textbox on screen that is disabled within a form tag, that gets populated from AJAX....as user selects beginning date, AJAX will populate the ending date.  Ending date is disabled.

When I do a postback to page after user clicks submit there isn't any value getting posted, although there is a value on screen.  This is true for any disabled text box when value='something'.

html:
------------------
<tr>
  <td align="right" valign="top">Ending Date:</td>
  <td align="left" valign="top">
    <span id="txtEndingDate">
       <input class="readonly" readonly="true" disabled="disabled" type="text" name="EndingDate" size="13" maxlength="10" value="$ending_date">
    </span>
  </td>
</tr>



php
------------------
if(isset($_POST['EndingDate']))   { $ending_date    = $_POST['EndingDate']; }



How can I get values from the post?


0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33456668
I'm afraid you can't.  I took your code above and made a test page.  As long as the field is 'disabled', it doesn't appear in the 'POST' array, it isn't being submitted.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33456686
Here's the test page if you want it.  Save it as 'disabled.php' and let it 'post' to itself.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>disabled.php</title>
</head>
<body>
<?php 
print_r($_POST);
$ending_date = "||";
if(isset($_POST['EndingDate']))   { $ending_date = $_POST['EndingDate']; }
 ?>
<table summary="">
<tr>
  <td align="right" valign="top">Ending Date:</td>
  <td align="left" valign="top">
<form action="disabled.php" method="post">
    <span id="txtEndingDate">
       <input class="readonly" readonly="true" disabled="disabled" type="text" name="EndingDate" size="13" maxlength="10" value="<?php echo $ending_date; ?>">
 <!--       <input class="readonly" readonly="true" type="text" name="EndingDate" size="13" maxlength="10" value="<?php echo $ending_date; ?>"> -->
    </span>
<input type="submit" name="submit" value="Submit" />
</form>

</td>
</tr>
</table>
</body>
</html>

Open in new window

0
 
LVL 6

Accepted Solution

by:
ramelong earned 43 total points
ID: 33458849
You can "duplicate" the field with a hidden one:

You will receive the hidden field instead of the text one, while you still can show the disabled text field.
I think that you even name both fields (whith the same name)...
<input class="readonly" readonly="true" disabled="disabled" type="text" size="13" maxlength="10" value="<?=$ending_date?>">
<input type="hidden" name="EndingDate" value="<?=$ending_date?>">

Open in new window

0
 
LVL 5

Assisted Solution

by:sscotti
sscotti earned 82 total points
ID: 33461772
You can try to dynamical enable the form after you populate it via AJAX and still leave it readonly.  That way the user won't be able to change the value but it should be submitted when you post the page.

I tried that and it seems to work:


2.  document.forms[0].EndingDate.value = 'test';
2.  document.forms[0].EndingDate.disabled = false;

POST form.  It will pass the value and the field is still not writable if it is set to readonly.
0
 
LVL 5

Assisted Solution

by:sscotti
sscotti earned 82 total points
ID: 33461781
Why do you have the form element disabled in the first place?  Do you only want to submit that field if you've populated it with something dynamically without user input?
0
 
LVL 2

Expert Comment

by:Tiller79188231
ID: 33467254
use a javascript function to submit the values, javascript can read the value of a disabled field
0
 

Author Comment

by:thewyzzard
ID: 33526137
From within the developers IDE, Websmart BCD, I found this function that will read disabled html elements when the form is submitted..........thanks for all your ideas....but this solution is the one that worked for me....  xl_EnableDisabledElements

<form id="Detail"  action="thisfile.php" method="post" onsubmit="return xl_EnableDisabledElements(this)">

0
 
LVL 2

Expert Comment

by:Tiller79188231
ID: 33527724
that's pretty sure that's what sscotti posted for your to do...
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34221194
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

803 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