Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

HTML Form within Description

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 06-10-2005, 01:20 PM
 
dgstadtman dgstadtman is offline
 

Member
  
Join Date: Oct 2004
Location: Hilton Head Island, SC
Posts: 16
 

Default HTML Form within Description

Hi...

I have a product on a site (not finished) that needs a php form put in. I have put the form into the detailed description of the item...easy enough, right?

Here is the link to view the form.


I tell the form to post to the php handler, but when you hit submit...it just takes you to your cart. Weird. I know that I have the error and success pages put in the correct place.

Oh and the email does not send, either.

Can someone review my code and tell me what I am doing wrong? Is there a possibility that I cannot even do this in Xcart?

Here is the HTML form, within the detailed description:

Code:
<form method="POST" action="http://www.shellypopcandles.com/store/favorrequest.php"> Fields marked &quot;<font color="#FF0000">*</font>&quot; are required <table width="330" border="0"> <tr> <td width="216">Your Email:* </td> <td width="148"><input type="text" name="EmailFrom" size="40"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td>First Name:* </td> <td><input type="text" name="FirstName" size="40"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td>Last Name:* </td> <td><input type="text" name="LastName" size="40"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td>Quantity Desired:* </td> <td><input type="text" name="QuantityDesired" size="6"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td align="left" valign="top">Colors:*</td> <td><input name="honeyBrown" type="checkbox" id="honeyBrown" value="HoneyBrown"> Honey Brown <input name="txSnow" type="checkbox" id="txSnow" value="TexasSnow"> Texas Snow <input name="creamy" type="checkbox" id="creamy" value="Creamyliscious"> Creamyliscious <input name="brickyard" type="checkbox" id="brickyard" value="Brickyard"> Brickyard <input name="lusciousLilac" type="checkbox" id="lusciousLilac" value="LusciousLilac"> Luscious Lilac <input name="sage" type="checkbox" id="sage" value="Sage"> Sage <input name="pinkyToe" type="checkbox" id="pinkyToe" value="PinkyToe"> Pinky Toe <input name="rhythmBlues" type="checkbox" id="rhythmBlues" value="RhythmBlues"> Rhythm Blues</td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td><valign="right"><input type="submit" name="submit" value="Submit"></valign></td> </tr> </table></form>

And here is the PHP handler...put in the proper place.

Code:
<?php // get posted data into local variables $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "info@shellypopcandles.com"; $Subject = "Favor Quote Request"; $FirstName = Trim(stripslashes($_POST['FirstName'])); $LastName = Trim(stripslashes($_POST['LastName'])); $email = Trim(stripslashes($_POST['EmailFrom'])); $QuantityDesired = Trim(stripslashes($_POST['QuantityDesired'])); $Colors = Trim(stripslashes($_POST['honeyBrown', 'txSnow', 'creamy', 'brickyard', 'lusciousLilac', 'sage', 'pinkyToe', 'rhythmBlues'])); // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "FirstName: "; $Body .= $FirstName; $Body .= "\n"; $Body .= "LastName: "; $Body .= $LastName; $Body .= "\n"; $Body .= "email: "; $Body .= $EmailFrom; $Body .= "\n"; $Body .= "QuantityDesired: "; $Body .= $QuantityDesired; $Body .= "\n"; $Body .= "Colors: "; $Body .= $Colors; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.shellypopcandles.com/store/sent.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.shellypopcandles.com/store/error.html\">"; } ?>

I would really really appreciate the help. I am kind of new to this and I have been working on it all day!
__________________
bracediscountstore.com

xgart gold 4.0.12
fancy categories 4.0.12
Reply With Quote
  #2  
Old 06-10-2005, 05:41 PM
 
dgstadtman dgstadtman is offline
 

Member
  
Join Date: Oct 2004
Location: Hilton Head Island, SC
Posts: 16
 

Default

