Missing $_POST element.

springthorpeSoftware
springthorpeSoftware used Ask the Experts™
on
When form is re-submitted via JavaScript on another page, one (and maybe more, I haven't looked) of the $_POST values is missing.  Many others do exist.

A text box with the same name/id as the requested $_POST element exists on the submitted form (I've verified the name/id.) and that text box contains text, but PHP is throwing an "Undefined index:" error when I do a "$v = $_POST['xx']".  I did a dump of the $_POST elements and it is not there.

If, however, I re-submit from the form itself (not from another open page), that $_POST value DOES exist.

As a note, there are over 100 fields on the re-submitted page.  Don' t know if this would affect it, or not.

Has anyone heard of this behavior and, if so, how to correct?

Thanks,
Bruce

JavaScript that submits page. It is on the active window, function is called by a button click:

function CloseIt()
{
	if (!(window.opener.document.adiApproveOrder == undefined) 
	 && !(window.opener.document.adiApproveOrder.closed)) {
		var actn = document.getElementById("action").value;
		if (actn == "approved") {
			window.opener.document.adiApproveOrder['action'].value = "deliver";
		} else if (actn == "submitted") {
			window.opener.document.adiApproveOrder['action'].value = "submitted";
		} else {
			window.opener.document.adiApproveOrder['action'].value = "";
		}
		window.opener.document.adiApproveOrder.submit();
	}
	window.close();
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
Is the "action" id non-unique within the page? If so, renaming it to "myaction" or something else unique would fix the issue.
Thanks for replying!  No, "$action" is a unique value. It's stored in a hidden text box.  Both pages use it, however.
The control for it on the "main" page is being properly loaded by the JS on the "calling" page.  That value is part of the $_POST array on the main page when it is re-submitted.
Bruce

Commented:
What does the source code for the form look like?
Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
Is the page the form is on publicly viewable?
Terry Woods - Yes. Button on "main" page re-submits it with a specific $action value, which triggers opening of "sub" page (a new page on top of the main). Sub page generates one or more pdf files and opens them in new windows for viewing. On sub page, user then clicks a button, which loads field "action" on the main form, re-submits main, then closes itself.

gr8Gonzo - Following is my "testing" code, at top of main page, just after include files are loaded and session is started:

// logs error if post value does not exist
echo "value: " . $_POST['ord_seller_units'] . '<br>';

// if posts are supposed to be there, dump them.
if (isset($_POST['action'])) {
      foreach ($_POST as $f => $v) {
            echo $f . ': ' . $v . '<br>';
      }
}

// this is the control code on the main page
<input type="text" name="ord_seller_units" id="ord_seller_units" size="4"
                        style="text-align:center"
                        value="<?php echo $ord_seller_units;?>" onchange="ChangedSellerUnits()" />

Thanks, guys!
Commented:
I meant - can you provide the final, rendered HTML source for the form? In other words, go to the form in your browsers, go to View Source, then copy and paste it all in here.

The reason I'm asking is because if there is an HTML error, the browser might be trying to correct the error but messing it up.

1. We have to see whether the field is being sent at all (or being sent with an incorrect blank value). One easy way to test this is with Fiddler.

2. If Fiddler shows that the field is not part of the data at all, then either there's corrupt HTML, or that field is outside the form tag, or there is JavaScript that is interfering with the form submission. If you have any JavaScript that messes with the DOM (adding, modifying, or removing HTML elements) then maybe it is messing up the page structure.

3. If Fiddler does show that the field is being sent over, then the problem is with PHP. You may have code that is improperly sanitizing or removing the field or overwriting it or something.
Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
You could provide the URL for the page, rather than providing the HTML source, if you prefer.
Terry, unfortunately, I'm not allowed to show all of the code, just snippets.  Can't give you a link due to security policies.
Went back through the code twice, including your suggestion of looking at the html. There were no PHP, JS, or html errors. Added echos and alerts of values before and after. Could not find reason for 4 of the fields not having $_POST values on reload.  All 4 had fields visible on the main form with correct values when the dialog was opened.
Solved by having "main" page re-read data from database when dialog is closed.  (The records are saved on the main page before the dialog is opened.) Have something that works, so this will have to remain a mystery.
Awarding you the points because you spent so much time on it.
Thanks, again.
Bruce
Thanks, guys!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial