Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Help needed with form & paypal

Hi guys,

Im having a problem with shipping rates and paypal. I have been following the 'Build a Simple PHP Application' videos but when configuring the shipping rates the UK paypal is only letting me set flat rates or percentages. Problem being I would like to be able to set different rates for different locations really.

Here is my form code so far:

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="<?php echo $product["paypal"]; ?>">
    <input type="hidden" name="item_name" value="<?php echo $product["name"]; ?>">
    <input type="hidden" name="shipping" value="10.75"> 

    <table>
    <tr>
        <th>
            <input type="hidden" name="on0" value="Size">
            <label for="os0">Size</label>
        </th>
        <td>
            <select name="os0" id="os0">
                <option value="S">S </option>
                <option value="M">M </option>
                <option value="L">L </option>
                <option value="XL">XL </option>
                <option value="XXL">XXL </option>
            </select>
        </td>
    </tr>
    <tr>
        <th>
            <input type="hidden" name="on1" value="Gender">
            <label for="os1">Gender</label>
        </th>
        <td>
            <select name="os1" id="os1">
                <option value="Male">Male </option>
                <option value="Female" >Female </option>
            </select> 
        </td>
    </tr>
    </table>
    <input type="submit" value="Add to Cart" name="submit">
</form>

If anyone has a solution it would be very much appreciated. Thanks :)

1 Answer

Alexander Sobieski
Alexander Sobieski
6,555 Points

If you're looking to do something more complex, such as Table Rate shipping, or integrating with UPS or the postal system, it's going to be a bit of work.

The issue is, if you let Paypal store the shopping cart, you have to let them use their rules to calculate the shipping.

Your best bet would probably be to use an out-of-the-box shopping cart system (and customize the theme)... or learn to code your own shopping cart system and pass the final info to Paypal at the end of the transaction.

Maybe Randy or a Moderator would know more about that.