cforms II User Forum

Registration is currently disabled.
Guest

FAQs

Login form protected by Login LockDown.


Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

    

Wildcard usage:
*  matches any number of characters    %  matches exactly one character

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
Show 'dynamic' redirection page
March 8, 2011
9:41 pm
Guest

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

my_cforms_action

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

my_cforms_action

:

## 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.

March 8, 2011
10:19 pm
Guest

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.

March 10, 2011
9:36 pm
Guest

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&currency=$currency&desc=$desc" ;

    } // End of $formID-dependent code
}

March 10, 2011
9:41 pm
Guest

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.

March 11, 2011
9:32 am
Guest

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

}

March 13, 2011
6:13 pm
Paul
Amsterdam, NL
Moderator
Forum Posts: 421
Member Since:
February 10, 2009
Offline

Thanks 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.

* Paul Silter
November 1, 2012
12:19 pm
sdk
Guest

How do I change

 return "$url?instId=$instid&cartId=$cartid&amount=$amount&currency=$currency&desc=$desc" ;

into sending a POST method ?

 

Thanks

Forum Timezone: Europe/Berlin

Most Users Ever Online: 959

Currently Online:
29 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: 3756

Members: 1463

Moderators: 3

Admins: 2

Forum Stats:

Groups: 1

Forums: 4

Topics: 5355

Posts: 18731

Newest Members: juredujmovic, dreamkeeper, rajattyagi, wrokaa, lukass

Moderators: Paul (421), cnymike (8), sonika (95)

Administrators: Oliver (6400), Nicky (3)