| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
interface HC3_Ui_Element_IForm |
| 3 |
{ |
| 4 |
public function setId( $set ); |
| 5 |
public function getId(); |
| 6 |
public function getAction(); |
| 7 |
public function setAction( $action ); |
| 8 |
public function render(); |
| 9 |
public function willCallCommand( $command ); |
| 10 |
} |
| 11 |
|
| 12 |
class HC3_Ui_Element_Form extends HC3_Ui_Abstract_Element implements HC3_Ui_Element_IForm |
| 13 |
{ |
| 14 |
protected $uiType = 'form'; |
| 15 |
|
| 16 |
protected $htmlFactory = NULL; |
| 17 |
protected $action = NULL; |
| 18 |
protected $content = NULL; |
| 19 |
protected $id = NULL; |
| 20 |
|
| 21 |
protected $willCallCommand = NULL; |
| 22 |
|
| 23 |
public function __construct( HC3_Ui $htmlFactory, $action, $content = NULL ) |
| 24 |
{ |
| 25 |
$this->htmlFactory = $htmlFactory; |
| 26 |
$this->content = $content; |
| 27 |
$this->setAction( $action ); |
| 28 |
$this->id = 'hc3form_' . mt_rand( 100000, 999999 ); |
| 29 |
} |
| 30 |
|
| 31 |
public function setId( $set ) |
| 32 |
{ |
| 33 |
$this->id = $set; |
| 34 |
return $this; |
| 35 |
} |
| 36 |
|
| 37 |
public function willCallCommand( $command ) |
| 38 |
{ |
| 39 |
$this->willCallCommand = $command; |
| 40 |
return $this; |
| 41 |
} |
| 42 |
|
| 43 |
public function getId() |
| 44 |
{ |
| 45 |
return $this->id; |
| 46 |
} |
| 47 |
|
| 48 |
public function getChildren() |
| 49 |
{ |
| 50 |
$return = array( $this->content ); |
| 51 |
return $return; |
| 52 |
} |
| 53 |
|
| 54 |
public function setChild( $key, $child ) |
| 55 |
{ |
| 56 |
$this->content = $child; |
| 57 |
return $this; |
| 58 |
} |
| 59 |
|
| 60 |
public function getAction() |
| 61 |
{ |
| 62 |
return $this->action; |
| 63 |
} |
| 64 |
|
| 65 |
public function setAction( $action ) |
| 66 |
{ |
| 67 |
$this->action = $action; |
| 68 |
return $this; |
| 69 |
} |
| 70 |
|
| 71 |
public function render() |
| 72 |
{ |
| 73 |
$content = $this->content; |
| 74 |
|
| 75 |
// $nonceVal = wp_create_nonce( 'shiftcontroller' ); |
| 76 |
// $nonceView = '<input type="hidden" name="hc_nonce" value="' . $nonceVal . '"/>'; |
| 77 |
// $content = $this->htmlFactory->makeCollection( array($nonceView, $content) ); |
| 78 |
|
| 79 |
$out = $this->htmlFactory->makeElement('form', $content) |
| 80 |
->addAttr('action', $this->action) |
| 81 |
->addAttr('method', 'post') |
| 82 |
->addAttr('accept-charset', 'utf-8') |
| 83 |
->addAttr('id', $this->id) |
| 84 |
; |
| 85 |
|
| 86 |
$attr = $this->getAttr(); |
| 87 |
foreach( $attr as $k => $v ){ |
| 88 |
$out->addAttr( $k, $v ); |
| 89 |
} |
| 90 |
|
| 91 |
return $out; |
| 92 |
} |
| 93 |
} |