3 ways to create a small Joomla! shopping cart with RSForm!Pro and PayPal - Part 3Posted by. Mihaela This article was posted in RSForm!Pro Tagged with joomla extensions , forms , PayPal , shopping cart
To install the example, in the backend panel, head to Components -> RSForm!Pro ->Backup/Restore. After the form restore, you will find the Custom PayPal example in the Manage Forms tab. Note that you will need at least RSForm!Pro revision 28.
You can use custom scripts with your RSForm!Pro forms to extend the component functionality: you can specify product quantity, automatically calculate the total amount, auto fill the form fields, add a shipping cost and handling fee, etc.
Specifying products quantity:
We will modify the custom script available on the forum to automatically calculate the total amount of the selected products and passe it further to the PayPal page.
The form includes 3 products with different prices. For each product, the customer can select the desired quantity from a drop-down box. The form can be easily extended to a higher number of products. (when you add more products don't forget to change the Form Layout).
e.g. Product 1 - Price $100.00: Quantity     [. . . .] 
Product 2 - Price $200.00: Quantity     [. . . .] 
Product 3 - Price $90.00: Quantity     [. . . .] 
The Total field will automatically calculate the amount based on the user's selection:
($100 x 3)+($90 x 5)=$750
After submission, the customer will be redirected to the PayPal page.
Steps to create the above Paypal form:
1. Add products, prices and quantities.
We have created 3 Checkbox Groups to add the products along with their prices, and 3 Dropdown Components for specifying the quantity.
The Additional Attributes area incorporates the following code snippets: onclick="enableQuantity('Product10','QunatityProd1');" and onchange="calculateTotal();"
- The format of the Items area (100|Product 1 - Price $100) is designed to separate the value from the label, thus the Product 1 - Price $100 will be displayed in the front-end, but if selected, the price (100) will be stored.
2. Modify form layout.
After all the fields have been added, you will have to go to the Form Layout tab, and uncheck the Auto-generate layout checkbox. This will allow you to edit the actual form layout. It is to be noted that if you add a field after this has been unchecked the layout code will not be automatically updated.
document.getElementById(quantity).disabled = false;
document.getElementById(quantity).disabled = true;
var products = new Array("Product10","Product20","Product30");
var total = 0;
for(i;i < products.length;i++)
total = total + parseInt(document.getElementById(products[i]).value) * parseInt(document.getElementById('QuantityProd'+(i+1)).value);
document.getElementById('Total').value = total;
The enableQuantity function will enable the quantity drop-down if you have checked a product checkbox. This has been added so you can't select a quantity if you don't have selected a product first.
The calculateTotal function does what the name states - it calculates the total for the selected products and quantity. In terms of functionality, it verifies what products have been checked, gets the quantity and updates the value of the total field.
3.Add additional attributes to checkbox and drop-downs
After modifying the form layout, go back to the Components tab and add the following Additional Attributes:
In the Checkbox Groups add :
In the Drop-down components add:
4. Add the custom script in the Scripts tab
Now, that all the calculation and aesthetics part is over it is time to move on to the actual PayPal part. In order to redirect to PayPal after the form is submitted you will have to place the following script in the Scripts called after form process area:
if($_POST['form']['Total'] != '0')
$business = 'firstname.lastname@example.org';
$item_name = 'Products';
$currency_code = 'USD';
$amount = $_POST['form']['Total'];
$return = 'http://your_site.com';
header('Location: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business='.$business.'&item_name='.$item_name.'¤cy_code='.$currency_code.'&amount='.$amount.'&return='.$return); exit();
The custom script must be added in the "Script called after form has been processed ".
(Components -> RSForm!Pro -> Manage forms -> Select the PayPal form -> Scripts -> Script called after form has been processed ).
You will find a detailed explanation of the "Script called after form has been processed" section in the article Custom PHP code from documentation.
if($_POST['form']['Total'] != '0') : This basically verifies if the value of the total field is not "0". If it is 0 then there is no point to redirect to PayPal to complete the payment, and the form will carry out its normal routine. If it is different from "0" then set the PayPal parameters and redirect to PayPal.
$email@example.com' - replace firstname.lastname@example.org email with your PayPal seller account
$item_name='Products' - the product name that you intend to sell trough PayPal
$currency_code='USD' - you can change this value according to the PayPal currency codes
$amount=$_POST['form']['Total'] - grabs the calculated total value. This value will be passed to PayPal.
$return='http://your_site.com' - replace http://your_site.com with the website address where you want to redirect the customers after purchasing.
The parameters that we used are for demo purpose only. You should use the details from your PayPal account. Additional parameters can be used in the same manner. Further details on these can be seen on the PayPal documentation page.
If you want an alternative to custom scripting, you can use the RSForm!Pro PayPal plugin that we have discussed in the first 2 parts of this article: PayPal form with a Single Product field and PayPal form with Multiple Products fields, although it won't be as much as flexible as the custom script is.
If you have further questions about this script or about integrating RSForm!Pro with PayPal, you can ask our support department or simply, leave them in comments.
- 3 ways to create a small Joomla! shopping cart with RSForm!Pro and Paypal - Part 1
- 3 ways to create a small Joomla! shopping cart with RSForm!Pro and Paypal - Part 2
- 3 ways to create a small Joomla! shopping cart with RSForm!Pro and Paypal - Part 4: payment confirmation
Well, I'm trying to enable a customized form in which i can calculate the total of the shopping, but i don't want to submit my form to paypal.
I've made my form, but i can't display the total..I don't know if it is just a text field with some extra attribute or if it's the paypal total option...
We have a product that has a fixed, required value of X dollars. However we want to take an additional, not necessarily required donation using this boxes and or a box where they could enter their own amount.
We were using the Paypal plugin, but cant use both single product (original setup) and multiple products at the same time.
What could be the best way to have the single product plus the additional donation?Quote
$amount = floatVal($_POST ['form']['Total']) 40;
is there a tutorial for adding a paypal field that the user can enter there own amount (like for donations)?
You can simply adapt this one or the one posted on the http://www.rsjoomla.com/customer-support/forum/37-rsform-pro/4877-rsform-pro-paypal-integration.html. The only difference is that you will have to grab the amount like this:
I want to be able to produce buttons for about 100 items (each with about 10-20 different sizes each which are different prices) items as quickly as possible.
Product 1 for example has 20 sizes and each size is a different price. I want to create it so that the customer can select a size from product one but also a quantity, is it possible to do this? I was able to create a button with product 1 (10 options) and i can check any options I want but the quantity dropdown is global.
I need to know i can do this before purchasing.
Alexandru Plapana said:
I am not sure if you worked with RSForm!Pro before, but this was an update on an existing feature. Backup / Restore was available prior to this update too. You are correct though - the previous version did not provide an option to maintain form ids, whic ... RSForm!Pro Ver. 1.50.0 - Rewritten and Improved Backup / Restore Functionality
Alexandru Plapana said:
I doubt that anyone would ever be able to create a layout / style that would fit everyone needs. It is important to provide the flexibility for users (indeed, with enough knowledge) to make adjustments for their own, particular needs. Thank you for point ... RSEvents!Pro Template Override Example
Ville Niemi said:
Thank you! I hope I will never need this anymore, but I have done site migrations before, and direct copying of database tables really should NOT be the only working way to move forms and submissions. Actually, the fact that it really was as simple as ju ... RSForm!Pro Ver. 1.50.0 - Rewritten and Improved Backup / Restore Functionality
Ville Niemi said:
I made an RSEvents template override just BEFORE you posted this tutorial... just lucky I guess. Few notes: J!3.3 template manager has a pretty handy feature that makes an override for you with a single click. You should mention that. When making the ove ... RSEvents!Pro Template Override Example
Alexandru Plapana said:
First of all, if the resource is private, it would be best to simply have the download folder outside of the public_html folder. This way, direct access won't be possible. Second of all, you can set permissions per file / folder. PS: I do agree that th ... RSFiles! Ver. 1.14.0 - Improved file permissions, frontend ordering and overall experience