Members Login
Chronoforms Book
The ChronoForms Book, written for ChronoForms v3 contains 350 pages of invaluable ChronoForms How-tos hints and tips.
Note: many of the ideas can be used in ChronoForms v4 but the admin interface is very differetn and code examples may need to be modified.
ChronoEngine.com is
| Paid registration using Paypal plugin |
|
Here I'm going to show how to create a paid registration form using the Joomla registration plugin + paypal API plugin, the tutorial will show some of the powerful features of Chronoforms V3.1 as well!
first, this is my form:
as you can see, very basic form with all basic details for registration and billing! Ok, lets configure the Joomla registration plugin for this form, go to the forms manager, check the form and click "Joomla registration" from the left side plugins bar, configure it as shown, the first 5 fields are form fields names dependent and will need to match the fields names at your form code!
the last 6 settings are form independent and can be chnaged based on your requirements! please note that the plugin is set to run AFTER email! now save, then go into the form and enable the Joomla registration plugin under the plugins tab, The Joomla registratio plugin ONLY, leave the paypal plugin unchecked!
hit save again, now lets configure the paypal plugin
again, all fields above are form fields names dependent and so place them wisely, you can keep them the same though if you are going to use the form code I posted here! note that this plugin too will run AFTER email! now lets configure our paypal API settings, you need to get this data from your paypal account, the data shown are the sandbox data, it may be useful to set debug to yes to see some useful info after the form is submitted which includes the paypal response!
Now lets configure an email to send to the user once paid and registered :
Please note that the email is NOT enabled by default so the form doesn't send it by default! we will enable it manually in our code! here is a simple template as well:
hit apply and go to the form code tab and place this code in the onSubmit after email box : <?php $MyPlugins =& CFPlugins::getInstance($MyForm->formrow->id); if(!$MyPlugins->cf_joomla_registration['errors']){ $MyPlugins->runPlugin('after_email', array('ONSUBMIT', 'ONLOADONSUBMIT'), 'cf_paypal_api'); if($MyPlugins->cf_paypal_api['payment_status'] == 'SUCCESS'){ echo "Thank you for registering at Mysite.com. You will be recieving a confirmation email shortly"; $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id); $MyFormEmails->setEmailData(1, 'enabled', '1'); $MyFormEmails->sendEmails($MyForm, $MyFormEmails->emails); }else{ $regUser = new JUser($MyPlugins->cf_joomla_registration['user']->id); $regUser->delete(); $MyForm->addErrorMsg( 'An error occured : '.$MyPlugins->cf_paypal_api['error_message'] ); $MyForm->haltFunction["autogenerated_after_email"] = true; } }else{ $MyForm->addErrorMsg($MyPlugins->cf_joomla_registration['errors']); $MyForm->haltFunction["autogenerated_after_email"] = true; } ?>
So what does the code above do ? Once the form submits, the Joomla registration plugin will run and will try to register the user to the website database, if any problems happened then we will report the error back to the user and reshow the form : $MyPlugins =& CFPlugins::getInstance($MyForm->formrow->id); $MyForm->addErrorMsg($MyPlugins->cf_joomla_registration['errors']); $MyForm->haltFunction["autogenerated_after_email"] = true; // disable db connection save if all went fine with the registration then we will run the paypal plugin, if paypal returned success then we show a thanks message and send our previously configured email: if(!$MyPlugins->cf_joomla_registration['errors']){ $MyPlugins->runPlugin('after_email', array('ONSUBMIT', 'ONLOADONSUBMIT'), 'cf_paypal_api'); if($MyPlugins->cf_paypal_api['payment_status'] == 'SUCCESS'){ echo "Thank you for registering at Mysite.com. You will be recieving a confirmation email shortly"; $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id); $MyFormEmails->setEmailData(1, 'enabled', '1'); //enable the email $MyFormEmails->sendEmails($MyForm, $MyFormEmails->emails); //end form emails } if Paypal failed then we delete the user account created and reshow the form with the paypal error and ask the user to re-register! $regUser = new JUser($MyPlugins->cf_joomla_registration['user']->id); // load inserted user $regUser->delete(); // delete user $MyForm->addErrorMsg( 'An error occured : '.$MyPlugins->cf_paypal_api['error_message'] ); // show paypal error $MyForm->haltFunction["autogenerated_after_email"] = true; That's It!! :) the form source code is below
<table width="95%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td colspan="4"><h3>Your Login Information</h3></td>
</tr>
<tr>
<td>Desired Login Name:</td>
<td colspan="3"><input type="text" name="login_name" id="login_name" /></td>
</tr>
<tr>
<td>Password:</td>
<td colspan="3"><input type="text" name="password1" id="password1" /></td>
</tr>
<tr>
<td>Confirm Password:</td>
<td colspan="3"><input type="text" name="password2" id="password2" /></td>
</tr>
<tr>
<td>Email Address:</td>
<td colspan="3"><input type="text" name="email_address" id="email_address" /></td>
</tr>
<tr>
<td colspan="4"><h3>Your Information</h3></td>
</tr>
<tr>
<td>First Name:</td>
<td><label>
<input type="text" name="first_name" id="first_name" />
</label></td>
<td>Last Name:</td>
<td><input type="text" name="last_name" id="last_name" /></td>
</tr>
<tr>
<td>Address 1:</td>
<td colspan="3"><input type="text" name="address1" id="address1" /></td>
</tr>
<tr>
<td>Address 2:</td>
<td colspan="3"><input type="text" name="address2" id="address2" /></td>
</tr>
<tr>
<td>City:</td>
<td colspan="3"><input type="text" name="city" id="city" /></td>
</tr>
<tr>
<td>State:</td>
<td><select name="state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select></td>
<td>Zip Code</td>
<td><input name="zipcode" type="text" id="zipcode" size="10" maxlength="5" /></td>
</tr>
<tr>
<td>Phone Number:</td>
<td colspan="3"><input type="text" name="phone_number" id="phone_number" /></td>
</tr>
<tr>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="4"><h3>Billing Information</h3></td>
</tr>
<tr>
<td>Name on Credit Card:</td>
<td colspan="3"><input type="text" name="cc_name" id="cc_name" /></td>
</tr>
<tr>
<td>Credit Card Type:</td>
<td colspan="3"><select name="cc_type" id="cc_type">
<option value="Visa">Visa</option>
<option value="MasterCard">MasterCard</option>
<option value="Discover">Discover</option>
<option value="Amex">American Express</option>
</select>
</td>
</tr>
<tr>
<td>Credit Card Number:</td>
<td colspan="3"><input type="text" name="cc_number" id="cc_number" /></td>
</tr>
<tr>
<td>Expiration Month:</td>
<td><select name="expDateMonth" id="expDateMonth">
<option value=1>01</option>
<option value=2>02</option>
<option value=3>03</option>
<option value=4>04</option>
<option value=5>05</option>
<option value=6>06</option>
<option value=7>07</option>
<option value=8>08</option>
<option value=9>09</option>
<option value=10>10</option>
<option value=11>11</option>
<option value=12>12</option>
</select>
</td>
<td>Expiration Year:</td>
<td><select name="expDateYear" id="expDateYear">
<option value=2008>2008</option>
<option value=2009>2009</option>
<option value=2010 selected>2010</option>
<option value=2011>2011</option>
<option value=2012>2012</option>
<option value=2013>2013</option>
<option value=2014>2014</option>
<option value=2015>2015</option>
</select>
</td>
</tr>
<tr>
<td>Security Code:</td>
<td colspan="3"><input type="text" name="cc_security" id="cc_security" /></td>
</tr>
<tr>
<td>Billing Zip Code:</td>
<td colspan="3"><input type="text" name="cc_zipcode" id="cc_zipcode" /></td>
</tr>
<tr>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="4"><label>
<input type="submit" name="button" id="button" value="Submit" />
</label></td>
</tr>
</table>
<input type="hidden" name="amount" value="35.00" />
<input type="hidden" name="currencyCode" value="USD" />
<input type="hidden" name="countryCode" value="US" />
|

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for
goods and services provided by ChronoEngine.com







