field-template.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /**
  3. * This is a template file that you can use when creating new field types for Ninja Forms.
  4. * The simplest way to use this file is to copy its contents and paste them into a new file.
  5. * Then you would just replace the placeholder content with your own and remove the sections you don't need.
  6. *
  7. * Below you will find a breakdown of all the variables available to you when registering a field and what they do.
  8. **/
  9. $args = array(
  10. //name - Required - This is the name that will appear on the add field button.
  11. 'name' => 'My Custom Field',
  12. 'edit_options' => array( //Optional - An array of options to show within the field edit <li>. Should be an array of arrays.
  13. array(
  14. 'type' => 'text', //Required - What type of input should this be?
  15. 'name' => 'my_text', //What should it be named. This should always be a programmatic name, not a label.
  16. 'label' => 'My Text Label', //Label to be shown before the option.
  17. 'class' => 'widefat', //Additional classes to be added to the input element.
  18. ),
  19. array(
  20. 'type' => 'select',
  21. 'name' => 'my_select',
  22. 'label' => 'My Select Label',
  23. ),
  24. ),
  25. 'display_function' => 'ninja_forms_field_upload_display', //Required - This function will be called to create output when a user accesses a form containing this element.
  26. 'sub_edit_function' => 'ninja_forms_field_upload_sub_edit', //Optional - This will be called when an admin or user edits the a user submission.
  27. 'group' => '', //Optional
  28. 'edit_label' => true, //True or False
  29. 'edit_label_pos' => true,
  30. 'edit_req' => true,
  31. 'edit_custom_class' => true,
  32. 'edit_help' => true,
  33. 'edit_meta' => false,
  34. 'sidebar' => 'template_fields',
  35. 'edit_conditional' => true,
  36. 'conditional' => array(
  37. 'value' => array(
  38. 'type' => 'text',
  39. ),
  40. ),
  41. 'pre_process' => 'ninja_forms_field_upload_pre_process',
  42. 'process' => 'ninja_forms_field_upload_process',
  43. 'req_validation' => 'ninja_forms_field_upload_req_validation',
  44. );
  45. //Register the Upload field
  46. add_action('init', 'my_custom_field_register');
  47. function my_custom_field_register(){
  48. $args = array(
  49. 'name' => 'File Upload',
  50. 'edit_options' => array(
  51. array(
  52. 'type' => 'text',
  53. 'name' => 'my_text',
  54. 'label' => 'My Text Label',
  55. 'class' => 'widefat',
  56. ),
  57. array(
  58. 'type' => 'select',
  59. 'name' => 'my_select',
  60. 'label' => 'My Select Label',
  61. ),
  62. ),
  63. 'display_function' => 'ninja_forms_field_upload_display',
  64. 'sub_edit_function' => 'ninja_forms_field_upload_sub_edit',
  65. 'group' => '',
  66. 'edit_label' => true,
  67. 'edit_label_pos' => true,
  68. 'edit_req' => true,
  69. 'edit_custom_class' => true,
  70. 'edit_help' => true,
  71. 'edit_meta' => false,
  72. 'sidebar' => 'template_fields',
  73. 'edit_conditional' => true,
  74. 'conditional' => array(
  75. 'value' => array(
  76. 'type' => 'text',
  77. ),
  78. ),
  79. 'pre_process' => 'ninja_forms_field_upload_pre_process',
  80. 'process' => 'ninja_forms_field_upload_process',
  81. 'req_validation' => 'ninja_forms_field_upload_req_validation',
  82. );
  83. ninja_forms_register_field('_upload', $args);
  84. }