Connecting custom form with database

raifs 04 Nov, 2009
Hi,

i've made a custom form with ajax loader and inserted it into form code tab. Because of the ajax loader there are no input fields in "form code" area and I can not auto-generate field names and types.
I turned debug on and it gave me this:

1. Form passed first SPAM check OK
2. Form passed the submissions limit (if enabled) OK
3. Form passed the Image verification (if enabled) OK
4. Form passed the server side validation (if enabled) OK
5. $_POST Array: Array ( [id] => Array ( [1] => 1 [2] => 3 [3] => 7 [67] => 727 [txt_5] => [txt_6] => [txt_66] => 0 [txt_10] => 0 [txt_11] => 0 [txt_7] => 0 [txt_8] => 0 [txt_9] => 0 [txt_65] => 0 [12] => 242 [13] => 247 [14] => 249 [15] => 254 [16] => 263 [17] => 273 [txt_18] => [txt_19] => [txt_20] => [txt_21] => [txt_22] => [txt_23] => [txt_24] => [txt_25] => [txt_26] => [txt_27] => [txt_28] => [txt_29] => [31] => 305 [32] => 310 [33] => 313 [35] => 338 [txt_36] => [34] => 323 [38] => 362 [txt_79] => [txt_80] => [txt_94] => [txt_95] => [39] => 0 [40] => 0 [41] => 0 [42] => 0 [43] => 0 [44] => 0 [45] => 0 [46] => 0 [txt_64] => 0 [txt_92] => 0 ) [valgr] => [min_b] => 300 [max_b] => 450 [min_h] => 350 [max_h] => 1200 [ol_ul_h2] => [etvert1x2] => 1 [etvert1x1] => 1 [ethori1x2] => 1 [ethori1x1] => 1 [submit] => Vaata [beschlag] => 0 [wings] => 0 [vdummy] => on [adummy] => on [min_br] => [max_br] => [min_hr] => [max_hr] => [ralrvkasten_id] => Array ( [82] => ) [ralrvendschiene_id] => Array ( [90] => ) [ralraendschiene_id] => Array ( [104] => ) [rollpreis_tmp] => 0 [glasfaktor] => 1 [ravfaktor] => 1 [products_id] => 1 [iv_tmp] => 0 [iv_val] => 0 [tgr_tmp] => 0 [tgr_val] => 0 [ssv_tmp] => 0 [ssv_val] => 0 [siv_tmp] => 0 [siv_val] => 0 [osv_tmp] => 0 [osv_val] => 0 [spr_tmp] => 0 [res_tmp] => 0 [res_val] => 0 [fap_tmp] => 0 [fap_val] => 0 [bes_tmp] => 0 [bes_val] => 0 [gri_tmp] => 0 [gri_val] => 0 [fbap_tmp] => 0 [fbap_val] => 0 [aus_tmp] => 0 [aus_val] => 0 [rofueschie_ns_tmp] => 0 [rfsn_val] => 0 [rofueschie_as_tmp] => 0 [rfsa_val] => 0 [rkurbel_tmp] => 0 [rmotor_tmp] => 0 [rhoch_tmp] => 0 [rhoch_val] => 0 [rendschiene_tmp] => 0 [resv_val] => 0 [rakurbel_tmp] => 0 [ramotor_tmp] => 0 [rahoch_tmp] => 0 [rahoch_val] => 0 [raendschiene_tmp] => 0 [resa_val] => 0 [rav_h_l_tmp] => 0 [rav_h_r_tmp] => 0 [rav_h_o_tmp] => 0 [rav_h_u_tmp] => 0 [rav_k_l_tmp] => 0 [rav_k_r_tmp] => 0 [rav_k_o_tmp] => 0 [rav_k_u_tmp] => 0 [rav_h_l_val] => 0 [rav_h_r_val] => 0 [rav_h_o_val] => 0 [rav_h_u_val] => 0 [rav_k_l_val] => 0 [rav_k_r_val] => 0 [rav_k_o_val] => 0 [rav_k_u_val] => 0 [validate_ftype] => id[4]27 [preisliste] => [panzerteilung] => 0 [gesamtpreis] => 0 [0350762db04b140fa036a2c45d810a44] => 1 [1cf1] => b0b071c64a0c5f39b3e5167c5fe333e8 [chronoformname] => Proov1000 )
6. $_FILES Array: Array ( )
7. Form passed the plugins step (if enabled) OK
8. Debug End


Hope someone can help me.

I want to put submitted data into database...

Regards,
Raivo
Max_admin 04 Nov, 2009
Hi Raivo,

If you mean that your AJAX loader is causing the form to fail generating the fields names then may be you can add the table fields manually with the same names as your form fields names which you know ? there is a + sign in the table creation screen to let you add more fields to the table!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
raifs 04 Nov, 2009
Thank you for quick answer.

I have field names like name="id[1]", name="id[2]"....name="id[text_1]" etc. How should my database table look like?
Should it be smth like this:
`1` int(11) NOT NULL,
`2` int(11) NOT NULL,
.....
`text_1` int(11) NOT NULL,

or this:
`id[1]` int(11) NOT NULL,
`id[2]` int(11) NOT NULL,
.....
`id[text_1]` int(11) NOT NULL,

I'm thinking that if i get proper database i will get my form's data into this....

Regards,
Raivo
GreyHead 04 Nov, 2009
Hi raivo,

I'm not sure if you can use [] in a MySQL column name - I rather think that you can't but check the MySQL docs.

Do you need to use input names in this form? It's not helpful.

If you do that you could add a loop in the OnSubmit Before box to unpack the id array and write the values back into the $_POST array before saving.

Bob

PS You can pass the field names to ChronoForms to create the table by putting a fake code snippet into the Form HTML like this
<!-- name='name_1' name='name_2' . . .''>
raifs 04 Nov, 2009
Hi GreyHead,

thank you for your answer. I manage to put a php code after sending email that handles inserting values to database.

<?php
$db =& JFactory::getDBO();
$query = "INSERT INTO #__konfigurator (id_1, id_2) VALUES
('".$_POST['id'][1]."', '".$_POST['id'][2]."')";
$db->setQuery($query);
$result = $db->query();
echo "done";
?>

somehow it doesn't put the right values in database. '".$_POST['id'][1]."' - this should be "1" or "2" but it goes to db as "," and '".$_POST['id'][2]."' should be "2" or "3" but it stay blank. Could it be chronoform issue or database version or maybe you can give me some hint on fixing this. In the form there are inputs: <input id="id[1]1" type="radio" checked="checked" value="1" name="id[1]"><input id="id[1]2" type="radio" value="2" name="id[1]">

I'm really in trouble and appreciate any help.

Regards,
Raivo
GreyHead 04 Nov, 2009
Hi Raivo,

There's a quote problem in ('".$_POST['id'][1]."', '".$_POST['id'][2]."')";
use ('".$_POST[id][1]."', '".$_POST[id][2]."')"; instead

I still don't like this solution though - feels messy :-(

Bob
This topic is locked and no more replies can be posted.