I have a number of forms in my site and having got used to chronoforms I would like to use a chronoform rather than designing a form from scratch with all the checking etc that implies.
But I want to use radio buttons for choices and checkboxes for extras. But the number of choices and extras depends on what previous selections have been made. So I want to add radio buttons and add checkboxes 'dynamically' using a php script.
I can see the 'form code' section into which I can 'echo' what I want but will it work???
--
Dave
Hi Bob...Thanks! that was a nice short reply. I can confirm that in principle it works. The snag now is how to get the actual options into the chronoform.
In the script outside the chronoform I have an indexed array $myoptions
Inside the chronoform I can write a 'foreach($myoptions as $anoption){echo a radio button for each option etc}
But how do I get my array $myoptions over the boundary and into the chronoform?
Something to do with 'post' and 'request' but I can find nothing about using POST other than as a form method. I have several books on HTML and on php but only one refers to POST other than as a 'form method' and all that one says is POST can be used independently of the <form> tag. it does not give an example of HOW???
Perhaps I am being dim. Just a one-line answer will do fine.
--
Dave
Thanks Bob,
Very quick reply...but a bit complex for me. In any case I am not wealthy enough to have 'dreamweaver' I have assorted php editors instead.
How abut putting my array into $session and getting it back inside the chronoform? Or is that time-wasting?
--
dave
Hi Dave,
Dreamweaver isn't important, you can do something similar with your preferred PHP/HTML editor.
I can't image why you would want to add the array to the user session. I'm missing the problem here completely :-(
Bob
Hi Bob, Thanks.
No Perhaps it is me that is missing the point.
Depending on what the user has chosen earlier...it might be a hat, or a cat or an umbrella I want to offer him options say 'red' or 'green' or ' or 'blue' or 'male' or 'female' anything from 1 to 10 options. The radio buttons need to be programmed to present the options clearly. The actual name of the options has to therefore appear inside the Chronoform.
I think I see what your system is.
I don't have an 'include' directory in my com_chronocontact directory but of course I can put one there. and having done that I can put the appropriate .php file there, to be included within the Chronoform. But this still leaves me with the problem of getting the $myoptions array into the file to be included. (I suppose via POST and request ??).
I have always expected 'include' files to be static data.
and where does your final "<?php echo implode("/n",$options); ?>" fit into the jigsaw?
Something to save me putting lots of backslashes into the echo statements?
Sorry but I am a bit of a dunce in these matters.
--
dave
Hi Dave,
Getting clearer . . .
To pass information from one form to another where the first form doesn't need any 'on submit processing', set the OnSubmit URL of from 1 to be the URL for Form 2. Then the information you need is available in the $_POST array and can be accessed with the Joomla! JRequest::get methods.
If you need to process form 1 then my preference would be to save the data in a database table (and then recover it in form 2). Alternatively you can use the Joomla JSession methods to save it into the User Session from Form 1 and then recover it in Form 2.
Bob
PS The implode statement just takes the $options array and coverts it into a string for use in the Form HTML.
Of Course, Thanks,
I had only just dragged the 'options' out of the database based upon the original choice ID.
Leave the getting of options until inside the Chronoform!
That still leaves it necessary to pass the choice id into the other form but that is not so daunting, because that choice was itself settled by a form so would be there in POST.
Thanks will try it on that basis.
--
Dave
Hi Bob,
Thanks again. I have now got it working.
The 'implode("\n",$options); bit did not work...It produced the options in a line. In other words the \n did not come out as a newline.
I had to echo the lines one by one from the 'foreach' statement with a <br /> after each. And I had to produce exactly the <input value line in the exact form that Max has it. But it is now fine.
I do not yet understand the use of curly braces in HTML and cannot find much about them.
Anyway thanks fro your help without which I would never have got it working.
--
Dave
p.s I wrote a reply like this before but I think I clicked 'save' instead of 'Submit' but I cannot find it now!
Hi Dave,
The "\n" has to be exactly like that; single quotes and /n will not work. You can also use and empty string "" but the resulting HTML has a long single line of options.
The {$xxx} syntax works inside a double-quoted string and is the equivalent of ".$xxx." I prefer it because it keeps the code cleaner e.g. value='{$xxx}' instead of value='".$xxx."'
Note: using single quotes round a value is OK as long as the values don't include single quotes themselves.
Bob