Guys, im scratching my head around this one.
I have this website that basically contains a few forms that are filled in by the user. The user then can download that information in human readable format (pdf) or machine readable format (xml) but I'm having a slight problem submitting textboxes.
I have a few of them, for instance in the description section, but when i access the $_POST['Desc_Desc_desc'] value, it's empty even though i can see content on the textarea. The weird thing is that when i use firebug to inspect the element, it shows the element as if it had no contents..
Can anyone figure what is causing this strange behavior?
I had a similar issue but later I found out that somewhere at the bottom, I had reused the same name for another element which was empty. That wiped off my required element at var_dump, print_r as well. It took a while to get that out.
In
service_level_library.buttons.prepForSubmit
, the textarea is cloned along with the rest of the form via the DOMcloneNode
method. This copies HTML element attributes, but not DOM properties. (Sometimes DOM element node properties have a corresponding attribute, so updating the property affects the attribute, which can make it appear that DOM properties are being copied.)While textarea DOM objects have a
value
property, the textarea HTML element doesn't have a correspondingvalue
attribute, so thevalue
property isn't exposing an attribute. Thus when you clone the node, the (empty)value
attribute is what gets copied, leaving the current value of the element (as accessible via thevalue
property) behind.To fix your script, do one of:
defaultValue
property or setting the text content of the node, before cloning. This works because the current value of the cloned node will be set to its initial value, and a deep copy of a textarea will copy its text contents (the source of its initial value).I used firebug to analyze what gets sent to your script by
The form data is being sent correctly
Bottom line: the form does not get submitted to the intended recipient.
You say in your question
$_POST['Desc_Desc_desc']
, although in the code I see a textarea with nameDep_desc
and idDep_Desc_Desc
. Then you should write$_POST['Dep_desc']
, i.e. thename
of the<textarea>
instead of theid
.Also,
textarea
s don't have avalue
attribute, so in your html you should write the initial content between the opening and the closing tag.HTML
PHP
notes
nl2br
: Respect new lines in the html output replacing the\n
symbol with<br />
.htmlspecialchars
: Prevent possibleXSS
attacks.