Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    html shopping cart - Forms

    Hi everyone,

    Hi, i'm Jackie and i'm new to the HTML scene. I am writing in need of some help as I have to write a basic "shopping cart" for an assignment.

    I have done some research and have begun writing simple html code. Essentially i have a form where i enter the quantity i want for ITEM X which cost say $1. When i push submit it goes to a CGI script which i use the quantity to determine how many the customer wants. Now, how do I obtain the price for ITEM X? Is it possible to, on submit, to send the quantity information (user input) and the price (fixed) to the CGI script?

    Here's the code part i'm talking about:
    ----------------------------------------------------------------------
    <b>Book 1 Cost:</b> $1
    <br>
    <form name="input" action="/cgi-bin/add_to_cart.cgi" method="get">
    Please enter quantity:
    <input type="text" name="Item1Q">
    <input type="submit" value="Add to Cart">
    </form>
    ----------------------------------------------------------------------

    You see when i go in the cgi script:

    my $itemQuantity = param('Item1Q");

    $itemQuantity would contain the quantity from html code correct? is it possible to pass, say a nother variable, i.e. the price of the book?

    Thanks for any help ,
    Jackie

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,462
    Thanks
    0
    Thanked 633 Times in 623 Posts
    You could use a hidden input field eg. <input type="hidden" value="5.00">

    Not advisable for a real cart though unless the server side script validates that the correct price is passed as it is trivial for someone to copy the form and change a hidden price to 0.01
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey felgall


    Thanks for ur reply. By servier side script do u mean, say a CGI script that queries a database which would have the price of the book to compare it with?

    JB

  • #4
    Regular Coder
    Join Date
    Sep 2006
    Location
    Vermont, USA
    Posts
    154
    Thanks
    0
    Thanked 6 Times in 6 Posts
    I second that motion. The only reason for providing the price in the form would be to use it in actual calculations. This is clearly not advised for the reasons mentioned by felgall. And yes, he means you would take the price that was sent to the script and validate it against the price stored for the given item number, however, this just complicates matters when you should be pulling the price by id anyway, without the need for comparison.

    This assumes you have a database of products, if you dont...are you using flat files? Hard coding these pages? If you're hardcoding or using flat files, it's highly advised that you start learning database programming immediately - once you understand how to do it correctly, it can cut down your development time significantly.
    Active PHP/MySQL application developer available for immediate work.
    syosoft.com mavieo.com - Remote Web Site Administration Suite - Reseller Ready

  • #5
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your reply syosoft!

    Yes I realised i would need a database of products. I'm okay with databases so that shouldn't be a problem. I've read through the textbook and i'm having problems just thinking how ALL of these things (PERL/CGI, HTML, MySQL, Apache) would come together.

    U see i have a form field of "quantity" and when i put, say quantity of 3, i pass that into a cgi module that i'm writing, and the cgi would have to query the dB of products, find the correct product and "add" it to a cart.

    What i havn't thought of is where to store the cart information (i.e. the number and type of products). Have you guys got any suggestions?

    Cheers,
    JB


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •