Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Created May 10, 2016 18:29
Show Gist options
  • Save Shelob9/ee2210ad15f66aee40acdc8fd23f3348 to your computer and use it in GitHub Desktop.
Save Shelob9/ee2210ad15f66aee40acdc8fd23f3348 to your computer and use it in GitHub Desktop.
Code examples for creating Caldera Forms add-on UI, excerpted from https://calderawp.com/downloads/braintree-for-caldera-forms/
<?php
//////////////////////////////////////////////////////////////////////////
//This is the config.php file that generates the processor admin UI /////
////////////////////////////////////////////////////////////////////////
//When you register your processor on the caldera_forms_get_form_processors filter, you set an argument for "template" with the path to this file.
if ( class_exists( 'Caldera_Forms_Processor_UI' ) ) {
//show an SSL required notice if is_ssl() is false
echo Caldera_Forms_Processor_UI::ssl_notice( 'Braintree for Caldera Forms' );
//get the field configuration
$cf_braintree_config_fields = cf_braintree_config_fields();
//get HTML for UI
$config_fields = Caldera_Forms_Processor_UI::config_fields( $cf_braintree_config_fields );
//echo UI
echo $config_fields;
}
<?php
///////////////////////////////////////////////////////////////////////////////////////////////////
//this is the fields config function that is in the functions.php file of our BrainTree add-on/////
///////////////////////////////////////////////////////////////////////////////////////////////////
/**
* The fields we need for this proccesor
*
* @since 0.1.0
*
* @return array
*/
function cf_braintree_config_fields() {
$fields = array(
array(
'id' => 'sandbox',
'label' => __( 'Test Mode', 'cf-braintree' ),
'type' => 'checkbox',
'required' => false,
),
array(
'id' => 'braintree_merchant_id',
'label' => __( 'Merchant ID', 'cf-braintree' ),
'desc' => __( 'Enter your unique merchant ID (found on the portal under API Keys when you first login).', 'cf-braintree' ),
'type' => 'text',
'magic' => false,
),
array(
'id' => 'braintree_merchant_account_id',
'label' => __( 'Merchant Account ID', 'cf-braintree' ),
'desc' => __( 'Enter your unique merchant account ID (found under Settings > Processing > Merchant Accounts).', 'cf-braintree' ),
'type' => 'text',
'magic' => false,
),
array(
'id' => 'braintree_public_key',
'label' => __( 'Public Key', 'cf-braintree' ),
'desc' => __( 'Enter your public key (found on the portal under API Keys when you first login).', 'cf-braintree' ),
'type' => 'text',
'magic' => false,
),
array(
'id' => 'braintree_private_key',
'label' => __( 'Private Key', 'cf-braintree' ),
'desc' => __( 'Enter your private key (found on the portal under API Keys when you first login).', 'cf-braintree' ),
'type' => 'text',
'magic' => false,
),
array(
'id' => 'orderID',
'label' => __( 'Order ID', 'cf-braintree' ),
'required' => false,
),
array(
'id' => 'submitForSettlement',
'label' => __( 'Submit For Settlement Immediately?', 'cf-braintree' ),
'required' => false,
'type' => 'checkbox'
),
array(
'id' => 'amount',
'label' => __( 'Price', 'cf-braintree' ),
),
array(
'id' => 'cardholderName',
'label' => __( 'Cardholder Name', 'cf-braintree' ),
),
array(
'id' => 'card_number',
'label' => __( 'Card Number', 'cf-braintree' ),
),
array(
'id' => 'card_exp_month',
'label' => __( 'Expiration Month', 'cf-braintree' ),
),
array(
'id' => 'card_exp_year',
'label' => __( 'Expiration Year', 'cf-braintree' ),
),
array(
'id' => 'card_cvc',
'label' => __( 'CVV Code', 'cf-braintree' ),
),
array(
'id' => 'first_name',
'label' => __( 'Customer First Name', 'cf-braintree' ),
),
array(
'id' => 'last_name',
'label' => __( 'Customer Last Name', 'cf-braintree' ),
),
array(
'id' => 'customer_email',
'label' => __( 'Customer Email', 'cf-braintree' ),
'allow_types' => 'email',
'exclude' => 'system'
),
array(
'id' => 'card_address',
'label' => __( 'Street Address Line 1', 'cf-braintree' ),
'required' => false,
),
array(
'id' => 'card_address_2',
'label' => __( 'Street Address Line 2', 'cf-braintree' ),
'required' => false,
),
array(
'id' => 'card_city',
'label' => __( 'City/ Locality', 'cf-braintree' ),
'required' => false,
),
array(
'id' => 'card_state',
'label' => __( 'State/ Providence/ Region', 'cf-braintree' ),
'required' => false,
),
array(
'id' => 'card_zip',
'label' => __( 'Zip Code/ Postal Code', 'cf-braintree' ),
'required' => false,
),
array(
'id' => 'card_country',
'label' => __( 'Country Code', 'cf-braintree' ),
'required' => true,
),
);
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment