peers , March 08 2009

someone emailed to ask how i wrote data to sobi2 and registration, short of time at the moment to go through the mootools part of the form, but thopefully the sobi2 table quiries and image renaming will help. no way i could have even attempted this without chronoforms or the forum!

instructions for registration where found in download area
i used the form wizard so to make use of chronoforms already written css,
edited the form using dreamweaver (it's a very long dynamic form for what i need), copying the css locally to help
for the categories, used mootools 1.1 (same js version joomla 1.5 and chronoforms uses) to create a dynamic form showing subcategory tick boxes and questions based on parent category tick boxes

image upload was done using Image resizer plugin for chronoforms (brilliant!)
images placed in the /images/sobi2/clients folder, and a js in the onsubmit after email box, used to rename images to the corresponding sobi2 id. (see code below)

put the form html in the form code html box in chronoforms
put the js in the form javascript box
put the db quiries in the onsubmit after email box (see below code)

in chronoforms 3.0
set db connection to no.
general tab.. set form tag attachment as enctype="multipart/form-data"
code used for database writes and image renaming is:

//set variables
$db = & JFactory::getDBO();
$org = JRequest::getVar('org_name', '', 'post', 'string');
$dt = date("Y-m-d")." - ".date("H:i:s");

//create directory entry ready for moderation
$query = "INSERT INTO #__sobi2_item
SET title = ".$db->quote($org).",
    hits = ".$db->quote('0').",
    published = ".$db->quote('1').",
    confirm = ".$db->quote('0').",
    approved = ".$db->quote('1').",
    archived = ".$db->quote('0').",
    publish_up = ".$db->quote('0000-00-00 00:00:00').",
    publish_down = ".$db->quote('0000-00-00 00:00:00').",
    checked_out = ".$db->quote('0').",
    checked_out_time = ".$db->quote('0000-00-00 00:00:00').",
    ordering = ".$db->quote('0').",
    owner = ".$db->quote('0').",
    icon = ".$db->quote('').",
    image = ".$db->quote('').",
    background = ".$db->quote('').",
    ip = ".$db->quote($ipa).",
    last_update = ".$db->quote($dt).",
    updating_user = ".$db->quote('0').",
    updating_ip = ".$db->quote($ipa).",
    metakey = ".$db->quote('').",
    metadesc = ".$db->quote('').";";
$sobi_id=$db->insertid(); //get last row primary index for other related tables

//categories - all category tick boxes are named like name=categories[] - subcategories are hidden on load using mootools js, then the divs are chnaged to block when category tick boxes are checked. when submit button is clicked, a function is called (using onclick) to untick any parent categories ticked which have subcategories ticked (to reduce unceccesary categorys)
$categories = array();
$categories = JRequest::getVar('categories', array(), 'post', 'array');
foreach($categories as $key=>$category) {
$query ="INSERT INTO #__sobi2_cat_items_relations
SET catid = ".$db->quote($key).",
itemid = ".$db->quote($sobi_id).",
       ordering = ".$db->quote('1').";";
$db->query(); }

//all textbox form elements are named txtboxes[key] where key is the sobi2 directory fieldid
$txtboxes = array();
$txtboxes = JRequest::getVar('txtboxes', array(), 'post', 'array');
foreach($txtboxes as $key=>$txtbox) {
$query ="INSERT INTO #__sobi2_fields_data
SET fieldid = ".$db->quote($key).",
data_txt = ".$db->quote($txtbox).",
data_char = ".$db->quote('').",
itemid = ".$db->quote($sobi_id).";";
$db->query(); }

//regions checkbox group
$regions = array();
$regions = JRequest::getVar('regions', array(), 'post', 'array');
foreach($regions as $key=>$region) {
$query ="INSERT INTO #__sobi2_fields_data
SET fieldid = ".$db->quote('46').",
data_txt = ".$db->quote($region).",
data_char = ".$db->quote('').",
itemid = ".$db->quote($sobi_id).";";
$db->query(); }

//contact method checkbox group
$regions = array();
$cntctmthd = JRequest::getVar('cntctmthd', array(), 'post', 'array');
foreach($cntctmthd as $key=>$cmethod) {
$query ="INSERT INTO #__sobi2_fields_data
SET fieldid = ".$db->quote('47').",
data_txt = ".$db->quote($cmethod).",
data_char = ".$db->quote('').",
itemid = ".$db->quote($sobi_id).";";
$db->query(); }

//stages checkbox group
$stages = array();
$stages = JRequest::getVar('stages', array(), 'post', 'array');
foreach($stages as $key=>$stage) {
$query ="INSERT INTO #__sobi2_fields_data
SET fieldid = ".$db->quote('56').",
data_txt = ".$db->quote($stage).",
data_char = ".$db->quote('').",
itemid = ".$db->quote($sobi_id).";";
$db->query(); }

//phases checkbox group
$invphases = array();
$invphases = JRequest::getVar('phases', array(), 'post', 'array');
foreach($invphases as $key=>$phase) {
$query ="INSERT INTO #__sobi2_fields_data
SET fieldid = ".$db->quote('57').",
data_txt = ".$db->quote($phase).",
data_char = ".$db->quote('').",
itemid = ".$db->quote($sobi_id).";";
$db->query(); }

//preferences checkbox group
$indpref = array();
$indpref = JRequest::getVar('pref', array(), 'post', 'array');
foreach($pref as $key=>$ind) {
$query ="INSERT INTO #__sobi2_fields_data
SET fieldid = ".$db->quote('58').",
data_txt = ".$db->quote($ind).",
data_char = ".$db->quote('').",
itemid = ".$db->quote($sobi_id).";";
$db->query(); }

//legal aid radio options
$legalaid = array();
$legalaid = JRequest::getVar('legalaid', array(), 'post', 'array');
foreach($legalaid as $key=>$legala) {
$query ="INSERT INTO #__sobi2_fields_data
SET fieldid = ".$db->quote('67').",
data_txt = ".$db->quote($legala).",
data_char = ".$db->quote('').",
itemid = ".$db->quote($sobi_id).";";
$db->query(); }

//fixed fee interview options
$fixedfee = array();
$fixedfee = JRequest::getVar('fixedfee', array(), 'post', 'array');
foreach($fixedfee as $key=>$fixedf) {
$query ="INSERT INTO #__sobi2_fields_data
SET fieldid = ".$db->quote('68').",
data_txt = ".$db->quote($fixedf).",
data_char = ".$db->quote('').",
itemid = ".$db->quote($sobi_id).";";
$db->query(); }

//fixed_fee interview options
$lexcel = array();
$lexcel = JRequest::getVar('lexcel', array(), 'post', 'array');
foreach($lexcel as $key=>$lex) {
$query ="INSERT INTO #__sobi2_fields_data
SET fieldid = ".$db->quote('74').",
data_txt = ".$db->quote($lex).",
data_char = ".$db->quote('').",
itemid = ".$db->quote($sobi_id).";";
$db->query(); }

//logo and icon image rename - see chronoforms resize_plugin and file_upload settings
$file_path_parts = pathinfo($attachments['logo']);
$basename = $file_path_parts['basename'];
$logo_old_name = big_.$basename;
$icon_old_name = med_.$basename;
$extn = $file_path_parts['extension'];
$extn = strtolower($extn);
$file_folder = JPATH_SITE.DS.'images'.DS.'com_sobi2'.DS.'clients';
$oldlogo = $file_folder.DS.$logo_old_name;
$sobilogo = $sobi_id.'_img.'.$extn;
$newlogo = $file_folder.DS.$sobilogo;
rename($oldlogo, $newlogo);
$oldicon = $file_folder.DS.$icon_old_name;
$sobi_icon = $sobi_id.'_ico.'.$extn;
$newicon = $file_folder.DS.$sobi_icon;
rename($oldicon, $newicon);

//update the table with logo and icon
$query = " UPDATE #__sobi2_item SET image = '$sobilogo', icon = '$sobi_icon' WHERE itemid = '$sobi_id'";


still working on the sobi2 template (some good links at and ) using css instead of sobi2's table based templates!

and also the form validation and commenting i need to go back to. no doubt the php could be shortened, maybe making use of multidimentional arrays like named in the form as name=arrayname[x:y]?


Hi peers,

Thanks very much for a taking the time to write this - very valuable.


PS Made sticky and moved to the showcase forum.

Powered by ChronoForums -

ChronoForms Book

The ChronoForms Book, written for ChronoForms v3 contains 350 pages of invaluable ChronoForms How-tos hints and tips.

Note: many of the ideas can be used in ChronoForms v4 but the admin interface is very different and code examples may need to be modified.


Members Login Inc. (Ohio, USA) is an authorized retailer for
goods and services provided by