K2 integration with ChronoForms

  • Comments:View comments
Rate this item
(3 votes)

This is a simple tutorial for how to integrate ChronoForms and K2...


To integrate Chronforms and K2, such that form fields generated by ChronoForms can be populated with K2 extra field values for a K2 item.

For example, you have created a ChronoForms form with name 'contactus', this form has the following fields:

1- input_email: This is the email address for the receiver.

2- input_title: This is the subject of the message.

You want this form to be displayed in K2 item view pages, where each item has an extra field with alias 'emailAddress', the value of this field to populate the 'input_email' field of the form, and the title of K2 item will pupulate the 'input_title' field of the form.



First of all, you need to apply the template overrides feature of K2, to limit the form display in specific items, by category for example.

Now, go to your overrides folder, and edit the file item.php as the following:

1- Insert the code directly after this line 

defined('_JEXEC') or die; 

here is the code...

if(file_exists(JPATH_SITE.DS.'components'.DS.'com_chronoforms'.DS.'chronoforms.html.php') && file_exists(JPATH_SITE.DS.'components'.DS.'com_chronoforms'.DS.'libraries'.DS.'chronoform.php')){	

Then, insert this code where you want the form to be displayed:


$javascript = '$K2(document).ready(function(){
        $K2("input[name=input_email]").val("'. $this->item->extraFields->Street->emailAddress.'");
		$K2("input[name=input_title]").val("'. $this->item->title.'");		
$document = JFactory::getDocument();

Make sure to enclose the code with php opening and closing tags.

Then save the file and test.

This tutorial is tested with Joomla 2.5 and K2 2.6.8

Read 8064 times