Jump to content

Button Functionality


crazy8

Recommended Posts

Ok so I have been working on a form that has been MUCH modified from its original state which was done by a past employee. Anyway I have come along way and I am near done. I have my form and is almost all totaly new code in comparison to the original scripts. Do to this it seems I have lost functionality to 2 out of 3 of my buttons and I am realy not sure how to get them working again with the new code/form. Here is my code for the form as of now.
[code]<form name="cart_quantity" action="test.php" method="POST" style="display:inline; margin:0px;" autocomplete = "off">
<div class="bttns">
<input type="image" src="i/update_quote.gif" border="0" alt="Update Totals" >
<input type="image" src="i/get_quote.gif" border="0" onClick="http://ugly/winstedSQL/quote_sess.php" >
<input type="image" src="i/clear_quote.gif" border="0" alt="Clear Quote" class="multi" ></div>

<a name="quote"></a><div class="h2brdr"><h2>Current Quote</h2></div>

<?php
define("PHPINCDIR","../../phpinc/");
include ('ez_db.php');
require_once(PHPINCDIR.'ez_html_family.php');
require_once(PHPINCDIR.'ez_class_page.php');
require_once(PHPINCDIR."quotefunctions.php");
require_once(PHPINCDIR."html_common.php"); 

if (!empty($_POST['prod_quantity']) AND !empty($_POST['model'])){
    $_SESSION['prod_quantity'][$_POST['model']] = $_POST['prod_quantity'];

} elseif (!empty($_POST['cart_quantity'])){
    // update qty in cart session after submit
  for ($i=0; $i<count($_SESSION['prod_quantity']); $i++){
        if ($_POST['cart_quantity'][$i] >= 1){
            $_SESSION['prod_quantity'][$_POST['cart_id'][$i]] = $_POST['cart_quantity'][$i];
      } else {
            $_SESSION['prod_quantity'][$_POST['cart_id'][$i]] = '';
            unset($_SESSION['prod_quantity'][$_POST['cart_id'][$i]]);
        }
    }
}

if (is_array($_SESSION['prod_quantity'])){
    echo "<table width=\"600\" border=\"0\" cellspacing=\"0\" align=\"center\">";
    foreach ($_SESSION['prod_quantity'] AS $prod=>$qty){
    $sql = mysql_query("SELECT * FROM product WHERE model='$prod'");
    $row = mysql_fetch_array($sql);
    echo <<< TBL
        <tr><td class="plinky"><img src="i/t.gif" alt="" height="1" width="52"></td>
        <td align="center" class="plinky"><a href="ez_p.php?n={$row['id']}" target="_blank" onclick="javascript:op('ez_p.php?n={$row['id']}'); return false">{$row['model']}</a></td>
        <td align="center">{$row['little_desc']}</td>
        <td align="center" class="plinky"><input type="text" name="cart_quantity[]" value="$qty" style="width: 40px;" size="5" maxlength="5" class="quanw">
        <input type="hidden" name="cart_id[]" value="{$row['id']}"></td>
        </tr>
TBL;
}
echo "</table>";
}
?>
 
  <table width="600" height="20" border="0" align="center" cellspacing="0">
  <tr><td align="right" width="107" class="plinky"><strong>Quantity:</strong></td>
<td class="plinky" align="center" width="73"><input name="prod_quantity" size="2" maxlength="4" class="quanw" type="text" style="width: 40px">
</td>
  <td width="414" align="left" class="plinky"><strong>Enter Model Number:</strong>
  <input name="model" style="width: 50px;" size="20" maxlength="20" class="quanw" value="" type="text">
  </td>
</tr></table>
    </form>[/code]
Now also I should mention how I want this to work. I need only the "update quote" button to show when the page first loads. Then after the first model number and quantity are entered and submitted then I need the other two to be displayed with the "update quote" button.
The issue I am having with the "get quote" button is this. On the original site now when this button is hit you get redirected to a page to fill out shipping info and such. The link that gets displayed in the address bar is [quote]http://ugly/winstedSQL/quote_sess.php#quote[/quote] So Im not sure how to link this and get it working the way it should.
Lastly the "clear quote" Is something new to me. My script as you can see is using sessions since this is pretty much a "cart" used to build a quote. Where my issue lies is that I dont know how to "clear" let alone program a button to do it. I have looked around for possable code, and havent found a thing.

Any help on any of this would be a huge help and greatly appreciated. Thank you all so much and keep up the great work.
Link to comment
Share on other sites

I don't see any "buttons" in that code, so I will have to make up some names/values.

