Load a form under certain conditions

AntonioGraca 17 Mar, 2013
Hello
I need to load a form under certain conditions. If user dont have records in table, then load "admin_parametros_locais" form. If user have records i table, do nothing.
I tested some others solutions and this seemed the most ideal.
But the problem is loading a specific form... The query seems ok.

On Load I put a custom code with the following code:

<?php
$user =& JFactory::getUser();
$user_id = $user->id;

$query_locais = "SELECT COUNT(*)
FROM  `apo_chronoforms_data_parametros_registo_locais_treino_pistas` 
WHERE  `cf_user_id`=$user_id";

if (empty($query_competicoes)){
$formname = 'admin_parametros_locais';
$MyForm =& CFChronoForm::getInstance($formname);
$MyForm->showForm($formname);
}
?>


But the code gives error in line lode $MyForm->showForm($formname);. For a whole day I tried other solutions ... Nothing . Someone help me understand what is wrong with this code ?

Thanks

António Graça
GreyHead 17 Mar, 2013
Hi António,

You have to include the code to execute the query - without that it does nothing :-(
<?php
$user =& JFactory::getUser();
$user_id = $user->id;
$db =& JFactory::getDBO();
$query_locais = "
  SELECT COUNT(*)
    FROM `#__chronoforms_data_parametros_registo_locais_treino_pistas`
    WHERE `cf_user_id`=$user_id";
";
$db->setQuery($query);
$count = $db->loadResult();
. . .
?>

I'd include this code in the form On Load event and then redirect the user (or show a different form page) if $count > 0

Bob
AntonioGraca 18 Mar, 2013
Hello Max
Thanks, for your contribution. Now the code of the query is more correct. But the big problem is: how to show a specific form through the custom code?
I've tried several examples found on the forum and do not work. Give error Line 16 ($MyForm->showForm($formname);).

My code:
<?php
$user =& JFactory::getUser();
$user_id = $user->id;
$db =& JFactory::getDBO();
$query_locais = "
  SELECT COUNT(*)
    FROM `#__chronoforms_data_parametros_registo_locais_treino_pistas`
    WHERE `cf_user_id`=$user_id";
$db->setQuery($query_locais);
$count = $db->loadResult();

if (empty($count)){
$formname = 'admin_parametros_locais';
$MyForm =& CFChronoForm::getInstance($formname);
$MyForm->showForm($formname);
}
?>


Once more, thanks

António Graça
GreyHead 18 Mar, 2013
Hi António,

Err, this is Bob here.

I don't know, I would just use the Event Switcher [GH] action plus the Show Form action.

Bob
AntonioGraca 18 Mar, 2013
Oh, God....😲
Hi, Bob, Sorry about name 😶

I'm building an application for the registration of training and competitions (athletics) only to registered users. For this application to work well, should be introduced some records to user choice of local competitions, athletes , etc. The idea is when the user logs, the "system " can understand (by hidden way) if the user have or not records in the table (for example, local of competition). If the user already have records in the table then nothing happens, the application run normally. But if user still not have records in table, will be automatically loaded a form inviting the user to enter data relevant to the application running. For this reason I did not use the Event Switcher [GH] action. I think the best way is what I'm trying to follow. A routine that checks whether the user have records in the table: If Yes, anything happens; If Not, will load a form to user fill. If he wants to use the application and does not have records in tables that have important data to the application running , no choice has to fill out the form to proceed.
I think, the Event Switcher [GH] only work choosing an option. Therefore, I think Event Switcher [GH] not be indicated for my question. Do you agree with me?

The query is ok, but I can not load a form inside the If in Custom code 😢

Thanks and again sorry for the name switch

Thanks
António Graça
AntonioGraca 18 Mar, 2013
Hi, again

I trying use If Then Else [ST] with no results....

PS: two days ago I've been running searching of the solution, but the solution seems to be in shape and I can not catch ...

Thanks
GreyHead 18 Mar, 2013
Hi António,

I think, the Event Switcher [GH] only work choosing an option. Therefore, I think Event Switcher [GH] not be indicated for my question. Do you agree with me?


No, I don't agree with you :-(

I'd use either this or the very similar 'If then Else' action.

Bob
AntonioGraca 18 Mar, 2013
Hi, Bob

I have used the Event Switcher [GH] in another function and resulted 100%. Explored and it seemed to me that was not what I needed for this issue. Or maybe I do not know how to use in this situation. But I'll try to better exploit, maybe the answer is here .... 😑

Thanks BOB

António Graça
GreyHead 18 Mar, 2013
Hi António,

They are both 'conditional' actions that let you set up almost any combination of events to be run depending on the conditions. To redirect you can either use the Show Form or ReDirect User actions.

Bob
AntonioGraca 19 Mar, 2013
Hello Bob.

You were right. I found the quick solution in Event Switcher [GH], and very easy. My mistake was thinking that the Event Switcher [GH] only worked with the switch ()... case ... But luckily that works with other control and condictional structures. It's Done, but now there is a problem. Form does not work when loaded for the show form event within the Event Switcher [GH].
The form is a routine (via code) to write to the table database several records, once. When not in the control structure Event Switcher [GH], works fine, writes the records in the table database, but when the form is loaded (through show form event) inside the Event Switcher [GH] no longer writes, does nothing.

I need to check how 6 tables; I use 2 Event Switcher [GH] within each I have the code to check whether the user has records in the table database. Within each option of Event Switcher [GH] I have the show form event (which loads the form if the user has no data in the table), the form have code to write multiple records to the table.
The code Event Switcher [GH], to identify if the user has records, works correctly;
The code for the form write multiple records, if not called through the Event Switcher [GH], works correctly.
What I missed? :?

Thanks

António Graça
GreyHead 19 Mar, 2013
Hi António,

I'm finding it hard to understand what you are doing here. Please take a Form Backup using the icon in the Forms Manager and post it here (as a zipped file) or PM or email it to me and I'll take a closer look (I know it won't work without the tables but I can see the structure).

Bob
AntonioGraca 19 Mar, 2013
Hi, Bob
The form admin_parametros will check whether the user has records in the database. If existing records, nothing happens. But if not existing records, then will load a form to user add the records (in multiple way)in database tables.
Everything works fine in isolation way, the code to add new records works fine. But when the form is loaded through the Event Switcher [GH],the code to add records in the database table no longer works ...


Thanks

António Graça
GreyHead 19 Mar, 2013
Hi António,

But when the form is loaded through the Event Switcher [GH] the code to add records in the database table no longer works ...


I don't know of any reason for that. As far as I know there is absolutely no connection between loading the form from the Event Switcher, or from the On Load event, or directly from a URL - unless there are particular parameters in the URL that you use in the form.

What do you see in the Debugger for the second form?

Bob

PS I do see a Show Stopper after the first Event Switcher in the admin_parametros form that will stop the second Event Switcher from running.
AntonioGraca 20 Mar, 2013
Hello, Bob
Thanks for your response and for being available to help others ...
I think I know what the problem is, but do not know how to solve.

Form 1nd = Tester to load the 2nd form through the Event Switcher [GH]
Form 2nd = If is loaded, add multiple records to table

When I load the 2nd form through the menu, everything works fine (checks if the captcha is correct, add the new record to the table and makes debug). But if loaded through the 1st form (through Event Switcher [GH]) nothing works (detects if the field is empty, but does not check if the captcha is correct, do not writes new records and does not make the debug).

I think that is the submit button, not works fine when the form is called through the Event Switcher [GH], it can be a bug?

The result of debug when 2and form is load by Event Switcher [GH]: nothing appear
The result of debug when 2and form is load by menu:
Array
(
    [chronoform] => admin_parametros_locais
    [event] => submit
    [format] => html
    [Itemid] => 1089
    [option] => com_chronoforms
    [view] => form
    [locais_select1] => EM da Maia
    [locais_select2] => Est. Universitário (Lx)
    [locais_select3] => Expocentro (pc)
    [locais_select4] => Est. Universitário (Aveiro)
    [locais_select5] => EM de Faro
    [locais_select6] => EM de Elvas
    [locais_select7] => EM de Guimarães
    [locais_select8] => Centro Estágios do Luso
    [locais_select9] => Outro estádio
    [locais_select10] => Outro estádio
    [chrono_security_answer] => 
    [input_submit_214] =>   Registar Parâmetros Locais  
    [c9413d2c0698e908388a1baee2147201] => 1
)
Validation Errors: 

Array
(
)
Debug Data
1.	Core Captcha
1.	Passed the answer check!
Debug Data
1.	Core Captcha
1.	Passed the answer check!


Another issue, that is not very important, when the 2nd form is loaded by Event Switcher [GH] changes the space between the boxes. I send PrtScreen of two situations.

thank you

António Graça
AntonioGraca 20 Mar, 2013
Hi, Bob

I tested loading the 1st form through the menu and the 2nd form now works even when loaded via the Event Switcher [GH].

So, the question has to do with how the 1st form is called. I load the 1st form admin_parametros on the front page, via {chronoforms}admin_parametros{/chronoforms}.

- When loaded through the menu, everything works;
- When loaded in an article called through {chronoforms}admin_parametros{/chronoforms} submit the 2nd form no longer works ...

Some light on the subject?

Thanks again

António Graça
GreyHead 20 Mar, 2013
Hi António,

It may be a problem with the URL used to call the form if the problem arises when it is from the plugin. Please try setting the Relative URL for the form with the Event Switchers to NO. The setting is on the form General tab.

Bob
AntonioGraca 22 Mar, 2013
Hi, Bob
I apologize for just now give you a feedback on the proposed solution to the form does not save the records (through code Custom Code), when the form was called by Event Switcher [GH]. In fact, the proposal was the beginning of the solution. Besides placing Relative URL to the form to NO loaded by Event Switcher [GH], also had to put in all the forms that were called by Event Switcher [GH] for the problem to be solved.
But, then the form will not return to the site they should. Solution: Code and Redirect User.
Solved!
Thank You!!!
But you did not come to give some idea of ​​the problem exposed in the pictures I sent; the spaces between the fields were in different forms that was called from the Event Switcher [GH]. When we force the error in the Captcha and makes Event Loop then stay with the correct spaces.

Any idea?

António Graça
AntonioGraca 05 Apr, 2013
Hi, Bob

Please, it has news about this issue?

when the 2nd form is loaded by Event Switcher [GH] changes the space between the boxes.



But you did not come to give some idea of ​​the problem exposed in the pictures I sent; the spaces between the fields were in different forms that was called from the Event Switcher [GH]. When we force the error in the Captcha and makes Event Loop then stay with the correct spaces.



Thanks

António Graça
GreyHead 06 Apr, 2013
Hi António,

There is no news because I have no idea why there should be any difference. Presumably one form is loading with the frontforms.css and the other with frontforms_tight.css. What do you see when you check to see which CSS files are being loaded?

Bob
AntonioGraca 07 Apr, 2013
Hello, Bob

In fact, when the form is loaded via the Event Switcher [GH] loads the file frontforms_tight.css and also the frontforms.css.
When I force the captcha error, to the form reloaded, or when I load the form directly from the menu, only the file frontforms_tight.css is loaded.
The problem seems to be the padding value in .ccms_form_element...

Any idea? :?


Thanks

António Graça
GreyHead 10 Apr, 2013
Hi António,

I can see what is happening there. But there is nothing in the Event Switcher that would affect which files are loaded :-( That is all handled by the Show HTML action.

I wonder, is there another form on the page that is using the the other CSS file?

Bob
AntonioGraca 16 Apr, 2013
Hello, Bob
I canot see other form on the page that using the the other CSS file... :?
Only I have 2 modules in same page, not forms.

Thanks, bob.

António Graça
GreyHead 22 Apr, 2013
Hi António,

Please post a link to the form so I can take a quick look.

Bob



Bob
AntonioGraca 04 May, 2013
Hi, Bob
I send you a PM with the pass and user to access to my site.


Thanks
GreyHead 06 May, 2013
Hi António,

I don't see a PM from you in my inbox?

Bob
AntonioGraca 07 May, 2013
Hi, Bob
In my box the PM sent, I have two copy of PM sent to you...


Thanks...
GreyHead 08 May, 2013
Hi António,

I got the second one thank you. I've looked at the form and can see that the CSS file being loaded changes. But there is nothing in the Event Switcher [GH] code that makes any changes in the file loading.

Which Show HTML action are you using?

Bob
AntonioGraca 08 May, 2013
Hello, Bob
Thanks again for your (ever big) help.

I using the native Show Html... Show html (0)


Thanks
AntonioGraca 08 May, 2013
General configuration of Show Html
Yes
Yes
Yes
No
Yes
GreyHead 08 May, 2013
Hi Antonio,

That all looks good. The code in the Show HTML action that handles the CSS loading is very simple
			if((bool)$form->form_params->get('tight_layout', 0) === false){
				$document->addStyleSheet($uri->root().'components/com_chronoforms/css/frontforms.css');
			}else{
				$document->addStyleSheet($uri->root().'components/com_chronoforms/css/frontforms_tight.css');
			}

I still have no idea why it changes :-(

Please take a Form Backup using the icon in the Forms Manager and post it here (as a zipped file) or PM or email it to me and I'll take a closer look and see if I can replicate the problem on a test site.

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