Solved

PHP $_POST and Disabled Fields

Posted on 2010-08-16
13
1,855 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 143

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

Industry Leaders: 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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 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