Jump to content

Archived

This topic is now archived and is closed to further replies.

maziagha

Having a huge FORM problem

Recommended Posts

Hi all!

I have made/modified a PHP web-shop. Everything work fine except now i want to have a possibility to also choose Size on products i buy. The problem is that my script will not post the variables from the Form. Here how the code looks like for this part.

<form method="post">
<?php
if ($pd_size == 1) { ?>

<select name="sizer">
  <option value="Small">Small</option>
  <option value="Medium">Medium</option>
  <option value="Large">Large</option>
</select>

<? }
else if ($pd_size == 2) { ?>

<select name="sizer" >
  <option value="One-Size">onesize</option>
  <option value="XL">XL</option>
</select>
<?php } else if ($pd_size == 3) {?>

<select name="sizer">
  <option value="S-M">S-M</option>
  <option value="M-L">M-L</option>
<?php } ?>
</select>

<?php
// if we still have this product in stock
// show the 'Add to cart' button
//if ($pd_qty > 0) {
?>
<input type="submit" name="btnAddToCart" value="Add To Cart &gt;" onClick="window.location.href='<?php echo $cart_url; ?>';" class="addToCartButton">
</form>

I have tried to put "Action" same as  $cart_url but still it wont post the Sizes.

Hope someone can help me.

Share this post


Link to post
Share on other sites
This part:
[quote author=maziagha link=topic=101742.msg402891#msg402891 date=1153778936][code]
<form method="post">[/code]
[/quote]
Why not make it have the action in there as usual? action="filename.php"
[code]
<form method="post" action="filename.php">
[/code]
[quote author=maziagha link=topic=101742.msg402891#msg402891 date=1153778936]
[code]<input type="submit" name="btnAddToCart" value="Add To Cart &gt;" onClick="window.location.href='<?php echo $cart_url; ?>';" class="addToCartButton">
</form>
[/code]
[/quote]
I'd go with the action="value.php" instead, and you can add variables to this too:
[code]
<form name="formyform" method="post" action="index.php?id=<?php echo $cart_id?>">
[/code]

Share this post


Link to post
Share on other sites
Ys i have tryid this, but it still wont do it.
Instead of adding the product to cart, it just refreshes the page.

Share this post


Link to post
Share on other sites
remove the onclick from the submit button. you dont want to "redirect" when it's clicked.

Share this post


Link to post
Share on other sites
Simple stuff.  The problem isn't with the form, it's with the form processing script and we haven't seen any of thaqt.

Share this post


Link to post
Share on other sites
you can find the source code @ http://www.phpwebcommerce.com/php-mysql-shopping-cart-tutorial.php

Share this post


Link to post
Share on other sites
Can anyone take a look at the codes and tell me what is wrong?
The size part i have added my self so its not in the original code.

Share this post


Link to post
Share on other sites
form method="post">
<select name="sizer">
  <option value="Small">Small</option>
  <option value="Medium">Medium</option>
  <option value="Large">Large</option>
</select>

This is what i added to the productdetail.php next to the descriptions part. But i can't get it posted so i can $_request it later on.

Share this post


Link to post
Share on other sites
what about the processing part? have you done anything to save this into the database?

Share this post


Link to post
Share on other sites
Well, since i don't get any posting of the form i cant even write it to database. I tryied but failed that also.
Can you run the cart sript and check where it is bugging? Please please pretty please

Share this post


Link to post
Share on other sites
i think it's the third if statement causing the problem. see my comment
[code]<form method="post" action="<?php echo $cart_url ?>">
<?php
if ($pd_size == 1) { ?>

<select name="sizer">
  <option value="Small">Small</option>
  <option value="Medium">Medium</option>
  <option value="Large">Large</option>
</select>

<?php }
else if ($pd_size == 2) { ?>

<select name="sizer" >
  <option value="One-Size">onesize</option>
  <option value="XL">XL</option>
</select>
<?php } else if ($pd_size == 3) {?>

<select name="sizer">
  <option value="S-M">S-M</option>
  <option value="M-L">M-L</option>
<?php } /*<---- This is supposed to go after </select>*/ ?>
</select>

<input type="submit" name="btnAddToCart" value="Add To Cart &gt;" class="addToCartButton">
</form>
[/code]

Share this post


Link to post
Share on other sites
nah never mind guys i solved the problem after sleeping on it and dreaming about it.  ;D
The problem was that the add to cart URL was taken from an include file and that caused the problem.
solved it buy making the page to a big script page.

Thank you all for trying to help.

Share this post


Link to post
Share on other sites

×

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.