cforms II User Forum

Registration is currently disabled.
Guest

FAQs

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 Related Topics
Radio Button Option opens new page
June 28, 2010
8:22 pm
Mike
Guest

Hello Everyone,

First, excellent form, easy to use, fits any website.

Question (if possible).  I would like to set the option that depending on what radio button is selected it opens a specific page.  Example;

Radio Button 1 selected, opens page 1

Radio Button 2 selected, opens page 2

This would happen after form is filled out (name, email, specific button selected) and the user hits submit.

Has anyone tried this or is it too complicated?

Thanks in advance,

Mike

June 29, 2010
7:45 am
Guest

That's not too bad to do. Assuming you want a flat redirect, open up my-functions.php. Uncomment my_cforms_logic. Next there will be a block like this:

if ( $setting == "redirection" ){

### note: '$$$mypick' references the ID of the HTML element and has been assigned
### to the drop down field in the form configuration, with [id:mypick] !

$userfield = $cformsdata['data'][$cformsdata['data']['$$$mypick']];

if ( $userfield == 'abc' )
return 'http://my.new.url.com';

if ( $userfield == 'def' )
return 'http://my.other.url.com';

return 'http//www.google.com';
// you can also do return $userfield just to see the end value for testing…

}

It won't have the google line in there, but I throw that in there anyway to confirm at least something is being called. Next, replace 'mypick' with the ID name of your radio button. The easy way to do this is to enable custom ids and then add [id:myarbitraryid] to the first part of the form text before any '|' characters. Do not change the $$$ in front. Also, enable the redirect feature. You can leave the url blank it's irrelevant.

August 6, 2012
12:59 pm
Dale
Guest

Hi There,

OK – so this is a closest thread I've found for what I'm trying to do. Thank you so much – the plugin is great. 

However – my client is trying to track search keywords, leading to which option is chosen in the form by using the redirect on the thank you pages. IE if the choose hardware as the option the client would like the form to go to a hardware option thank you page for tracking purposes. (I hope that makes sense)

Below is the code I have thus far, with no syntax errors. I assume that the error I get back is because I haven't linked the logic, to the redirection, to the page forwarding instruction. I did get the ID as ###6 but as for the rest, and my HUGE lack of PHP syntax – I'm stumped. 

Could you please help? 

The page is here http://www.spartan.co.za/contact-us/ (the code below I haven't implemented because the site is live, and I can't have broken redirects) could you look at my code below and tell me what I'm doing wrong. PHP makes me feel like such a dummy. 

 

###
### Find below examples for your custom routines. Do not change the function names.
###

my_cforms_logic();

### my_cforms_action() : gets triggered just before sending the admin email
###
### my_cforms_filter() : after validation, before processing/saving input data (nonAJAX)
###
### my_cforms_ajax_filter() : after validation, before processing/saving input data (AJAX)
###

### TO USE THE FUNCTIOS:
### >>> uncomment the functions as required
### >>> and provide your custom code where appropriate

 

###
### Your custom application logic features
###
### "successMessage" $cformsdata = cforms datablock
### "redirection" $cformsdata = cforms datablock
### "filename" $cformsdata = $_REQUEST
### "adminTO" $cformsdata = cforms datablock
### "nextForm" $cformsdata = cforms datablock
###
### "adminEmailTXT" $cformsdata = cforms datablock
### "adminEmailHTML" $cformsdata = cforms datablock
### "autoConfTXT" $cformsdata = cforms datablock
### "autoConfHTML" $cformsdata = cforms datablock
###

{
function my_cforms_logic($cformsdata,$oldvalue,$setting) {
}

### If you're unsure how to reference $cformsdata use the below @mail call to send you the data array
### @mail('your@email.com', 'cforms my_action test', print_r($cformsdata,1), 'From: your@email.com');

 

###
### example: the below code changes the original Success Message

if ( $setting == "successMessage" && $oldvalue<>'' ){

### only form #1 (default form) should be affected:
if ( $cformsdata['id']=='' ){

return $oldvalue . '
Form submitted on '.date('D, d M Y H:i:s');

}

}

 

### example: the below code changes a user-variable in both the Text & HTML part of
### the admin email & auto confirmation email

if ( $setting == "adminEmailTXT" || $setting == "adminEmailHTML" || $setting == "autoConfTXT" || $setting == "autoConfHTML" ){

### it's only changed though for form #2
### and requires "{CustomSalutation}" to be in the message(s)
if ( $cformsdata['id']==2 ){

### Returned message depends on user choosing the radio option "Mrs" or "Mr" (field value!)
if( $cformsdata['data']['Salutation']=='Mrs' )
return str_replace('{CustomSalutation}','Dear Mrs. ',$oldvalue);
else
return str_replace('{CustomSalutation}','Dear Mr. ',$oldvalue);

}

}

 

### example: changes the next form to be form ID 5 (which is multi form page enabled)

if ( $setting == "nextForm" ){

### the below only triggers when the configured "next form" would have been 4
### and the user did not check extended option checkbox
if ( $oldvalue=='4' && $cformsdata['data']['extended options']=='on' )
return 5;

}

 

### example: changes the admin email address to "test123

if ( $setting == "adminTO" ){

if ( $oldvalue=='placeholder' )
return 'test123';

}

 

### example: changes the name of the uploaded file in the email (adding a prefix taken form a form field)

if ( $setting == "filename" ){
return $_POST['filetype'] . $oldvalue;
}

 

### example: changes redirection address based on user input field

{ if ( $setting == "redirection" ){

### note: '$$$mypick' references the ID of the HTML element and has been assigned
### to the drop down field in the form configuration, with [id:mypick] !

$userfield = $cformsdata['data'][$cformsdata['data']['$$$6']];

if ( $userfield == 'Long term rental' )
return 'http://www.spartan.co.za/quote-thanks-ltr/';
if ( $userfield == 'Short term hire' )
return 'http://www.spartan.co.za/quote-thanks-str-2/';
}

 

return $oldvalue;
}

}

 

 

###
###
### Your custom user data input filter
###
###

/*

function my_cforms_action($cformsdata) {

### Extract Data
### Note: $formID = '' (empty) for the first form!

$formID = $cformsdata['id'];
$form = $cformsdata['data'];

### triggers on your third form
if ( $formID == '3' ) {

### Do something with the data or not, up to you
$form['Your Name'] = 'Mr./Mrs. '.$form['Your Name'];

}

### Send to 3d party or do something else
@mail('your@email.com', 'cforms my_action test', print_r($form,1), 'From: your@blog.com');

}

ending comment line for: my_cforms_action ——————--> */

 

###
###
### Your custom user data input filter (non ajax)
###
###

/*

function my_cforms_filter($POSTdata) {

### triggers on your third form
if ( isset($POSTdata['sendbutton3']) ) {

### do something with field name 'cf3_field_3'
### (! check you HTML source to properly reference your form fields !)
$POSTdata['cf3_field_3'] = 'Mr./Mrs. '.$POSTdata['cf3_field_3'];

### perhaps send an email or do somethign different
@mail('your@email.com', 'cforms my_filter_nonAjax test', 'Form data array (nonAjax):'.print_r($POSTdata,1), 'From: your@blog.com');
}
return $POSTdata;

}

ending comment line for: my_cforms_filter ——————--> */

 

###
###
### Your custom user data input filter (ajax)
###
###

/*

function my_cforms_ajax_filter($params) {

### triggers on your third form
if ( $params['id']=='3' ) {

### do something with field #1
### (! for ajax, all form fields are counted sequentially! !)
$params['field_1'] = 'Mr./Mrs. '.$params['field_1'];

### perhaps send an email or do somethign different
@mail('your@email.com', 'cforms my_filter_Ajax test', 'Form data array (Ajax):'.print_r($params,1), 'From: your@blog.com');

}
return $params;

}

ending comment line for: my_cforms_ajax_filter ——————--> */

?>

August 6, 2012
1:04 pm
Dale
Guest

Sorry – here are the errors that code gives. I just don'tknow how to fix it. 

Warning: Missing argument 1 for my_cforms_logic(), called in /home/adpxxsfg/public_html/wp-content/plugins/cforms/my-functions.php on line 6 and defined in /home/adpxxsfg/public_html/wp-content/plugins/cforms/my-functions.php on line 37

Warning: Missing argument 2 for my_cforms_logic(), called in /home/adpxxsfg/public_html/wp-content/plugins/cforms/my-functions.php on line 6 and defined in /home/adpxxsfg/public_html/wp-content/plugins/cforms/my-functions.php on line 37

Warning: Missing argument 3 for my_cforms_logic(), called in /home/adpxxsfg/public_html/wp-content/plugins/cforms/my-functions.php on line 6 and defined in /home/adpxxsfg/public_html/wp-content/plugins/cforms/my-functions.php on line 37

Forum Timezone: Europe/Berlin

Most Users Ever Online: 959

Currently Online:
24 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: 3708

Members: 1463

Moderators: 3

Admins: 2

Forum Stats:

Groups: 1

Forums: 4

Topics: 5307

Posts: 18665

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

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

Administrators: Oliver (6400), Nicky (3)