The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Terms and conditions

RickWRickW Member
in Help edited October 2009
I have one product that requires "terms and conditions". I would like to include the terms and a checkbox on the product page where if left unchecked, clicking the buy button would display an error message rather than the cart.

The problem is, the form action doesn't allow for reviewing the checkbox. I thought I might be able to do a "$server" post, check for "T&C" and then a header("Location:https://mycompany.foxycart.com/cart";);

I don't even know if this would work or if there is a better way. Any suggestions?
Comments
  • tookingstookings Member
    edited October 2009
    You should be able to use fc_PreProcess() to check the form submission data, and if it doesn't validate (based on your own criteria...such as checkbox not checked) return the client to your product page without displaying the thickbox (and fire any other JS action...a simple alert box message for example).

    Do you have an example of this product page on your site? If you like, I can probably provide a little more specific code/detail on how I would attack this, later tonight. :)
  • RickWRickW Member
    edited October 2009
    I just read the fc_PreProcess() and it sounds perfect. How do I incorporate it?

    I think it would be easier to show you the code here. Otherwise you'd have to signup and create a username.

    Here is how my current code is written:


    echo"<form id='FormName' action='https://mycompany.foxycart.com/cart' class='foxycart' method='post'>";
    echo"<div align='center'>";
    echo"<div class='register' style='overflow: auto; width: 675px; padding-left:25px; border: 3px solid #cccccc; height:60px; background-color: white ;'>";

    echo"MY TERMS AND CONDITIONS.</div>";

    echo"<input type='checkbox' name='Terms' value='Terms' /><span class='bodycopy'>I have read and agree to the terms and conditions set forth by MY COMPANY.com</span><br><br>";

    echo"<input type='hidden' name='name' value='Credits'/>";
    echo"<input type='hidden' name='price' value='2.00'/>";
    echo"<input type='hidden' name='category' value='Credits'/>";
    echo"<select name='quantity'>";
    echo"<option value='{q:10}'>10</option>";
    echo"<option value='{q:30}'>30</option>";
    echo"<option value='{q:60}'>60</option>";
    echo"<option value='{q:100}'>100</option>";
    echo"<option value='{q:300}'>300</option>";
    echo"</select>


    <input type='submit' value='Buy Credits' /></div>";
    echo"</form>";
  • tookingstookings Member
    edited October 2009
    Something like the following code, inserted right before your "</head>" tag should probably work:
    <script type="text/javascript" charset="utf-8">
    function fc_PreProcess(MyPPFoxyData, MyPPFoxyID) {
    if(MyPPFoxyData.indexOf('Terms=Terms') != -1) {
    return true;
    }
    else {
    alert('You must accept the Terms and Conditions for this product.');
    return false;
    }
    }
    </script>

    I haven't been able to test that on a live server, so if that doesn't seem to do the trick, I'll update again in a few hours. :) Essentially, it's just checking to see if the checkbox value pair ("Terms=Terms" per your form sample) is set in the internal variable string that foxycart is about to send to the cart. If not, it sends an alert, and then "return false;" which tells the pre-thickbox code to abort and not show the thickbox or execute the cart.

    You can stick in an "alert(MyPPFoxyData);" if you want to see what the MyPPFoxyData string actually looks like...it's essentially the the form data in GET string format. MyPPFoxyID will just equal the id of the form that is being submitted....mainly in case you have multiple forms...or the same code on multiple pages, etc.

    Make sense?
  • tookingstookings Member
    edited October 2009
    RickW, here is a working example, with that code: http://www.tookdev.com/public/foxy/termform.html

    The only things I changed: Adding "h:" to the checkbox name ("name='h:Terms'" in the checkbox HTML) so "Terms" wouldn't show as an attribute in the customer's cart. I've also added another conditional that checks for "cart=empty" so the validation is skipped if you are clearing the cart instead of adding an item...just view source on the link above if you want to snag the updated code.
  • brettbrett FoxyCart Team
    You could also force the terms on the checkout itself.
    http://wiki.foxycart.com/docs:checkout:customfields#a_note_about_checkboxes

    You may want to do it in both places. The js that tookings created may be easier just to get going though.
  • Thanks Tookings for your example, it works great. I think having the Terms and Conditions in two places might be confusing and irritating. I'll be back soon with one last (I hope) question. Thanks again!
  • tookingstookings Member
    edited October 2009
    Awesome. :)

    And agreed...really more of a question of whether or not the T&C's should be tied to a specific product, or the entire/every order.
  • In my case, it was just one product. Thanks again - you guys are awesome!
Sign In or Register to comment.