Topic RSS
9:41 pm
Hello all,
I'm using CformsII to take registration data for an academic conference (http://www.ccdg2011.org/regist…..ation-form). We want to get an e-mail for each registration, so we know what is going on, but also want to pass the appropriate data (basically just the fee) to WorldPay for payments.
The approach that seems most logical is to use
to process the information from the form to (a) work out how much to charge and (b) submit the data to WorldPay. I can get all of this to work, but can't display the WorldPay page! I've got the following code as part of
:
## Set up cUrl stuff
$curl = curl_init();
$curlOptions = array(
CURLOPT_URL => 'https://secure.wp3.rbsworldpay.com/wcc/purchase',
CURLOPT_POST => TRUE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_POSTFIELDS => $postArray,
CURLOPT_HEADER => FALSE,
CURLOPT_CONNECTTIMEOUT => 2,
CURLOPT_RETURNTRANSFER => TRUE
) ;
curl_setopt_array ( $curl, $curlOptions);
$result = curl_exec( $curl ) ; // Save returned data
curl_close( $curl ) ;
echo "$result" ;
I know that things are working, as I can e-mail the result to me to check. So what I need to know is the appropriate combination of Cforms settings ('Hide form', 'Redirect to', etc.) and/or PHP material so that after a successful submission, Cforms deals with the 'e-mail to us' part, then displays the WorldPay page.
Thanks for any advice.
10:19 pm
Reading a bit further, I see that my_cforms_logic seems to have some ability to alter the redirection, but this seems to be the wrong 'place' to alter things, as I only want to redirect after processing.
9:36 pm
Okay, problem solved. For future reference, WorldPay allows you to pass your details by URL encoding as well as by POST. That means it is possible to tackle the issue from inside my_cforms_logic. My solution requires that 'Hide form after submission' is off and 'Redirect to' is on. Example code:
function my_cforms_logic($cformsdata,$oldvalue,$setting) {
if ( $setting == "redirection" ){
return my_cforms_special_action($cformsdata) ;
}
if ( $setting == "successMessage" ){
return 'Proceeding to secure payment system …' ;
}
}
function my_cforms_special_action($cformsdata) {
// Set up form data: $formID = '' for the first form
$formID = $cformsdata['id'];
$form = $cformsdata['data'];
// Only process for the first form
if ( $formID == '' ) {
// Convert the form fields into numbers, based on the form fields
if ($form['Registration type'] == 'Student') {
$amount = 60 ;
} elseif ($form['Registration type'] == 'Academic') {
$amount = 120 ;
} else {
$amount = 180 ; // Should be Industrial!
}
if ($form['Accommodation'] == 'Student') {
$amount += 38 ;
} elseif ($form['Accommodation'] == 'Broadview') {
$amount += 50 ;
} // else case here is 'None', of course
// WorldPay information for our site
$url = 'https://secure.wp3.rbsworldpay.com/wcc/purchase' ;
$instid = 'XXXXX' ; // Fill in merchant ID
$cartid = 'XXXXX' ; // Fill in account to credit (if needed)
$currency = 'GBP' ;
$desc = 'SomeRef' ; // A reference name
// Construct a global URL
return "$url?instId=$instid&cartId=$cartid&amount=$amount¤cy=$currency&desc=$desc" ;
} // End of $formID-dependent code
}
9:41 pm
I should add a few bits of explanation. First, I've obviously hard-coded the costs into my PHP, with the idea being that the e-mail I get is human-readable ('Registration type: Student', etc.), while the code does the conversion to money. Secondly, I needed to include the success message in the code: when I missed that out I got a blank message.
9:32 am
Joseph Wright said:
I should add a few bits of explanation. First, I've obviously hard-coded the costs into my PHP, with the idea being that the e-mail I get is human-readable ('Registration type: Student', etc.), while the code does the conversion to money. Secondly, I needed to include the success message in the code: when I missed that out I got a blank message.
I realised why I needed the success code: I'd forgotten to leave a default action in place:
function my_cforms_logic($cformsdata,$oldvalue,$setting) {
if ( $setting == "redirection" ){
return my_cforms_special_action($cformsdata) ;
}
return $oldvalue ; // Default action: do nothing
}
6:13 pm
February 10, 2009
OfflineThanks Joseph for sharing your coding experience with cforms using the my-functions.php approach, I think it'll be useful for all others!
I wish more cforms users would do so.
Paul.
Most Users Ever Online: 959
Currently Online:
60 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
tracedef: 43
mores: 21
Gyrus: 20
frozenwaste: 18
asuffredini: 15
photoworks: 14
Member Stats:
Guest Posters: 3552
Members: 1464
Moderators: 3
Admins: 1
Forum Stats:
Groups: 1
Forums: 4
Topics: 5159
Posts: 18392
Newest Members: juredujmovic, dreamkeeper, rajattyagi, wrokaa, lukass
Moderators: Paul (421), cnymike (8), sonika (95)
Administrators: Oliver (6398)
FAQs
Home
Add Reply
Add Topic
Quote










