SOBI2 Entry / CB reg

peers 03 Feb, 2009
Hi,

I've made a really nice js dynamic form for site registration via dreamweaver chronoforms and CB. (It's taken weeks as im new to javascript and mootools) Some of it uses 'usable forms script' as recommended in chronoform FAQS, some of it uses mootools. Works great if I want it just to register to CB.

I want the form to do two things in one go.. use chronoforms CB register plugin, AND submit a new entry to SOBI2 Directory for moderation! :/

Is it possible to have a form write results directly to the SOBI database to create a new SOBI2 entry? I think it'd need to write to two tables.
Do you think it'd work to make a custom SOBI2 entry template and drop it into chronoforms so it could then do the CB registration part aswell?

My brain is fried! Any ideas, help or pointers would be great!

Many thanks

Richard
GreyHead 03 Feb, 2009
Hi Richard,

I'm sure that it's possible!

I'd probably run the OnSubmit After code after the AutoGenerated code database save and build the SOBI2 queries there.

Bob
peers 03 Feb, 2009
Hi Bob. Thank you for a such quick reply! Part of me was hoping you'd say that wasn't possibleπŸ™‚ This is going to get very complicated. Absolutely no chance of me having got this far without chronoforms! Fantastic!

If I where to
1.)change the RunOrder, leaving Plugins to run first as default, and change Autogenerated block to run 2nd instead of 3rd, and the OnSubmit block to run 3rd
2.)connect to the relevant SOBI2 tables using DB Connection tab
3.) make sure form object names in my form are exactly the same as SOBI2 field names, and have hidden fields with static values for SOBI's backend stuff like 'aproved' 'published'
4.) add something similar to below in - Form Code / (On Submit code - after sending email:)

$sql="INSERT INTO jos_sobi2_fields_data (field1, fielfd2, field3)
VALUES
('$_POST[field1]','$_POST[field2]','$_POST[field3]')";

If I can just post an entry to SOBI, they're all to be moderated before publish anyway. here goes another month of being up all night lol.

Am I going in the right direction?

Many thanks

Richard
GreyHead 03 Feb, 2009
Hi Richard,

I'd do something like you've listed in Option 4 there but I'd probably use the SET syntax (which I prefer) to get round the field nameing problem
<?php
$db =& JFactory::getDBO();
$post['fielda'] = JRequest::getVar('fielda', '', 'post', 'string');
. . .
$query = "
  INSERT 
    INTO `#__sobi2_fields_data`
    SET `field1` = ".$db->quote($post['fielda']).",
     `field2` = ".$db->quote($post['fieldb']).",
      . . . ;";
$db->setQuery($query);
$db->query();
?>
Using JRequest allows you to use the Joomla data vetting to add some security and teh SET syntax makes the equivalences clearer and allows you to change fields around without having to juggle too much.

Bob
peers 11 Feb, 2009
Bob,

Thank you very much for your help. I'm hoping you could once again point me in the right direction..

When I write new records to the SOBI2 tables, one of the tables is something like 'items'. it has an auto incrimenting PRIMARY_KEY called item_id. so i should write a new record to that table with each form submition, as above.

other tables are related to the item_id, when i come to write rows to those tables using a variable, how can i call the item_id for the variable? is that the usual way?

ive got 100 check boxes to process, each check box being a categoy, and when form's submitted each ticked box would be a new row in one of the SOBI2 tables 'category_relations' that relates category ID's to item_id's
would you be able to point me in the right direction for creating a new row for each check box that is checked? There has to be a way to simplify this for the sheer volume of check boxes. (although it is dynamic front end using mootools, so the user will only see a small number of them)

Many thanks,

Richard
Max_admin 11 Feb, 2009
Hi Richard,

If I understand you correctly then you can name all the checkboxes as : somename[] , then you will get the result of them as an array, loop through it and create records!

regarding the item_id issue, you can get the last insert id some how, its posted here in the forums a while ago!


Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
peers 14 Feb, 2009
thanks again for the help.
I can't for the life of me understand why, but it seems top be creating two rows in the table. the first row is NULL the whole way, the second is as it should be. ive looked round everywhere, and come back to it a number of times, any ideas?

<?php
$db =& JFactory::getDBO();
$post['org_name'] = JRequest::getVar('org_name', '', 'post', 'string');
$query = "
  INSERT 
    INTO `#__sobi2_item`
    SET `title` = ".$db->quote($post['org_name']).",
	    `hits` = ".$db->Quote('0').",
		`published` = ".$db->Quote('0').",
     	`confirm` = ".$db->Quote('0').",
		`approved` = ".$db->Quote('0').",
		`archived` = ".$db->Quote('0').",
		`publish_up` = ".$db->Quote($post['recordtime']).",
		`publish_down` = ".$db->Quote('0000-00-00 00:00:00').",
		`checked_out` = ".$db->Quote('0').",
		`ordering` = ".$db->Quote('0').",
		`background` = ".$db->Quote('').",
		`ip` = ".$db->Quote($post['ipaddress']).",
		`updating_ip` = ".$db->Quote($post['ipaddress']).";";
