/includes/skip/elements/forms/textfield.php

  1. <?php 
  2. /** 
  3. * Skip Textfield Class 
  4. * @package Skip 
  5. * @since 1.0.0 
  6. * @ignore 
  7. */ 
  8.  
  9. namespace skip\v1_0_0; 
  10.  
  11. class Textfield extends Form_Element{ 
  12.  
  13. /** 
  14. * Constructor 
  15. * @since 1.0.0 
  16. * @param string $name Name of field. 
  17. * @param string $label Label of field. 
  18. * @param string $description Description of field which is shown under element 
  19. * @param array/string $args List of Arguments. 
  20. */ 
  21. function __construct( $name, $label = FALSE, $args = array() ) { 
  22. $defaults = array( 
  23. 'description' => '',  
  24. 'default' => '',  
  25. 'disabled' => FALSE 
  26. ); 
  27. $args = wp_parse_args( $args, $defaults ); 
  28. $args[ 'label' ] = $label; 
  29.  
  30. parent::__construct( 'input', $name, $args ); 
  31.  
  32. $this->add_param( 'type', 'text' ); // This is a text field! 
  33. /** 
  34. * Textfield getter Function 
  35. * @since 1.0.0 
  36. * @param string $name Name of field. 
  37. * @param string $label Label of field. 
  38. * @param string $description Description of field which is shown under element 
  39. * @see textfield() 
  40. * @ignore 
  41. */ 
  42. function get_textfield( $name, $label = FALSE, $description = FALSE ) { 
  43. $textfield = new Textfield( $name, $label, $description ); 
  44. return $textfield->render(); 
  45.  
  46. /** 
  47. * <pre>skip_text( $name, $args );</pre> 
  48. *  
  49. * Adding a Textfield. 
  50. *  
  51. * <b>Default Usage</b> 
  52. * <code> 
  53. * skip\textfield( 'name' ); 
  54. * </code> 
  55. * This will create an automated saved textfield. 
  56. *  
  57. * <b>Parameters</b> 
  58. *  
  59. * <code> 
  60. * $name // (string) (required) The name of the field. 
  61. * $args // (array/string) (optional) Values for further settings. 
  62. * </code> 
  63. *  
  64. * <b>$args Settings</b> 
  65. *  
  66. * <ul> 
  67. * <li>id (string) ID if the HTML Element.</li>  
  68. * <li>label (string) Label for Element.</li>  
  69. * <li>default (string) Default Value if no Value is set before.</li> 
  70. * <li>classes (string) Name of CSS Classes which will be inserted into HTML seperated by empty space.</li> 
  71. * <li>before_element (string) Content before the element.</li> 
  72. * <li>after_element (string) Content after the element.</li> 
  73. * </ul> 
  74. *  
  75. * <b>Example</b> 
  76. *  
  77. * Creating a labeled Textfield in an automatic saved form. 
  78. * <code> 
  79. * skip\form_start( 'myformname' ); 
  80. * skip\textfield( 'name', 'labelname' ); 
  81. * skip\form_end(); 
  82. * </code> 
  83. *  
  84. * Getting back the saved data. 
  85. * <code> 
  86. * $value= skip\value( 'myformname', 'name' ); 
  87. * </code> 
  88. * 
  89. * @package Skip\Forms 
  90. * @since 1.0.0 
  91. * @param string $name Name of field. 
  92. * @param string $label Label of field. 
  93. * @param string $description Description of field which is shown under element 
  94. * @see get_textfield() 
  95. */ 
  96. function textfield( $name, $label = FALSE, $description = FALSE ) { 
  97. echo get_textfield( $name, $label, $description ); 
.