Page 1 of 2
[SOLVED] CGCalendar, link sets some text into form field?
Posted: Fri Feb 28, 2014 4:48 pm
by thomahawk
I have some events set in CGCalendar. The detail infos show a link button to a FormBuilder Form for peoples to register for that event. Now, I would like the event title and date to be put automatically into a textfield on that form. (Instead of having the user memorize this info and write it in).
Is that possible?
Thanks for any input
Thom
Re: CGCalendar, link sets some text into form field?
Posted: Fri Feb 28, 2014 5:05 pm
by JohnnyB
Here's one approach that might work well.
Use the Smarty {assign} to set the event date and title into a variable, inside of your event detail template.
Then, write query strings in the link to the contact form, for example, the link might look like this in your detail template:
http://your-domain.com/registration?eve ... $EventDate}
Then, using Smarty or JS/jQuery, you can use a $_GET to retrieve the query string values and populate the form fields.
For example,
{$smarty.get.event} will return the value set by {$EventName} from the URL. ...and, {$smarty.get.date}....
So, you can do this in the Formbuilder template, but you can also use the Formbuilder's feature to set params that will fill in automatically when the form loads. Use something like this for the Formbuilder tag that is placed in your page/template:
{FormBuilder form='Your-Registration-Form' value_fld10=$smarty.get.event value_fld11=$smarty.get.date}
Where value_fld10 is the field's ID number assigned by formbuilder.
Re: CGCalendar, link sets some text into form field?
Posted: Fri Feb 28, 2014 9:37 pm
by thomahawk
Hi JohnnyB
Thank you for your great post. What still makes me unsure: Why is it necessary to put those strings into a link?
After I set data into a variable in CGCalendar template, can't I go to any other page or form that has that variable in there? This should make the stored data show up on that place, shouldn't it?
Thanks
Thom
Re: CGCalendar, link sets some text into form field?
Posted: Fri Feb 28, 2014 9:55 pm
by JohnnyB
Why is it necessary to put those strings into a link?
It isn't necessary if you use the Formbuilder tag that preloads field vals like the example I gave.
It would only be needed if you wanted to access the data via query strings directly in the formbuilder template using the {$smarty.get.querystringname} method.
Re: CGCalendar, link sets some text into form field?
Posted: Sat Mar 01, 2014 12:18 pm
by velden
I think another approach would be to use CGSimpleSmarty module. It has the {module_action_link}
Help is available from Extensions -> Modules -> help link behind the module name.
It can be a very useful tag.
Re: CGCalendar, link sets some text into form field?
Posted: Sat Mar 01, 2014 7:43 pm
by thomahawk
Thanks for the input. But it seems I am not able to get it.
My understanding is to set a variable in one page, and display it on another.
So I put this into the CGCalendar template:
{assign var="benutzersevent" value=$event.event_date_start}
(or for testing:
{assign var="benutzersevent" value='testtext'}
and put this into the content area of a simple page:
{$besuchersevent}
In Frontend: the opening of the first page should set the variable and then going to the second page should display the variable content. But it shows nothing there. Or is such a variable not valid for other pages?
Maybe that's where your link query string comes in? But honestly, I expected smarties to work... well... smarter then that. Am I wrong?
Re: CGCalendar, link sets some text into form field?
Posted: Sat Mar 01, 2014 7:50 pm
by velden
thomahawk wrote:
Maybe that's where your link query string comes in? But honestly, I expected smarties to work... well... smarter then that. Am I wrong?
Yes, you're wrong. Every variable is valid for one page request only. That has nothing to do with smarty but with how a web server/script engine works.
To use it for a subsequent request you need to store it (typically in cookie) or supply it to the next 'request' by get (in url) or post parameter.
In this case I would suggest the parameter thing which you can take care of yourself like JohnnyB suggested or use the {module_action_link}
Re: CGCalendar, link sets some text into form field?
Posted: Sat Mar 01, 2014 7:56 pm
by JohnnyB
It should work with adding the scope='global' parameter to your {assign} tag. This will make the variable available for all templates if you are using the latest CMSMS 1.11.x series that now use Smarty version 3.
But, if that doesn't work for some reason, then yes, that is where the Query strings are important because that data will be put into the URL link to the form and then Smarty logic can be used to capture the Query String values to populate the form fields.
Re: CGCalendar, link sets some text into form field?
Posted: Sat Mar 01, 2014 7:58 pm
by JohnnyB
You could also use session cookies to do this too. Set the variable in the CGCalendar and then save that variable as a session cookie. Then use Smarty to read the cookie for the form....
Re: CGCalendar, link sets some text into form field?
Posted: Sat Mar 01, 2014 8:02 pm
by velden
I don't think a cookie is the best approach here because every time a detail view is displayed you should set the cookie just for the case a use clicks the form link.
I think global scope is default in CMSMS and still is only valid for one request.
Note that using parameters (get or post) should be validated before actually using them (for security reasons).
Re: CGCalendar, link sets some text into form field?
Posted: Sat Mar 01, 2014 8:18 pm
by thomahawk
Thanks, Velden. I tried it with the link approach like described by JohnnyB. It produces a link
http://www.domainname.ch/index.php?page ... =12.5.2014 12:15 which is not a working link and resulted in page not found error.
So, JohnnyB, the scope='global' thing sounds promising. And yes, I have the latest version of CMSMS, just fresh installed last week. But I can not find any reference to this option.
I put this in the CGCalendar template
{assign var="benutzersevent" scope='global' value=$event.event_date_start}
and this on the next page {$besuchersevent} but it still displays nothing.
Re: CGCalendar, link sets some text into form field?
Posted: Sat Mar 01, 2014 8:56 pm
by JohnnyB
The page with alias of "anfrageformular" must be an existing page for the link to work. It should be the page that loads your Formbuilder form.
Since you are not using 'pretty urls' or mod_rewrite, your query string needs to be built a little differently.
This has too many "?" in it - only the first is needed. Each new query string is separated by an "&"
Code: Select all
http://www.domainname.ch/index.php?page=anfrageformular?event=12.5.2014
TO:
Code: Select all
http://www.domainname.ch/index.php?page=anfrageformular&event=12.5.2014
If the CGCalendar and Formbuilder are using the same page and template than the assign should work. But to send the smarty var data to a new page and/or new template, you'll need to use query strings.
More information about Smarty assign - http://www.smarty.net/docs/en/language. ... assign.tpl
I'm building the same kind of system for a friend's site that needs to handle registrations. I like using Formbuilder because you can have many different fields without using the Frontend User module and requiring FEU accounts.... Also, I have an article started to show how I work it out. Unfortunately, it has not been a priority because the deadline is 3 months away from now.... Otherwise, I would have better examples and exact Smarty code to post.

Re: CGCalendar, link sets some text into form field?
Posted: Sun Mar 02, 2014 10:09 am
by thomahawk
OK, even this dumb designer has got it now. Thank you JohnnyB! You're great!
I did set up pretty URL (I wanted that anyway, but as the site is not official now, its in a subdirectory and I had to figure out first how to get this working).
I did put this on the CGCalendar Template:
<a class="kalender-button" href="{cms_selflink href='anfrageformular'}?event={$event.event_date_start|date_format:"%d %m %Y"}">ANMELDEN</a>
And on the "anfrageformular" page I put this:
{$smarty.get.event}
It is now passing along the event date. I just need to integrate {$smarty.get.event} into a form field, I am confident I will get this to work.
The main problem was, on all the "assign variable" theme documentations for Smarty, they never explain that it does not work from one page to another.
Re: CGCalendar, link sets some text into form field?
Posted: Sun Mar 02, 2014 10:12 am
by thomahawk
Now to the security!
I assume one could send anything with such a link, maybe some php injection?
Velden mentioned: "Note that using parameters (get or post) should be validated before actually using them (for security reasons)."
But now, how can I do that validation?
Re: CGCalendar, link sets some text into form field?
Posted: Sun Mar 02, 2014 2:31 pm
by calguy1000
The main problem was, on all the "assign variable" theme documentations for Smarty, they never explain that it does not work from one page to another.
That's not a smarty thing it's an html/php thing. HTML and PHP are stateless therefore there is no implicit storage of data between requests.