$db->setQuery($query);
$db->query();
$sobi_id=$db->insertid();
?>


does the insertid() usage look right? the next table i write to doesnt pick up that value and defaults to 0
GreyHead 15 Feb, 2009
Hi peers,

That code looks OK to me and I just checked the insertid() docs and that looks good.

It looks to me as though the query is being executed twice . . . what code follows this when you say that the insertid isn't being picked up?

Bob
peers 15 Feb, 2009
Ive stripped it right down to this, no code follows. might not be worth trying to fix the lastip issue as it's still posting 2 rows. ive checked the whole form setup, just can't understand it. been up all night trying to figure it out. The second line is OK but why the qwerty would it post the damn thing twice?

<?php
$db = & JFactory::getDBO();
$post['org_name'] = JRequest::getVar('org_name', '', 'post', 'string');
$sql = "
  INSERT 
    INTO `#__sobi2_item`
    SET `title` = ".$db->quote($post['org_name']).";";
$db->setQuery($sql);
$db->query();
?>
GreyHead 15 Feb, 2009
Hi peers,

No suggestions from what I've seen here :-(
[sendfb][/sendfb]
Bob
peers 15 Feb, 2009
Hi Bob

I emailed the backed up form, any help would be a life saver. Is there anything obvious you can see why it would post the row twice, 1st time all NULL, second row as it should be?

peers
GreyHead 15 Feb, 2009
Hi peers,

The bad news and the good news is that it works perfectly for me :-( :-)

I changed only a few small things:[list]
  • removed the redirect url
  • added an echo of the sql
  • turned debug on
  • created an empty table for the output
  • [/list]

    The sql is only echoed once and there's only one record in the database table.

    Is it possible that the redirect is re-loading the page somehow . . . seems unlikley.

    Bob
    peers 15 Feb, 2009
    removed sobi2 and tables and reinstalled with new tables to see if it was an issue with the table, but that didnt work 😟
    thanks for checking over the settings, it works when i create a table also - might be on to something here - when i remove below code, the second line doesn't post, as expected, and the first line still posts all NULLs. lightbulb
    
    $db->setQuery($query); 
    $db->query();
    


    also, if i completely remove all the php from the onsubmit after email box, it still posts a row of all NULLs πŸ˜‘

    do all table columns have to be part of an array used in the autogen code? looking back at your earlier post, where they where all in $post[] array, is this required? would they have to be added to the array before the query? would the vars in the autogen code block - ipaddress cf_user_id etc have to have their own hidden form elements? please help :?
    GreyHead 16 Feb, 2009
    Hi peers,

    Try adding a line to clear the query
    . . .
    $db->setQuery($query);
    unset($query);
    $db->query();
    I'm wondering if the variable isn't somehow being carried into another database query later on.

    You could also test putting the OnSubmit After code *after* the AutoGenerated code using RunOrder tab.

    I don't properly understand your question about all table columns being needed in the AutoGenerated code - can you give me an example?

    In ChronoForms 3.0 Max has used the Joomla $bind() method to associate the $_REQUEST array with an array of column names retrieved from an sql 'SHOW FIELDS' query on the table. Using that approach everything to be saved has to be in the $_REQUEST array - hence the setVar()s used to add the IP address, etc.

    Bob
    peers 16 Feb, 2009
    already have the run order as plugins autogenerated block onsubmit block and my php is in the 'after email block' does that sound right?

    autogen block seems to post a complete row of nulls regardless of whats in the onsubmit block, if nothing is in the onsubmit block it still does. only use the autogenerated code to connect to the tables i assume, but does autogen block post a row?

    i assume not many people connect to tables that arnt created using chronoforms, as those tables have columns for each of the variables in the autogenerated block. do those variables have to have same table columns eg cf_user_id ? (it seems unwise to edit SOBI2 tables)

    the autogenerate block seems to post a row (should it?), is there anything to consider if completely removing the autogenerated code block by unsetting 'database connection' and manually connecting in the onsubmit code? would likely be just a couple of lines of code. any ideas?
    Max_admin 16 Feb, 2009
    Hi peers,

    when the form is submitted, all the submitted variables are available for the plugins, auto generated, onsubmit code, unless you did some redirect at one step of them!

    the auto generated simply uses a virtual class to bind the data posted to the table you selected and stores a new row, a new row will be stored ANYWAY if the auto generated code run, for the correct data to get stored, you must have posted fields names = the tables columns names!

    Regards,
    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    peers 17 Feb, 2009
    thanks guys, you have been really helpfull. πŸ˜€ these forums are a great resource for chronoforms
    unticked connect to database so autogen doesnt run, changed runorder back to default and following code posted a row with correct data..
    
    <?php
    $db = & JFactory::getDBO();
    $post['org_n'] = JRequest::getVar('org_name', '', 'post', 'string');
    $query = "
      INSERT 
        INTO `#__sobi2_item`
        SET `title` = ".$db->quote($post['org_n']).";";
    $db->setQuery($query);
    $db->query();
    
    Max_admin 18 Feb, 2009
    great, glad you got it working now!πŸ™‚

    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    This topic is locked and no more replies can be posted.