Buy Now
Sign in

Passing Parameter to Form from Content page using plugin

MainsailSoftware , January 15 2015
Answered
MainsailSoftware

I have a sign-up form I have created that adds a user to an activity. The form uses two DB tables: one that identifies multiple activities and the other participants associated to a given activity. I would like to use this form with the Chronoforms Plugin on a content page for a specific activity, but need to pass the form the activity identifier so the correct activity gets associated with the added participant. I don't want to create separate forms if I can avoid it, and don't want the user to have to select the appropriate activity. I am using Chronoforms v4.0.6 and gradually converting to v5.0.4 on Joomla! 3.3.3.

Is there a way to pass the activity identifier using something like {chronoforms data:"activity=2"}ActivityForm{/chronoforms} as described in this forum thread http://www.chronoengine.com/forums/posts/f4/t88901/chronoforms-plugin-parameter-and-show-form-action-support.html?hilit=plugin+parameters?

If not, how would you suggest I address this requirement?

Mbiyc Webmaster
President, Sr. Software Architect, Mainsail Software LLC

admin

Hi MainsailSoftware,

Please try this with v5:

				{chronoforms5}form_name&activity=XYZ{/chronoforms5}
				


Now a field named "activity" in your form should have the XYZ value set.

Regards,
Max

Max
If your main question got answered then please mark the answer using the button!

MainsailSoftware

Thanks Max,

I tried

{chronoforms5}Activity&activity_id=XYZ{/chronoforms5}

and the following is what is seen using the Debug action.

Array
(
[Activity] =>
[amp;activity_id] => XYZ
)

It working, but not as I expected... Any suggestions?

Mbiyc Webmaster
President, Sr. Software Architect, Mainsail Software LLC

MainsailSoftware

I also tried

{chronoforms5}Activity&activity_id=XYZ&member_name=Name{/chronoforms5}

and got

Array
(
[Activity] =>
[amp;activity_id] => XYZ
[amp;member_name] => Name
)

Mbiyc Webmaster
President, Sr. Software Architect, Mainsail Software LLC

admin

I think that your text editor in the article has replaced the "&" by "&", please disable the editor and fix this then save and retry!

Regards,
Max

Max
If your main question got answered then please mark the answer using the button!

MainsailSoftware

Hummm...

I am using Chrome browser and the latest Joomla! admin JCE editor...

I will try looking into what exactly is being generated and get back to you.

Mbiyc Webmaster
President, Sr. Software Architect, Mainsail Software LLC

MainsailSoftware

Looking at what the JCE editor is producing, you are exactly correct! If I Toggle the editor to show the generated html, I get...

<p>{chronoforms5}Activity&amp;activity_id=XYZ{/chronoforms5}</p>

I had to save the article with the JCE editor in Toggled to the html view. If you toggle back, it changes back to &amp;.

I tried my code with this article plugin reference and change my data reference from amp;activity_id to activity_id and it works perfectly.

This is an editor issue as you suggest, but I would think most Joomla! admins will use the built-in content editing tools.

Perhaps you might consider allowing other separators in addition to &, such as $ or ? or colon or semi-colon or comma?

For now I can keep this issue in mind and perform direct HTML editing of the plugin reference before saving.

Mbiyc Webmaster
President, Sr. Software Architect, Mainsail Software LLC

admin

Thanks, I added a fix for that!

Regards,
Max

Max
If your main question got answered then please mark the answer using the button!

GreyHead

Hi MainSailSoftware,

As a workaround you can edit the /plugins/content/chronoforms5/chronoforms5.php file and try adding an extra line after line 34

				$mainframe = \JFactory::getApplication();
$match = str_replace('&amp;', '&', $match); // << add this line
parse_str($match, $params);

Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much

MainsailSoftware

Thanks Max...

Perfect Bob!

Mbiyc Webmaster
President, Sr. Software Architect, Mainsail Software LLC

MainsailSoftware

First, I want to say how great you guys provide support for your product! I am really happy that I purchased Chronoforms!

Bob, I made the change you suggested and that fixed the DB Save issue, but after I changed the Article back so that the JCE editor once again produced <p>{chronoforms5}Activity&amp;activity_id=XYZ{/chronoforms5}</p> in the saved HTML, another error appeared.

The form I created initially does a DB Read to make sure the participant has not already registered for the Activity. As part of the conditions for the DB Read I have this snippet of PHP code:

<?php return array( 'activity_id' => $form->data['activity_id']); ?>

The error that appears on the frontend is as follows:

Notice: Undefined index: activity_id in /hsphere/local/home/a965916/mbiyc.com/joomla/administrator/components/com_chronoforms5/chronoforms/actions/db_read/db_read.php(67) : eval()'d code on line 4

Debut show:

Array
(
[Activity] =>
[amp;activity_id] => XYZ
)

I have look at the code in the admin component indicated at line 67. I guess I could hack something there, but I am not so sure I would be correcting the code in the right location. If I go back to making sure the saved Article HTML does not convert & to &amp;, everything works correctly.

So, it appears that a fix to some other location in the code maybe needed. I will leave it up to you two to tell me how to proceed.

Jim

Mbiyc Webmaster
President, Sr. Software Architect, Mainsail Software LLC

MainsailSoftware

Sorry Guys.... Please ignore my previous 2 posts... The change you recommended worked fine.

Evidently, when I FileZilla'ed the new plugin code up to the server, it did not initially take... I assume a Caching issue.

I also modified your debug action to include pr($form->actions_config) so I can see what the action is getting...

Again, thanks to the both of you for a great job with support and the components you have developed!

Jim

Mbiyc Webmaster
President, Sr. Software Architect, Mainsail Software LLC

admin

Hi Jim,

Great, no problems! :)

btw, no need to hack the debugger action, just use your code inside a "custom code" atcion:

				
<?php
pr($form);


Regards,
Max

Max
If your main question got answered then please mark the answer using the button!

MainsailSoftware

Dah!... I should have thought of that! But I was in coding mode in my local NetBeans editor.

Thanks again... love working with you guys!

Jim

Mbiyc Webmaster
President, Sr. Software Architect, Mainsail Software LLC