Skip to content

Commit

Permalink
minor tweaks for addon support
Browse files Browse the repository at this point in the history
  • Loading branch information
viveleroi committed Dec 16, 2011
1 parent f34b3fb commit e129bc6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
33 changes: 30 additions & 3 deletions Formbuilder/Formbuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct($form = false){
// Set the serialized structure if it's provided
// otherwise, store the source
if(array_key_exists('form_structure', $form)){
$form['form_structure'] = json_decode($form['form_structure']);
$form['form_structure'] = $this->objectToArray( json_decode($form['form_structure']) );
$this->_form_array = $form;
}
else if(array_key_exists('frmb', $form)){
Expand Down Expand Up @@ -109,7 +109,7 @@ public function generate_html($form_action = false){
if(is_array($this->_form_array['form_structure'])){

$html .= '<form class="frm-bldr" method="post" action="'.$form_action.'">' . "\n";
$html .= '<ol>'."\n";
$html .= '<ol class="frmb">'."\n";

foreach($this->_form_array['form_structure'] as $field){
$html .= $this->loadField((array)$field);
Expand Down Expand Up @@ -448,7 +448,7 @@ protected function loadSelectBox($field){
* @return string
* @access protected
*/
private function elemId($label, $prepend = false){
protected function elemId($label, $prepend = false){
if(is_string($label)){
$prepend = is_string($prepend) ? $this->elemId($prepend).'-' : false;
return $prepend.strtolower( preg_replace("/[^A-Za-z0-9_]/", "", str_replace(" ", "_", $label) ) );
Expand All @@ -466,5 +466,32 @@ private function elemId($label, $prepend = false){
protected function getPostValue($key){
return array_key_exists($key, $_POST) ? $_POST[$key] : false;
}


/**
* Converts an object into an array
* @param type $object
* @return type
*/
protected function objectToArray($object) {
if (is_object($object)) {
foreach ($object as $key => $value) {
if(is_object($value)){
$array[$key] = $this->objectToArray($value);
} else {
$array[$key] = $value;
}
}
}
else if(is_array($object)){
foreach ($object as $key => $value) {
$array[$key] = $this->objectToArray($value);
}
}
else {
$array = $object;
}
return $array;
}
}
?>
5 changes: 4 additions & 1 deletion css/jquery.formbuilder.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ ul.frmb {
.del-button {
float: right;
margin-right: 10px;
}
}

/* html display helpers */
textarea, .multi-row span { display: block; }
1 change: 1 addition & 0 deletions example-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>jQuery FormBuilder Demo (Output)</title>
<meta charset="utf-8" />
<link href="../../../css/jquery.formbuilder.css" media="screen" rel="stylesheet" />
</head>
<body>

Expand Down

0 comments on commit e129bc6

Please sign in to comment.