[SOLVED] CGCalendar, link sets some text into form field?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
User avatar
thomahawk
Power Poster
Power Poster
Posts: 312
Joined: Fri Jul 25, 2008 10:13 am

[SOLVED] CGCalendar, link sets some text into form field?

Post 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
Last edited by thomahawk on Mon Mar 03, 2014 6:05 pm, edited 1 time in total.
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: CGCalendar, link sets some text into form field?

Post 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.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
User avatar
thomahawk
Power Poster
Power Poster
Posts: 312
Joined: Fri Jul 25, 2008 10:13 am

Re: CGCalendar, link sets some text into form field?

Post 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
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: CGCalendar, link sets some text into form field?

Post 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.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: CGCalendar, link sets some text into form field?

Post 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.
User avatar
thomahawk
Power Poster
Power Poster
Posts: 312
Joined: Fri Jul 25, 2008 10:13 am

Re: CGCalendar, link sets some text into form field?

Post 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?
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: CGCalendar, link sets some text into form field?

Post 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}
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: CGCalendar, link sets some text into form field?

Post 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.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: CGCalendar, link sets some text into form field?

Post 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....
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: CGCalendar, link sets some text into form field?

Post 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).
User avatar
thomahawk
Power Poster
Power Poster
Posts: 312
Joined: Fri Jul 25, 2008 10:13 am

Re: CGCalendar, link sets some text into form field?

Post 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.
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: CGCalendar, link sets some text into form field?

Post 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. :-[
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
User avatar
thomahawk
Power Poster
Power Poster
Posts: 312
Joined: Fri Jul 25, 2008 10:13 am

Re: CGCalendar, link sets some text into form field?

Post 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.
User avatar
thomahawk
Power Poster
Power Poster
Posts: 312
Joined: Fri Jul 25, 2008 10:13 am

Re: CGCalendar, link sets some text into form field?

Post 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?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: CGCalendar, link sets some text into form field?

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “Modules/Add-Ons”