Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created December 15, 2016 14:04
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save andrewlimaza/3a73d143e06bc1fdec2a0c5102b4fed5 to your computer and use it in GitHub Desktop.
Save andrewlimaza/3a73d143e06bc1fdec2a0c5102b4fed5 to your computer and use it in GitHub Desktop.
Register Helper field type example shows an example of every possible field in Register Helper
<?php
/**
* This example is to show you the 'niche' options each Paid Memberships Pro - Register Helper Add-on field can take and how to use it.
* For more information on the Register Helper Add-on please visit https://www.paidmembershipspro.com/add-ons/free-add-ons/pmpro-register-helper-add-checkout-and-profile-fields/
**/
function my_pmprorh_init()
{
//don't break if Register Helper is not loaded
if(!function_exists("pmprorh_add_registration_field"))
{
return false;
}
//define the fields
$fields = array();
// TEXT FIELD
$fields[] = new PMProRH_Field(
"text_example", // input name, will also be used as meta key
"text", // type of field
array(
"size" => 20 // size attribute of text field
)
);
// TEXTAREA
$fields[] = new PMProRH_Field(
"textarea_example", // input name, will also be used as meta key
"textarea", // type of field
array(
"rows" => 10, // row attribute of textarea (height)
"cols" => 50, // cols attribute of textarea (width)
)
);
// SELECT
$fields[] = new PMProRH_Field(
"select_example", // input name, will also be used as meta key
"select", // type of field
array(
"multiple" => true, //allow multiple selections for select
"options" => array(
"" => "", // blank option to be displayed first, followed by options
"option_1" => "Option 1",
"option_2" => "Option 2",
"option_3" => "Option 3",
)
)
);
// SELECT2
$fields[] = new PMProRH_Field(
"select_2_example", // input name, will also be used as meta key
"select2", // type of field
array(
"options" => array(
"" => "", // blank option to be displayed first, followed by options
"option_1" => "Option 1",
"option_2" => "Option 2",
"option_3" => "Option 3",
)
)
);
// CHECKBOX
$fields[] = new PMProRH_Field(
"checkbox_example", // input name, will also be used as meta key
"checkbox", // type of field
array(
"text" => "Check this" // string for <label></label>
)
);
// RADIO
$fields[] = new PMProRH_Field(
"radio_example", // input name, will also be used as meta key
"radio", // type of field
array(
"options" => array( // display the different options, no need for a "blank" option
"option_1" => "Option 1",
"option_2" => "Option 2",
"option_3" => "Option 3",
)
)
);
// FILE
$fields[] = new PMProRH_Field(
"file_example", // input name, will also be used as meta key
"file", // type of field
array(
"accept" => "image/*" // accept all image types for file upload (http://www.w3schools.com/TAGs/att_input_accept.asp)
)
);
// HTML
$fields[] = new PMProRH_Field(
"html_example", // input name, will also be used as meta key
"html", // type of field
array(
"html" => "<p><u>Add a paragraph into your checkout.php for Paid Memberships Pro. You may also use normal HTML code to generate fields.</u></p>" // accepts HTML code
)
);
// HTML
$fields[] = new PMProRH_Field(
"hidden_example", // input name, will also be used as meta key
"hidden" // type of field - creates a field that is hidden. (Great for creating a honeypot for your checkout form)
);
/**
* Conditional field example. Display a textfield depending on checkbox value
**/
$fields[] = new PMProRH_Field(
"conditional_example_depends_on", // input name, will also be used as meta key
"checkbox", // type of field
array(
"text" => "Check this to display a text field" // string for <label></label>
)
);
$fields[] = new PMProRH_Field(
"conditional_example_show", // input name, will also be used as meta key
"text", // type of field
array(
"depends" => array(
array(
"id" => "conditional_example_depends_on", //depends on this field
"value" => true //if checkbox is checked show this field
)
)
)
);
foreach($fields as $field)
pmprorh_add_registration_field(
"checkout_boxes", // location on checkout page
$field // PMProRH_Field object
);
//that's it. see the PMPro Register Helper readme for more information and examples.
}
add_action("init", "my_pmprorh_init");
@kimwhite
Copy link

Can you add an example of checkbox_grouped on this gist?

@nav4050
Copy link

nav4050 commented Jun 23, 2020

How do i make the below radio selection as required and how do i add the text box if user selects Option 3?

$fields[] = new PMProRH_Field(
"radio_example", // input name, will also be used as meta key
"radio", // type of field
array(
"options" => array( // display the different options, no need for a "blank" option
"option_1" => "Option 1",
"option_2" => "Option 2",
"option_3" => "Option 3",
)
)
);

@tanushka
Copy link

$fields[] = new PMProRH_Field(
"radio_example", // input name, will also be used as meta key
"radio", // type of field
array(
"options" => array( // display the different options, no need for a "blank" option
"option_1" => "Option 1",
"option_2" => "Option 2",
"option_3" => "Option 3",
)
)
);

$fields[] = new PMProRH_Field(
"conditional_example_show", // input name, will also be used as meta key
"text", // type of field
array(
"depends" => array(
array(
"id" => "radio_example", //depends on this field
"value" => "option_3" //if checkbox is checked show this field
)
)
)
);

@AnadarPro
Copy link

How can we pre-check a checkbox? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment