Test Forms Class - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Test Forms Class.php

  1. <?php
  2. class Clio_Users_Forms {
  3.  
  4.    protected $slug;
  5.    protected $args = array(
  6.       'id' => '',
  7.       'name' => '',
  8.       'class' => '',
  9.       'type' => 'text',
  10.       'required' => '',
  11.       'value' => '',
  12.       'values' => array(),
  13.       'placeholder' => '',
  14.       'options' => array(),
  15.       'selected' => '',
  16.       'checked' => ''
  17.    );
  18.  
  19.    public function get_attr( $args ) {
  20.       $args = array_merge( $args, $this->args ); 
  21.       foreach( $args as $key => $value ) {
  22.          if( $value ) {
  23.             $args[$key] = "{$key}=\"{$value}\"";
  24.          }
  25.          else {
  26.             unset( $args[$key] );
  27.          } 
  28.       }
  29.       print_r( $args );
  30.       return $args;
  31.    }
  32.  
  33.    public function input( $args ) {
  34.  
  35.       $this->get_attr( $args );
  36.       extract( $args );
  37.  
  38.       ob_start(); ?>
  39.  
  40. <label for="<?php echo $name; ?>">
  41.    <input type="<?php echo $type; ?>" name="<?php echo $name; ?>
  42. </label>
  43.  
  44.       <?php return ob_get_clean();
  45.    }
  46. }
  47.  
  48. $args = array(
  49.       'name' => 'mon_nom',
  50.       'type' => 'text',
  51.       'value' => 'klk',
  52.    );
  53.  
  54. $inst = new Clio_Users_Forms();
  55. print_r( $inst-> get_attr( $args ));
File Description
  • Test Forms Class
  • PHP Code
  • 15 Apr-2018
  • 1.09 Kb
You can Share it: