Multipage, validation and choices

V@lentine 16 Apr, 2013
Hello,

I've just built my first multipage form with CF : trop bien !!
Now I have a question to which I found no answer on the forum and FAQ.

I'm adding online registration to our training courses. People register either individually or through their employer.

For the moment I did like this :
Page 1 : data about the candidate -> Page 2 : data about the employer -> Page 3 : who will pay
On each page I have required fields.

But if the candidate comes by himself, he won't fill data about his employer, but as some data is required on Page 2, he can't process to the end.

2 issues possible :
1) How can I add 2 submit events (buttons) on Page 1 : one leading to Page 2 and one leading to Page 3
or
2) How can I "tell" CF that if the candidate has no employer the fields on Page 2 are no more required.

I think issue 1 is the most logical.


Thanks for advice
GreyHead 16 Apr, 2013
Hi V@lentine,

There are probably several ways of doing this but I'd probably set it up with two submit buttons on page one (or use a checkbox). Then in the On Submit code for that page, after the security and validation checks I'd use an Event Switcher to check if this is a Candidate or Employer and link this to different Show Form actions.

Bob

PS An alternative approach that is sometimes easier is to use two completely different forms or groupd of forms, one for the Candidate and the other for the Employer.
V@lentine 16 Apr, 2013
OK, I'll try this.

I have another question, juste wondering if I'm doing right...
I have custom code with php in my form (eg. a dropdown list filling years of birth calculated with current year).
So I'm switching from wizzard mode to edit the events, and after each change I have to click on the form's name to paste my custom code again.
Is there a way to avoid that ? I mean is there an event I should add to paste my code in the wizzard directly ?
(Just to save time)

And lastly : how can I tell CF to submit my form to a file (I knew how to in CF3) ?

PS An alternative approach that is sometimes easier is to use two completely different forms or groupd of forms, one for the Candidate and the other for the Employer.


Sure but I'm lazy, I don't want to dupplicate and update 2 forms😉
V@lentine 16 Apr, 2013
I did as you adviced (or I think I did) and read this http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&p=259856 + other posts :
I added a second submit button to my first page.
I added an Event Switcher [GH] with this code :
<?php
if isset($form->data['input_submit_2']) return 'event_a';
if isset($form->data['input_submit_3']) return 'event_b';
?>

Event A : Show Form "redirect to form" [MyForm] Form Event : Page 2
Event B : Show Form "redirect to form" [MyForm] Form Event : Page 3

but in both case I get to Page 2..

[attachment=0]events.jpg[/attachment]

Thanks, I have many questions today🙂
V@lentine 18 Apr, 2013
Sometimes a day off is good advice ! I found an issue without using event switcher :
I'm just testing which submit button has been used on page one to replace 'required' with '' :
<?php $required=isset($_POST["input_submit_2"])?'required':''; ?>
(...)
  <input maxlength="150" size="30" class=" validate['<?php echo $required;?>','digit']" title="" type="text" value="" name="cp_ent" />



Now if you should have a clue for this, your answer will be welcomed :😉
I have custom code with php in my form (eg. a dropdown list filling years of birth calculated with current year).
So I'm switching from wizzard mode to edit the events, and after each change I have to click on the form's name to paste my custom code again.
Is there a way to avoid that ? I mean is there an event I should add to paste my code in the wizzard directly ?
(Just to save time)

And lastly : how can I tell CF to submit my form to a file (I knew how to in CF3) ?
GreyHead 18 Apr, 2013
Hi V@lentine,

In your first post I suspect that the problem is that you are using just isset(), The value may well be set but not have a value; you need to check specifically for the value. In this case I'd give both submit buttons the same name but different values.

Please see this FAQ for adding Custom HTML; for PHP, if it's simple I add it to the Custom Element element; if it's more complex I'd use a Custom Code action.

In general I try to avoid using the Custom Code tab.

Bob
V@lentine 22 Apr, 2013
Dear GreyHead,

I'm sorry to bother you again, but I just don't manage to do without putting my code in the custom code tab.
No matter, that's not the problem. My form works until I try to reach page 3.
I've changed the test as you righlyt suggested, replacing "isset" with a test on, value, and that's OK. The fields are required as I wanted depending on the button selected.

Now when I submit page 2 I get an error message :
"Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 42260278 bytes) in C:\wamp\www\serfa\components\com_chronoforms\libraries\chronoform.php on line 385"
I've tried to remake my form from the start... Still can't deal with it !

I would like to submit the data to a php file in order to generate a pdf document. I can't find the event to do that.

Well before I just out of my window I'd like to submit my data...
GreyHead 22 Apr, 2013
Hi V@lentine,

I can't tell much from the info here. A 'memory exhausted' error is often the result of a loop so my guess would be that your Event Loop action points back to the same On Submit event.

Bob
V@lentine 23 Apr, 2013
I've removed the captcha and the events linked to it, and still get the same error...


You didn't reply to my other question, how can I submit to a php file ?
I'm looking for this :
[attachment=0]submit.jpg[/attachment]
GreyHead 23 Apr, 2013
Hi V@lentine,

A loop is still the most likely explanation for a Memory Exhausted error.

There's now a ReDirect User action (and a ReDirect URL action if you need to set the URL dynamically).

The Submit URL box is on the form General tab, but I don't think you need that.

Bob
V@lentine 24 Apr, 2013
Hello Bob,

I finally managed to get rid of the error, I re-did my form, making more backup copies than ever... but I have't put the captcha on for the moment. I'll try again later.

I also managed to do what I was asked, thanks to Custom Code : I save my data to a DB table (manually because DB Save sent me some errors and because I wanted to do some operations on the data before saving) and then I display a link to my php file so that the user can download and print his subscribing form (created on the fly with FPDF).

Now I have to do the same for diplomas (the document on the end is different) and do some coding on the intranet application (with CF3) to get back the data from this form !

I wanted to thank you for tour patience and kind support.
All this should be soon online (if we manage to have everybody agree on the design !), normally next month !

Best regards,

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