peleg Posted July 26, 2009 Share Posted July 26, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/167551-solved-cant-use-_post-but-_get-works/ Share on other sites More sharing options...
ldougherty Posted July 26, 2009 Share Posted July 26, 2009 So if you change $var1 = $_POST['inpAddDestination']; $var2 = $_POST['inpAddAddress']; to $var1 = $_GET['inpAddDestination']; $var2 = $_GET['inpAddAddress']; without changing the form method to GET it does work? Quote Link to comment https://forums.phpfreaks.com/topic/167551-solved-cant-use-_post-but-_get-works/#findComment-883503 Share on other sites More sharing options...
thewooleymammoth Posted July 26, 2009 Share Posted July 26, 2009 please post the relevant code in destinationadd.php, thanks Quote Link to comment https://forums.phpfreaks.com/topic/167551-solved-cant-use-_post-but-_get-works/#findComment-883511 Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 Do print_r[$_POST] to check if it contains your values or not. It MUST be your php code that is wrong since the form isn't. Quote Link to comment https://forums.phpfreaks.com/topic/167551-solved-cant-use-_post-but-_get-works/#findComment-883520 Share on other sites More sharing options...
peleg Posted July 28, 2009 Author Share Posted July 28, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/167551-solved-cant-use-_post-but-_get-works/#findComment-885282 Share on other sites More sharing options...
PFMaBiSmAd Posted July 28, 2009 Share Posted July 28, 2009 What does a phpinfo(); statement show for post_max_size? What is the entire code of the page with your form on it? Quote Link to comment https://forums.phpfreaks.com/topic/167551-solved-cant-use-_post-but-_get-works/#findComment-885288 Share on other sites More sharing options...
.josh Posted July 28, 2009 Share Posted July 28, 2009 $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[...] ? Quote Link to comment https://forums.phpfreaks.com/topic/167551-solved-cant-use-_post-but-_get-works/#findComment-885289 Share on other sites More sharing options...
peleg Posted July 29, 2009 Author Share Posted July 29, 2009 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; }; Quote Link to comment https://forums.phpfreaks.com/topic/167551-solved-cant-use-_post-but-_get-works/#findComment-885521 Share on other sites More sharing options...
peleg Posted July 29, 2009 Author Share Posted July 29, 2009 $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. Quote Link to comment https://forums.phpfreaks.com/topic/167551-solved-cant-use-_post-but-_get-works/#findComment-885522 Share on other sites More sharing options...
haku Posted July 29, 2009 Share Posted July 29, 2009 Are you posting this through Ajax? Quote Link to comment https://forums.phpfreaks.com/topic/167551-solved-cant-use-_post-but-_get-works/#findComment-885526 Share on other sites More sharing options...
peleg Posted July 30, 2009 Author Share Posted July 30, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/167551-solved-cant-use-_post-but-_get-works/#findComment-887088 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.