Textbox.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /**
  3. * Class NF_Field_Textbox
  4. */
  5. class NF_Fields_Textbox extends NF_Abstracts_Input
  6. {
  7. protected $_name = 'textbox';
  8. protected $_section = 'common';
  9. protected $_icon = 'text-width';
  10. protected $_aliases = array( 'input' );
  11. protected $_type = 'textbox';
  12. protected $_templates = 'textbox';
  13. protected $_test_value = 'Lorem ipsum';
  14. protected $_settings = array(
  15. 'disable_browser_autocomplete',
  16. 'mask',
  17. 'custom_mask',
  18. 'custom_name_attribute',
  19. 'personally_identifiable'
  20. );
  21. public function __construct()
  22. {
  23. parent::__construct();
  24. $this->_nicename = __( 'Single Line Text', 'ninja-forms' );
  25. add_filter( 'ninja_forms_subs_export_field_value_' . $this->_name, array( $this, 'filter_csv_value' ), 10, 2 );
  26. }
  27. public function filter_csv_value( $field_value, $field ) {
  28. /*
  29. * sanitize this in case someone tries to inject data that runs in
  30. * Excel and similar apps
  31. * */
  32. if( 0 < strlen( $field_value ) ) {
  33. $first_char = substr( $field_value, 0, 1 );
  34. if( in_array( $first_char, array( '=', '@', '+', '-' ) ) ) {
  35. return "'" . $field_value;
  36. }
  37. }
  38. return $field_value;
  39. }
  40. }