SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question need some advise on a form

    ok on my web page have a table and a form is it poss when any one select from table it auto goes into the form which then gets emailed to me
    the web page is http://djbcaravanhire.co.uk/shop.php
    if you want to see what i have
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I din't get what you are actually expecting as advice. Can you be more descriptive what you want exactly and what is happening and what is not happening properly?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Doug, that is a Javascript question. You might find a script that does similar, or head over to the JS forum and ask how its done.

    However to do it something similar in PHP means
    a) collecting the order
    b) sending it to the server to work out the prices
    c) displaying it back to the user

    to achieve a) your form would need to encapsulate the table with rows like:
    PHP Code:
    <tr>
     <
    td>
        
    Dog wormer Pack of 6 )
     </
    td>
     <
    td>
        $
    23.99 
     
    <td>
        <
    input type=text name="product[23]" value ="0">
     </
    td>
    </
    tr
    Which could be generated from your database (providing an array such as:
    PHP Code:
    $products[23][label] = 'Dog wormer' ;
    $products[23][price] = 2399 ;
    $products[23][qty]   = 'Pack of 6' 
    To achieve b) you'd retrieve an array of all of their orders as;
    PHP Code:
    print_r $_POST('product') ) ; 
    So you could loop through theses results, and for those whose value is not 0, you can work out the price.

    Using JS alone means the user can order as much as they like, then change the price to one penny.

    You have to watch that after doing c) using the PHP-only way that they dont change the price too.

    You can certainly improve on this example, and add JS to enhance the experience, even using Ajax to work out the price "how much have I spent so far?" kinda thing.

    HTH
    Last edited by Cups; Aug 16, 2009 at 05:42. Reason: formatting example a bit better

  4. #4
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for that
    i was thinking some thing simmilar to this

    HTML Code:
    <body>
    <form>
    
    <tr>
    <td><strong>Frontline Spot On (Original)</strong></td>
    <br />
    <td>Frontline small 2 to 10kg 3 pipettes per box 14.00 </td><td>Quantity <td><input type="text" size="4" name="quan"></td></tr><input type="checkbox" name="frontline3" value="front3" />
    <br />
    <tr><td>Frontline small 2 to 10kg 6 pipettes per box 21.50 </td><td>Quantity <td><input type="text" size="4" name="quan"></td></tr><input type="checkbox" name="frontline6" value="front6" />
    <br />
    
    </form> 
    </body>
    the only entry needed is quantity and checkbox
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Of course you can do it that way, you can do it any way you want.

    The questions you want to address are:

    How do I keep the prices and description of the html form in sync with my prices (from a database?)
    How much code to I have to write?

    e.g. how are you generating these form elements "frontline6"

  6. #6
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok cups
    i do thank you for your help
    i want to keep it as simple as i can for the time being as i am doing this to help a young women who has just started her buisness up
    dont use database so prices would have to be change on the html page
    i have tried a couple of shopping carts but couldnt find a very simple one
    all i want the form to do is email the order to email addy i would use formtoemail to send
    cheers
    Doug
    could it be done with a spread sheet or am i off track
    Last edited by dougvcd; Aug 16, 2009 at 08:31. Reason: more info
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  7. #7
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Spreadsheet? No you're not off-track.

    You could export the data as .csv file and move it to the server when a price changes.

    (Or, you could get her to use Google Docs and make the spreadsheet available online, then your app can pick up details - but later perhaps?).

    With a .csv file similar to this:
    Code:
    1, "Dog wormer" , "Pack of 6", 23.99
    2, "Dog wormer" , "Pack of 12", 37.99
    You can find a script to read a similar csv file, and turn each element into an array:
    example.php
    PHP Code:
    <?php

    $products
    [1]['name'] = "Dog wormer";
    $products[1]['size'] = "Pack of 6";
    $products[1]['price'] = 23.99 ;

    $products[2]['name'] = "Dog wormer";
    $products[2]['size'] = "Pack of 12";
    $products[2]['price'] = 37.99;

    //Then loop through the array to make your form:

    echo '<table><form method=post action =""> ' PHP_EOL ;

    foreach( 
    $products as $k=>$v ){

    // echo what I gave you before

    echo '<tr>
     <td>
        ' 
    $v['name'] . '  ( ' $v['size'] . '  )
     </td>
     <td>
        $'  
    $v['price'] . 
     <td>
        <input type=text name="chosen_product[' 
    $k ']" value ="0">
     </td>
    </tr> ' 
    ;

    }

    echo 
    '</table><input type=submit></form>';

    if ( isset(
    $_POST['chosen_product']) ){

    echo 
    'This could be in your email:<hr />' ;
    var_dump$_POST ) ; // have a look

        
    foreach( $_POST['chosen_product'] as $k=>$v ){

        if( 
    $v 
        echo 
            
    $products[$k]['name'] . ' '
          
    $products[$k]['size'] . ' '
          
    $products[$k]['price'] * $v .'<br />' ;

        }

    echo 
    '<hr /> ' ;
    }
    ?>
    example.php contains a dummy array, generates the form and they works out the total price from the original array. Copy it to a file and test it out.

    That array could have 2 or 200 items, but you only need to get the arrays working correctly once.

    Have a play with it, and come back and ask when you cannot work out where you are going wrong. Understanding arrays is one of the hardest things to learn, but its worth taking time off to learn them.

  8. #8
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok good buddy played around a little and then found a shopping cart that is ok to start with untill they want to pay for one
    but a big thanks for your help
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net


Bookmarks

Posting Permissions

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