Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP $_POST and Disabled Fields

Posted on 2010-08-16
13
Medium Priority
?
1,894 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 84

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 84

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 84

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 172 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 328 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 328 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

704 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