Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1919
  • Last Modified:

PHP $_POST and Disabled Fields

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
thewyzzard
Asked:
thewyzzard
  • 3
  • 2
  • 2
  • +4
3 Solutions
 
Dave BaldwinFixer of ProblemsCommented:
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
 
mpvveeCommented:
just fill the value property for that input and you will get the info
0
 
thewyzzardAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Dave BaldwinFixer of ProblemsCommented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
ramelongCommented:
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
 
sscottiCommented:
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
 
sscottiCommented:
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
 
Tiller79188231Commented:
use a javascript function to submit the values, javascript can read the value of a disabled field
0
 
thewyzzardAuthor Commented:
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
 
Tiller79188231Commented:
that's pretty sure that's what sscotti posted for your to do...
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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