Hi everyone,
I updated the Form Builder module today to give it some improvements. You can get it from the modules>formbuilder folder.
Please check the format of the $form array that is being formed. I cant find examples of some of the widget properties. If someone can provide them, It'll be really really helpful.
form[checkboxes][' #default_value'] // 0,1,2 or value of the key?
form[checkbox]['#default_value'] // 0,1 or true/false
form[radios]['#default_value'] // similar problem
form[radio]['#default_value'] // similar problem
form[select]['#default_value'] // similar problem
form[date]['#default_value'] // (what will the format of the date be?)So basically .... all the default_value properties.
secondly, Right now the #options property of checkboxes and select are strings of format:
'#options' : "array('key1' => 'value 1', 'key2' => 'value 2'",Now is this correct or am I supposed to keep the type of #options as an array? In the latter case it will be something like this:
'#options' : {
'key1' : 'value 1',
'key2' : 'value 2'
}Everything till now was javascript.
I am also having problems with Urls. here is the code:
<?php
function formbuilder_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'formbuilder/receive',
'title' => t('formbuilder receive'),
'access' => user_access('formbuilder save forms'),
'type' => MENU_CALLBACK,
'callback' => 'formbuilder_receive'
);
:
:
?>This code basically defines a page which on my computer I can access via browser at:
http://localhost/drupal-4.7.2/?q=formbuilder/receive
Now I am trying to post the js form object through AJAX. For posting the form object, I need the url of the above page and I can't figure out how to get that. Simeple js files are included without a problem because drupal_get_path provides the absolute path. But for "formbuilder/receive", the page does not exist so I get a 404. Please help me out here...
Right now I am using a workaround posted below but I dont think this is going to work is all cases.
function send()
{
$.post("?q=formbuilder/receive",{ // The address of the page. A proper alternative for this is what I need
"formId" : formId, // Id of the form.
"properties" : s.object(properties) // The serialized js form Object
},function(xml){ alert( decodeURIComponent(xml)); }); // Some call back function
}Please Help me out here :)

Comments
Nice progress!
You're really pushing ahead. The formbuilder is looking very good.
A few comments and suggestions:
jsTools.queryvariable in jstools.module. It tracks whether clean_urls are enabled, and therefore whether site urls should have the '?q='. I'd say what you have is fine for now though.#default_valuesettings, these are generally references to objects passed into a function building a form. For example, a node title has a default value of$node->title--the title assigned to the node in a previous submit. This might be displayed on preview or on edit of a previously-submitted node. I don't see any way for you to know at this point what the appropriate value is--or, even if you did know, to put it in. So I'd say, leave it out, with a note in the readme. It can be added in later when we know more.<?php/**
* Retrieve data on all defined element types.
*/
function formbuilder_element_types() {
$types = array();
$basic_defaults = array(
'#description' => NULL,
'#attributes' => array(),
'#required' => FALSE,
'#tree' => FALSE,
'#parents' => array()
);
foreach (module_implements('elements') as $module) {
$elements = module_invoke($module, 'elements');
if (isset($elements) && is_array($elements)) {
$cache = array_merge_recursive($types, $elements);
}
}
if (sizeof($types)) {
foreach ($types as $element_type => $info) {
$cache[$element_type] = array_merge_recursive($basic_defaults, $info);
}
}
return $types;
}
?>
Then you can send the data to the browser as:
<?phpprint drupal_to_js(formbuilder_element_types());
?>
This might also allow you to drop the hard-coded indexes of element types 0 = 'checkbox', etc.), which would be good for extensibility.
function formbuilderThemeElement(type, element) { switch(type) { case 'select': var select = ''; var size = element['#size'] ? ' size="' . element['#size'] . '"' : ''; if (!element['#atrributes']) { element['#attributes'] = []; } element['#attributes']['class'] = formbuilderGetClass(element); return theme('form_element', element['#title'], ''. formbuilerSelectOptions(element) .'', element['#description'], element['#id'], element['#required'], form_get_error($element)); }This would need the additional functions
formbuilderGetClass()(based onform_set_class()),formbuilderAttributes()(based ondrupal_attributes()),formbuilderSelectOptions()(based onform_select_options()).Here's a rough idea of
formbuilderGetClass. We return a class because we can't pass by reference as is done in the Drupal equivalent./*** Sets a form element's class attribute.
*
* Adds 'required' and 'error' classes as needed.
*
* @param element
* The form element.
* @param name
* Array of new class names to be added.
*/
function formbuilderGetClass(element, class) {
if (class == null) {
class = [];
}
if (element['#required']) {
class[class.length] = 'required';
}
if (element['#attributes'] && element['#attributes']['class'])) {
class[class.length] = element['#attributes']['class'];
}
return class.split(' ');
}
A few more suggestions...
var_export()to turn the PHP into a string, then send the string back to the browser.Format?
I'll work on some of the
I'll work on some of the easier points right now and send u a reply in a a day or two. For the others, I'll work on and submit more by this week-end.
problem...
Hi!
I tried to use the _element_info to get the default values for an item as you said. I am getting a problem in the sense that the specifications at the http://api.drupal.org/api/HEAD/file/developer/topics/forms_api_reference... page are different from what is returned.
Value returned by the function for text area:
array ('#description' => NULL,
'#attributes' =>
array (
),
'#required' => false,
'#tree' => false,
'#parents' =>
array (
),
'#input' => true,
'#cols' => 60,
'#rows' => 5,
)
whereas the values defined in reference have following extra : after_build, default_value, prefix,suffix, title, type, weight. Also "input" was returned by the function but it is not there in reference.
As far as I can see only the properties which are common to all the widgets are not there and some "INTERNAL" properties are show. So I'll add these properties through code and do what you asked me to do.