Jump to content

Recommended Posts

In this form:

 

<form method="POST" id="frmdlgAdd" name="frmdlgAdd" action="destinationadd.php">

<p>Destination</p>

<input type="text" name="inpAddDestination" id="inpAddDestination" value="Acme">

<p>Address</p>

<input type="text" name="inpAddAddress" id="inpAddAddress" value="Acme Address">

</form>

 

in destinationadd.php, the $_POST is empty. If I simply change to using GET in the form and the PHP, it works, so I don't think the problem is my PHP code (I only change two $_POST's to $_GET and it works). Why can't I use POST? The PHP version is 5.2.9. Is this some sort of configuration problem?

 

Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/167551-solved-cant-use-_post-but-_get-works/
Share on other sites

Here is the PHP code:

 

<?php

// *****************************************************************************

//

// Add a new Destination

//

// *****************************************************************************

 

include 'inc/tas_db_functions.php';

 

echo 'Method is: ' . $_SERVER['REQUEST_METHOD'] . "\n";

echo "GET ---->\n";

print_r($_GET);

echo "\n";

echo "POST ---->\n";

print_r($_POST);

 

$db = new DBAccess;

 

$db->insert_row(

'Destination_tbl',

array(

'Destination' => quote($_GET['inpAddDestination']),

'Address1' => quote($_GET['inpAddAddress'])

)

);

 

?>

 

and the response when the form uses GET (in Firebug) is:

Method is: GET

GET ---->

Array

(

    [inpAddDestination] => Acme

    [inpAddAddress] => Acme Address

)

 

POST ---->

Array

(

)

 

and when I simpy change GET to POST in the form:

Method is: GET

GET ---->

Array

(

)

 

POST ---->

Array

(

)

 

I just noticed, and I double-checked it, that when I POST, the PHP still reports the Request Method as GET. I got a feeling that has something to do with it. Firebug, however, does think that a POST is being done, so it looks like my PHP is missing something.

 

 

 

$db->insert_row(
   'Destination_tbl',
   array(
      'Destination' => quote($_GET['inpAddDestination']),
      'Address1' => quote($_GET['inpAddAddress'])
      )
);

 

so if you have your form as method='post' did you change those two $_GET's to $_POST[...] ?

What does a phpinfo(); statement show for post_max_size?

 

It's 8M. That ought to be enough for this instance.

What is the entire code of the page with your form on it?

 

Well, it's part of a YUI Dialog...

 

// Add button click handler

var hAdd = function() {

var oData = this.getData();

var intID;

say('Add oData', oData);

this.hide();

this.submit();

};

 

// configuration for dialog

var params = {

div:"dlgAdd",

header: {

text:"ADD DESTINATION",

color:"green",

font:'Georgia, "Times New Roman",Times,serif',

"bold":true,

size:"1.2em"

},

nextTo:"inpDestination",

bodyText:

'<form method="GET" enctype="multipart/form-data" id="frmdlgAdd" name="frmdlgAdd" action="destinationadd.php">' +

'<p>Destination</p>' +

'<input type="text" name="inpAddDestination" id="inpAddDestination" value="Acme">' +

'<p>Address</p>' +

'<input type="text" name="inpAddAddress" id="inpAddAddress" value="Acme Address">' +

'</form>',

addHandler:hAdd,

cancelHandler:function() {this.cancel();}

};

 

// create dialog

fn.AddDialog = function(oArgs) {

 

var elDivDlg, oHeader, strDiv;

 

// is default div name being overridden?

if (!fn.isDefined(oArgs.div)) {

oArgs.div = "dlgAdd";

};

 

// if div exists, we are done

if(!yud.get(oArgs.div)) {

 

elDivDlg = document.createElement("div");

elDivDlg.id = oArgs.div;

document.body.appendChild(elDivDlg);

 

fn.oAddDialog = new yw.Dialog(

oArgs.div,

{

visible:false,

context:[oArgs.nextTo, "tl", "bl"],

underlay:"none",

close:false,

modal:true,

hideaftersubmit:true,

buttons:

[

{text:"Add",  handler:oArgs.addHandler, isDefault:false},

{text:"Cancel", handler:oArgs.cancelHandler, isDefault:true}

]

}

);

 

fn.oAddDialog.setHeader(oArgs.header.text);

fn.oAddDialog.setBody(oArgs.bodyText);

fn.oAddDialog.render();

 

oHeader = oArgs.header;

strDiv = oArgs.div + "_h"

if(fn.isDefined(oHeader.color)) {yud.setStyle(strDiv, "color", oHeader.color);}

if(fn.isDefined(oHeader.font)) {yud.setStyle(strDiv, "fontFamily", oHeader.font);}

if(fn.isDefined(oHeader.bold) && oHeader.bold) {yud.setStyle(strDiv, "fontWeight", "bold");}

if(fn.isDefined(oHeader.size)) {yud.setStyle(strDiv, "fontSize", oHeader.size);}

}

 

return fn.oAddDialog;

 

};

$db->insert_row(
   'Destination_tbl',
   array(
      'Destination' => quote($_GET['inpAddDestination']),
      'Address1' => quote($_GET['inpAddAddress'])
      )
);

 

so if you have your form as method='post' did you change those two $_GET's to $_POST[...] ?

 

Yes. Remember that the dump of $_POST is empty.

Are you posting this through Ajax?

 

YES!!! THAT'S IT!!!

 

In the code:

 

var hAdd = function() {
var oData = this.getData();
var intID;

this.hide();
this.submit();
}

 

the this.submit() looks like it should do a normal submit, but the default is to do an XMLHttpRequest. I changed the default in the setup for the YUI Dialog, and indeed, it is now POSTing the data. I've had this problem in other places but never noticed that default before or thought to look at exactly how the data was being submitted.

 

I have been fighting with this problem for a while now and I never could figure out what was wrong. Turns out it's not a PHP problem at all, but it sure looked like one when I started.

 

Thank you all very much, but especially haku because your question pointed me in the right direction.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.