Alright...I figured out what it is. The 'add to cart' button on the product detail page uses the "submit" action. The fix that worked for me was kind of a workaround on the 'add to cart button'. I did this by disabling certain functions based on the weight of the product. Obviously, a quote doesn't weigh anything, so disabling a function would happen by wrapping conditional 'if' tags around functions:

Code:
{if $product.weight gt "0.05"}Insert Any Function {/if}

Since the quote has a weight of less than 0.05, it will not show "Insert Any Function"

You Can See it in action Here

In brief here are the steps.

-Create The Form
-Put the form into your detailed description
-Create your php handler
-Create a 'form sent' page (optional)
-Create a 'form error' page (optional)
-In customer/main/product.tpl, Disable functions you don't want by wrapping 'if' statements around those functions, as shown above

You also want to modify customer/main/products.tpl to remove the 'enter your price' label and make it redirect you to the product info page. Don't forget to edit $lbl_enter_your_price to say "get a quote" or something similar. Or you can just create a new label.

I know that a lot of people have wanted a mod like this, so I am working on a how-to right now.
__________________
bracediscountstore.com

xgart gold 4.0.12
fancy categories 4.0.12
Reply With Quote
  #3  
Old 06-10-2005, 06:50 PM
 
dgstadtman dgstadtman is offline
 

Member
  
Join Date: Oct 2004
Location: Hilton Head Island, SC
Posts: 16
 

Default

Step 1: Create The Form