Here is how you could put the three buttons on the page such that only the first one is displayed upon initial entry to the page and the other two are displayed upon successive loads when "Update Quote" is used. (I assume only the one button would be displayed with "Clear Quotes")
[code]<?php
echo '<button type="submit" value="updatequote">Update Quote</button>';
if ($_POST['submit']=='updatequote') {
    echo '<button type="submit" value="getquote">Get Quote</button>';
    echo '<button type="submit" value="clearquote">Clear Quote</button>';
?>[/code]

Then to do the "Clear Quotes" functionality add something like this to the top of your page:
[code]<?php
if ($_POST['submit']=='clearquote') {
    unset($_POST);
}
?>[/code]

As for the Get Quote action, you could use javascript to chage the action of the form so it is submitted to the other page or add functionality to this page to handle that as well.
Link to comment
Share on other sites

The buttons are right up near the top of the code.
[code]<div class="bttns">
<input type="image" src="i/update_quote.gif" border="0" alt="Update Totals" >
<input type="image" src="i/get_quote.gif" border="0" onClick="http://ugly/winstedSQL/quote_sess.php" >
<input type="image" src="i/clear_quote.gif" border="0" alt="Clear Quote" class="multi" ></div>[/code]

You may have missed them considering the code says nothing about buttons other then the "div" ;D

With the clear quote code, should I add that to the top of the page as in where my "sessions_start()" is or just at the top of my php script?
Link to comment
Share on other sites

Well like I said the only button that works right now is the "Update Quote" button, which is mostly due to all the new code being written. The "get quote" is supposed to goto another page (quote_sess.php) but I guess what I want to do now just to simplify everything is to just start that buttons functionality along with my "Clear Quote" button all over. So if it is possable to just write new code to do this thats what I would like to do, I just dont know quite how to do it. So here is a description of what I need my form to do as far as my buttons go, considering other then the code you have already submitted I realy dont know how to code what I need.

1) Form loads when customer accesses the page

2) Customer enters in a modle number and a quantity into the fields

3) Customer hits "Enter" or the "Update Quote" button and that info gets submitted to the "table" and is displayed.

4) When that first submition is made 2 more buttons are displayed onto the page. ("clear quote" and "Get Quote")

5) If customer ever needs to clear the quote then they have the option to do so, otherwise when customer is done building an order to get a quote on they hit "Get Quote" and are redirected to that "Quote_sess.php page to fill out order/shipping information.

So I guess to make a long story short. Ignore the current code for the buttons that is posted and let me know what I need as far as new code to get these buttons to do what I need them to.

Thank you much for your help mjdamato
Link to comment
Share on other sites

Ok, I understand that you may not be very experienced in PHP, but if you need very specific help as opposed to a general answer you need to provide the entire picture. Without having all the code in front of me I have to make generalizations and hope that you can make the changes necessary for your particular environment.

Put the entire code for the page in a txt file and upload to a post. I may be able to provide a solution then. Otherwise I am just making guesses because I don't know how your form is being submitted or what triggers to look for.
Link to comment
Share on other sites

Try this:
[code]<div class="bttns">
<input type="image" src="i/update_quote.gif" border="0" onClick="document.forms[0].submit" alt="Update Totals" >
<?php
  if (!empty($_POST['prod_quantity']) AND !empty($_POST['model'])){
?>
<input type="image" src="i/get_quote.gif" border="0" onClick="http://ugly/winstedSQL/quote_sess.php" >
<input type="image" src="i/clear_quote.gif" border="0" alt="Clear Quote" class="multi" >
<?php
  }
?>
</div>[/code]
Link to comment
Share on other sites

Doesnt look like that did the trick I get the same thing and in addition with that code if I hit "Get Quote" or "Clear Quote" the page looks like its refreshing or trying to do something and then only my  "Update Quote" button that will show.
Link to comment
Share on other sites

Well I have been getting other help with a few other problems Im having with my code also. Im thinking that atleast one of the issues has to do with my sessions code because when I hit "Clear Quote" after submiting a model number and quantity, another quantity box will display onto my form under the one that was already submitted. It will also do that if I enter and submit a model. Once it displays and I goto type "0" into the quantity box nest to the item it will also duplicate ALL the boxes that already exist in the quote with no "model" or "descriptions" just the boxes. I dont know if you are able to help out with that or not but maybe that is one source of my problem on this end with the code you gave me?
Link to comment
Share on other sites

Sorry, no. There is a lot going on there, most of which I am not sure what your expectation is.

You do seem to have some process problems concerning when and how the session data is modified. I would suggest creating a flowchart of the processes you want to happen on that page and then code to that.
Link to comment
Share on other sites

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.