vozzek Posted November 29, 2007 Share Posted November 29, 2007 Hi everyone, Does a standard html text field have to be located within a form in order for me to pull values from it within php? For example: I have a text field for quantity. The user can change it. Later on in my page there's a button that launches the user to a php script on another page, and I need to know what the value of that text field was when the button was pressed. There's not a form on my page, so I'm assuming I can't use $_GET or $_POST. Is this possible? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 So how does the button work now if its not a form? Is it just a img and your have a url associated with it? If so, a Form would be the best way with a POST method. Quote Link to comment Share on other sites More sharing options...
vozzek Posted November 29, 2007 Author Share Posted November 29, 2007 Is it just a img and your have a url associated with it? Yes, that's exactly it. I really want to avoid using a form if possible. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 29, 2007 Share Posted November 29, 2007 Why do you want to avoid using a form? Ken Quote Link to comment Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 You can still use the same button graphic with a form if you like. Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted November 29, 2007 Share Posted November 29, 2007 hide the html form values? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2007 Share Posted November 29, 2007 The only way to get information from a browser to a server is to make a HTTP request to the server and include that information as part of the request. The ways of making a HTTP request are a form that is submitted (POST or GET), a URL that is requested (GET), or using AJAX techniques (POST or GET.) Quote Link to comment Share on other sites More sharing options...
vozzek Posted November 29, 2007 Author Share Posted November 29, 2007 Okay, at the risk of getting laughed out, I'll try to explain why I don't want to use a form. I have four buttons on my view_cart page: UPDATE CART, EMPTY CART, CONTINUE SHOPPING, and CHECKOUT. Empty cart is a button that launches to a new php url called delete_from_cart.php. I pass the cart id number over using $cid. Looks like this: <input type="image" src="Images/button_empty_cart.jpg" name="Empty" value="Empty" onmouseover="this.src='Images/button_empty_cart_rollover.jpg'" onmouseout="this.src='Images/button_empty_cart.jpg'" onclick="window.location.href='delete_from_cart.php?cid=0'" /> Continue shopping is a button that launches the user back to the last category they were shopping in. The variable $lastcat is equivalent to the last url they were at. The button looks like this: <input type="image" src="Images/button_continue_shopping.jpg" name="Continue" value="Continue" onmouseover="this.src='Images/button_continue_shopping_rollover.jpg'" onmouseout="this.src='Images/button_continue_shopping.jpg'" onclick="window.location.href='<?php echo $lastcat; ?>'" The Checkout button is the most simple, because it's does nothing more than call another url, no parameter passing or variables needed: <input type="image" src="Images/button_checkout.jpg" name="Checkout" value="Checkout" onMouseOver="this.src='Images/button_checkout_rollover.jpg'" onMouseOut="this.src='Images/button_checkout.jpg'" onclick="window.location.href='checkout.php'" /> But my real problem lies in the Update Cart button. There can be any number of items in the cart, so I need to pass an array to my update_cart.php script. Originally I was using a form to post this to the next page, but for some reason it made every button on my entire page turn into a POST form button that launched me into update_cart.php. It didn't matter where I placed the <form> </form> code, it assumed all buttons were supposed to post. Dunno why. I deleted that code and went with the onclick="window.location" stuff. I made a small $SESSION array to contain the quantity information based upon cart id. The only two variables I need to do the MySQL update are cart id and quantity. Am I using redirection to these php files in order to make writes to my database? Yes. Am I doing this on separate pages to avoid using Ajax? Yes. Did I make an honest attempt to learn Ajax and incorporate it into my shopping cart? Definitely yes. But unfortunately it got rather complicated, took too much time, and I needed to get moving. My shopping cart isn't all THAT elaborate, and I just wanted to get going on it. The update cart button launches to the update_cart.php file and passes the total item count. (I use this variable to loop through my global array): <input type="image" src="Images/button_update_cart.jpg" name="Update" value="Update" onMouseOver="this.src='Images/button_update_cart_rollover.jpg'" onMouseOut="this.src='Images/button_update_cart.jpg'" onClick="window.location.href='update_cart.php?itemct=<?php echo $itemct; ?>'" /> So in the end, I just need a way to grab the text field I'm using for QUANTITY so I can post it to my session variable for that cart id (each cart id has its own quantity field). I thought maybe I could use a javascript OnChange event to launch into a small script that would set the variable, but without the field being immersed inside a form, I don't know how. I'm kinda new at all this stuff, so try not to smack me around too hard. Quote Link to comment 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.