FormBuilder submission to ListItExtended

As many of you might have been wondering what is going on with FormBuilder and FormBrowser, here is the thing:

FormBuilder is maintained at some level (lately with almost nothing has been done), fighting against time to continue with new line of form tool.

FormBrowser development has been stopped, due i jumped into ListItExtended team and started developing it. This means that FormBrowser might work, but there is no further plans to keep that project alive.

So, i am giving you option to save data into ListItExtended module instead of FromBrowser, cause these two are basically the same.

Let's take a tour and see how it is done...

text-logo.jpg

Requirements:

  • FormBuilder -module
  • ListItExtended -module
  • User Defined Tag

FormBuilder:

Create form with fields you want to be saved to ListItExtended instance:

Give unique alias to all those fields you want to save to ListItExtended instance.

Use " *Call A User Defined Tag With the Form Results" disposition field and select UDT that we will create shortly:

ListItExtended:

Create instance with ListItExtended mother module. Let's call it "ListIt2Competition". Create fields to this instance and make sure that each field has same alias that your previously created FormBuilder fields had.

User Defined Tag:

Now we are almost set. Let's create UDT that actually handles this submission, calling it: "save_fb2li"

Code:

/**
 * Load wanted ListItExtended instance, where you wan't to save items.
 * If instance can't be loaded, it will silently return.
 */
$mod = cmsms()->GetModuleInstance('ListIt2Competition');
if(!is_object($mod))
    return;

/**
 * Intitate item with identifier 'alias', $params['email'] comes from FormBuilder.
 * Do duplication check with 'item_id', silently return, if item already in database.
 */    
$alias = munge_string_to_url($params['email'], true);
$obj = $mod->LoadItemByIdentifier('alias', $alias);

if($obj->item_id > 0)
    return;

/**
 * Fill previously initiated ListIt2Item object with values from form submission.
 * NOTICE: All params that are not known by ListIt2Item object are going to ignored.
 */        
$obj->title = $params['email'];
$obj->alias = $alias;

foreach($params as $key => $value) {

    if(isset($obj->fielddefs[$key]))
        $obj->$key = $value;
}

/**
 * Save this object to database by using ListItExtended API.
 */        
$mod->SaveItem($obj);

This UDT will grab correct instance, attempt to load item based on it's alias, and if alias was not found, it will loop trough parameters that FormBuilder just sent. After object is filled we use ListItExtend API to save complete object.

If you want to skip duplication check, then use following code:

/**
 * Load wanted ListItExtended instance, where you wan't to save items.
 * If instance can't be loaded, it will silently return.
 */
$mod = cmsms()->GetModuleInstance('ListIt2Competition');
if(!is_object($mod))
    return;

/**
 * Intitate empty item using API.
 */    
$obj = $mod->InitiateItem();
/**
 * Fill previously initiated ListIt2Item object with values from form submission.
 * NOTICE: All params that are not known by ListIt2Item object are going to ignored.
 */        
$obj->title = $params['email'];

foreach($params as $key => $value) {
    if(isset($obj->fielddefs[$key]))
        $obj->$key = $value;
}

/**
 * Save this object to database by using ListItExtended API.
 */        
$mod->SaveItem($obj);

If you followed all instructions, you should have completely working system that saves form results to database.

NOTICE: These UDT's are usable with ListItExtended 1.4-beta1 and above. I am finally happy with our API, so i doubt that part of it will change any time soon.

We just used this method, not that long ago, to create this competition for bike brand in Finland.

If you want to check it out: http://www.nopsa.fi
Actual competition: http://www.nopsa.fi/kilpailu

Design by: http://www.ich-mach-das.at/
Coding by: http://www.orange-media.fi/

I hope this article was educational and useful. If you have further questions, please feel free to add comments or contact me in irc: stikki@irc.freenode.net

Enjoy.

Arvixe Hosting

Comments