Here is a sample, with email, firstname, lastname, quantity desired, and 3 checkbox fields: (don't forget to change your form location!)

Code:
<form method="POST" action="http://www.yoursite.com/xcart/quoteform.php"> Fields marked &quot;<font color="#FF0000">*</font>&quot; are required <table width="330" border="0"> <tr> <td width="216">Your Email:* </td> <td width="148"><input type="text" name="EmailFrom" size="40"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td>First Name:* </td> <td><input type="text" name="FirstName" size="40"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td>Last Name:* </td> <td><input type="text" name="LastName" size="40"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td>Quantity Desired:* </td> <td><input type="text" name="QuantityDesired" size="6"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td align="left" valign="top">Colors:*</td> <td><input name="check1" type="checkbox" id="check1" value="Yes"> check1 <input name="check2" type="checkbox" id="check2" value="Yes"> check2 <input name="check3" type="checkbox" id="check3" value="Yes"> check3 </tr> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td><valign="right"><input type="submit" name="submit" value="Submit"></valign></td> </tr> </table></form>

Now Put that Form in your detailed description.

Next, we will create the php form handler...be sure to change all of te email addresses and website locations: (credits for this are in the code)

Code:
<?php // Website Contact Form Generator // http://www.tele-pro.co.uk/scripts/contact_form/ // This script is free to use as long as you // retain the credit link // get posted data into local variables $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "you@email.com"; $Subject = "Quote Request"; $FirstName = Trim(stripslashes($_POST['FirstName'])); $LastName = Trim(stripslashes($_POST['LastName'])); $email = Trim(stripslashes($_POST['EmailFrom'])); $QuantityDesired = Trim(stripslashes($_POST['QuantityDesired'])); $check1= Trim(stripslashes($_POST['check1'])); $check2= Trim(stripslashes($_POST['check2'])); $check3= Trim(stripslashes($_POST['check3'])); // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= " Online Quote Request"; $Body .= "\n"; $Body .= "\n"; $Body .= "\n"; $Body .= "First Name: "; $Body .= $FirstName; $Body .= "\n"; $Body .= "\n"; $Body .= "Last Name: "; $Body .= $LastName; $Body .= "\n"; $Body .= "\n"; $Body .= "Email: "; $Body .= $EmailFrom; $Body .= "\n"; $Body .= "\n"; $Body .= "Quantity Desired: "; $Body .= $QuantityDesired; $Body .= "\n"; $Body .= "\n"; $Body .= "CHECKBOXES: "; $Body .= "\n"; $Body .= "Check1: "; $Body .= $check1; $Body .= "\n"; $Body .= "Check2: "; $Body .= $check2; $Body .= "\n"; $Body .= "Check3: "; $Body .= $check3; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.yoursite.com/xcart/sent.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.yoursite.com/xcart/error.html\">"; } ?>

Now create your sent.html and error.html pages and upload them into the correct location.

Now we will disable the functions we don't want on the product page in customer/main/product.tpl. For example, since I don't want the entire quantity section, i would replace this-

Code:
<TABLE width="100%" cellpadding="0" cellspacing="0" border="0"> <TR><TD colspan="2"><FONT class="ProductDetailsTitle">{$lng.lbl_details}</FONT></TD></TR> <TR><TD class="Line" height="1" colspan="2">[img]{$ImagesDir}/spacer.gif[/img]</TD></TR> <TR><TD colspan="2"></TD></TR> {if $config.Appearance.show_in_stock eq "Y" and $config.General.unlimited_products ne "Y" and $product.distribution eq ""} <TR><TD width="30%">{$lng.lbl_quantity}</TD><TD nowrap><SPAN id="product_avail_txt">{if $product.avail gt 0}{$product.avail}</SPAN>{else}{$lng.txt_no}{/if} {$lng.txt_items_available}</TD></TR> {/if} {if $product.weight ne "0.00"}<TR><TD width="30%">{$lng.lbl_weight}</TD><TD nowrap><SPAN id="product_weight">{$product.weight}</SPAN> {$config.General.weight_symbol}</TD></TR>{/if}

with this: (in line 2 I added {if $product.weight gt "0.05"} and I closed the code block with {/if})
Code:
<TABLE width="100%" cellpadding="0" cellspacing="0" border="0"> <TR><TD colspan="2">{if $product.weight gt "0.05"}<FONT class="ProductDetailsTitle">{$lng.lbl_details}</FONT></TD></TR> <TR><TD class="Line" height="1" colspan="2">[img]{$ImagesDir}/spacer.gif[/img]</TD></TR> <TR><TD colspan="2"></TD></TR> {if $config.Appearance.show_in_stock eq "Y" and $config.General.unlimited_products ne "Y" and $product.distribution eq ""} <TR><TD width="30%">{$lng.lbl_quantity}</TD><TD nowrap><SPAN id="product_avail_txt">{if $product.avail gt 0}{$product.avail}</SPAN>{else}{$lng.txt_no}{/if} {$lng.txt_items_available}</TD></TR> {/if} {if $product.weight ne "0.00"}<TR><TD width="30%">{$lng.lbl_weight}</TD><TD nowrap><SPAN id="product_weight">{$product.weight}</SPAN> {$config.General.weight_symbol}</TD></TR>{/if}{/if}

REMEMBER!!! Your product weight must be less than 0.05 for this to work. This way...your 'quote' product has a zero weight, taking out the things you don't want, while leaving the products with a weight of 0.05 or more to have all of the things that you take out with the 'if' statements.

Using the previous step, take out all of the other parts that you don't want to show for the 'quote' product.

Be sure to put an 'if' statement around the 'add to cart' button, or else you won't be able to use the submit button in your form.

NEXT- we are going to modify the category product listing page in customer/main/products.tpl so that we get a 'receive a quote now' message instead of 'Enter Your Price' since the price is $0. We will also make this link to the product details instead of adding it to your cart.

Open customer/main/products.tpl and change this:

Code:
{else} <FONT class="ProductPrice">{$lng.lbl_enter_your_price}</FONT> {/if}

to this:

Code:
{else} <FONT class="ProductPrice"><A href="product.php?productid={$products[product].productid}"> Get A Quote Now!</A></FONT> {/if}

I believe that that is it! I know that this will not work for everyone's application, but it works like a charm for me.

Yay...my first custom mod tutorial completed!

-Steveo
__________________
bracediscountstore.com

xgart gold 4.0.12
fancy categories 4.0.12
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 12:52 AM.

   

 
X-Cart forums © 2001-2020