adamstoffel Posted January 18, 2009 Share Posted January 18, 2009 I have a form set up like this: <form action="?action=update" method="post"> <input type="text" name="way" /> <input type="text" name="zip" /> <input type="submit" /> </form> When I submit the form it just take you back to the original page (which is intended) but without ?action=update. None of the post vars show up in PHP. Even when i use get, it takes me to ?way=abc&zip=xyz. I don't get it! Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/ Share on other sites More sharing options...
Philip Posted January 18, 2009 Share Posted January 18, 2009 Why not just use a hidden field? Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739909 Share on other sites More sharing options...
adamstoffel Posted January 18, 2009 Author Share Posted January 18, 2009 because sometimes i want to just link to the page and modify ?action to whatever with having to post anything. but i still will want to post vars sometimes also. Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739912 Share on other sites More sharing options...
elgoog Posted January 18, 2009 Share Posted January 18, 2009 try including the page name in your form action Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739914 Share on other sites More sharing options...
adamstoffel Posted January 18, 2009 Author Share Posted January 18, 2009 for action="index.php?action=update" on submit it still just takes you to index.php (without ?action=update) Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739918 Share on other sites More sharing options...
elgoog Posted January 18, 2009 Share Posted January 18, 2009 FYI: Pasted the below onto my local computer and worked ok <form action="index2.php?action=update" method="post"> <input type="text" name="way" /> <input type="text" name="zip" /> <input type="submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739926 Share on other sites More sharing options...
kenrbnsn Posted January 18, 2009 Share Posted January 18, 2009 Do something like this at the start of your script: <?php $action = ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['action']))?$_GET['action']:''; $action = ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']))?$_POST['action']:''; ?> Ken Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739929 Share on other sites More sharing options...
adamstoffel Posted January 18, 2009 Author Share Posted January 18, 2009 ok. hmm. i dont know whats going wrong with mine. in action: http://www.fhsgsa.org/dw2/cart.php you'll want to add something to the cart first: http://www.fhsgsa.org/dw2/index.php?c=12&p=77975 Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739930 Share on other sites More sharing options...
Philip Posted January 18, 2009 Share Posted January 18, 2009 <?php $action = ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['action']))?$_GET['action']:''; $action = ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']))?$_POST['action']:''; ?> Wouldn't that overwrite itself? If you had a GET var, but not a POST, action would be set to "" @ OP, I go to http://www.fhsgsa.org/dw2/cart.php?action=update However get the errors: Quote Notice: Undefined variable: shipzip in /home/content/f/h/s/fhsgsa/html/dw2/cart.php on line 8 Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/h/s/fhsgsa/html/dw2/cart.php: in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 219 Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739933 Share on other sites More sharing options...
adamstoffel Posted January 18, 2009 Author Share Posted January 18, 2009 yeah, i have this right up at the top. $action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : 'view'; $shipway = (isset($_POST['shipway']) && $_POST['shipway'] != '' && $_POST['shipway'] != NULL) ? $_POST['shipway'] : '03'; $shipzip = (isset($_POST['shipzip']) && $_POST['shipzip'] != '') ? $_POST['shipzip'] : NULL; but even if i echo $_GET['action'] or $_POST['shipzip'], its undefined. Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739936 Share on other sites More sharing options...
adamstoffel Posted January 18, 2009 Author Share Posted January 18, 2009 @KPhilip i fixed that. you caught me in the middle of a quick update. now at the top i have $action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : 'view'; $shipway = (isset($_POST['shipway']) && $_POST['shipway'] != '' && $_POST['shipway'] != NULL) ? $_POST['shipway'] : '03'; $shipzip = (isset($_POST['shipzip']) && $_POST['shipzip'] != '') ? $_POST['shipzip'] : NULL; echo $_POST['shipzip']; Quote <?php $action = ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['action']))?$_GET['action']:''; $action = ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']))?$_POST['action']:''; ?> Wouldn't that overwrite itself? If you had a GET var, but not a POST, action would be set to "" @ OP, I go to http://www.fhsgsa.org/dw2/cart.php?action=update However get the errors: Quote Notice: Undefined variable: shipzip in /home/content/f/h/s/fhsgsa/html/dw2/cart.php on line 8 Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/h/s/fhsgsa/html/dw2/cart.php: in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 219 Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739938 Share on other sites More sharing options...
Philip Posted January 18, 2009 Share Posted January 18, 2009 Hopefully you're still fixing it, Quote Notice: Undefined index: shipzip in /home/content/f/h/s/fhsgsa/html/dw2/cart.php on line 9 Notice: Undefined index: hidCartId in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 164 Notice: Undefined index: hidProductId in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 165 Notice: Undefined index: txtQty in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 166 Notice: Undefined index: shipzip in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 167 Notice: Undefined index: shipway in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 168 Notice: Undefined variable: returnUrl in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 217 Notice: Undefined index: shop_return_url in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 217 Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/h/s/fhsgsa/html/dw2/cart.php:9) in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 217 Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739943 Share on other sites More sharing options...
adamstoffel Posted January 18, 2009 Author Share Posted January 18, 2009 Really? Are there any items in your cart? I only get the first: Quote Notice: Undefined index: shipzip in /home/content/f/h/s/fhsgsa/html/dw2/cart.php on line 9 Ugh. Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739945 Share on other sites More sharing options...
Philip Posted January 18, 2009 Share Posted January 18, 2009 Okay - after putting another item in my cart (apparently it emptied itself) Quote Zip Code Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/h/s/fhsgsa/html/dw2/cart.php:9) in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 219 and: Quote Notice: Undefined index: shipzip in /home/content/f/h/s/fhsgsa/html/dw2/cart.php on line 9 I'm pretty sure the action=?GETVARS is browser dependent - some will run it, others wont (can anybody confirm this?) Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739952 Share on other sites More sharing options...
adamstoffel Posted January 18, 2009 Author Share Posted January 18, 2009 Ok, so if I don't do the echo on line 9 of cart.php, I think that should fix things. Which I have done. So what I should probably do is: Quote <form action="cart.php" method="post"> <input type="hidden" name="action" value="update" /> and... Quote if(isset($_GET['action']) && $_GET['action'] != '') {$action = $_GET['action'];} elseif(isset($_POST['action']) && $_POST['action'] != '') {$action = $_POST['action'];} else{$action = 'view';} Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739957 Share on other sites More sharing options...
Philip Posted January 18, 2009 Share Posted January 18, 2009 Quote <?php if(isset($_GET['action']) && $_GET['action'] != '') {$action = $_GET['action'];} elseif(isset($_POST['action']) && $_POST['action'] != '') {$action = $_POST['action'];} else{$action = 'view';} ?> Yeah, that's what I would do - of course don't forget to filter it (possibly use an array/switch to check to see if the action is acceptable) Link to comment https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/#findComment-739962 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.