Buy Now
Sign in

Chronoforms4 integration with K2

BNDragon , February 25 2014
Answered
BNDragon

Hello to all ,

This is my first tutorial , my english is not the best, so if you do not understand something say that I try to explain myself better , but try to be as concise as possible.

Today I present a simple integration between Chronoforms4 and K2 on Joomla! 3.2. I will demonstrate just 3 examples , the rest are identical ! ;)

I'll show you how to fill in the Title , Alias ​​and INTROTEXT .
Assume for this tutorial that the user can enter any title, the Alias ​​is like the pre-defined items of K2 (word-word-word format ... (all lowercase and separated by hyphens)) and will be hidden from the user, in other words, is automatically entered when submitting the form, and finally, the user can insert any content in INTROTEXT, and whoever follows this tutorial have the basic (reallybasic) notions in ChronoForms4!

Fist at all, you should consult your Database to confirm the name of the table fields which will be saved. Probably ithave the same name that I 'll give, but you should check it out!
In this case , the Title in the table is "title " Alias ​​'s "Alias ​​" and INTROTEXT is " introtext " .

First, we create a simple form ( Form Wizard ) :



Element configuration (neatly):
Note: In this example just set the tab "General"!





And then the result should look something like:


In the event, suffice two actions:


And just configure the DB Save:


Give a name and Save&Close!


In the Forms Manager click on the form name (K2ItemForm).
In the Code tab should appear something like this:


Look for this code:
				<input name="ButtonSubmit" id="ButtonSubmit" class="" value="Submit" type="submit" />
				


And add:
				onclick="var str = document.getElementById(‘fieldTitle’).value; str = str.toLowerCase().replace(/[^a-z0-9\s-_æ]/gi, '').replace(/[_\s]/g, '-').replace(/-+/g, '-');document.getElementById(‘fieldAlias’).value=str;"
				


So it becomes:
				<input name="ButtonSubmit" id="ButtonSubmit" class="" value="Submit" type="submit" onclick="var str = document.getElementById(‘fieldTitle’).value; str = str.toLowerCase().replace(/[^a-z0-9\s-_æ]/gi, '').replace(/[_\s]/g, '-').replace(/-+/g, '-');document.getElementById(‘fieldAlias’).value=str;" />
				


Save and you are done!
Note: Be careful when you change the form, because when you re-save it, the code "onclick" disappears and have to put it back.

Hopefully be useful to you;)

Attachments
ChronoFormsK2-1.png
ChronoFormsK2-1.png
(12.74 KiB)
896 Downloads/Views
ChronoFormsK2-2.png
ChronoFormsK2-2.png
(11.55 KiB)
822 Downloads/Views
ChronoFormsK2-3.png
ChronoFormsK2-3.png
(6.6 KiB)
770 Downloads/Views
ChronoFormsK2-4.png
ChronoFormsK2-4.png
(11.15 KiB)
765 Downloads/Views
ChronoFormsK2-5.png
ChronoFormsK2-5.png
(10.59 KiB)
783 Downloads/Views
ChronoFormsK2-6.png
ChronoFormsK2-6.png
(10.02 KiB)
778 Downloads/Views
ChronoFormsK2-7.png
ChronoFormsK2-7.png
(8.64 KiB)
773 Downloads/Views
ChronoFormsK2-8.png
ChronoFormsK2-8.png
(16.01 KiB)
797 Downloads/Views
ChronoFormsK2-9.png
ChronoFormsK2-9.png
(9.3 KiB)
767 Downloads/Views
ChronoFormsK2-10.png
ChronoFormsK2-10.png
(29.94 KiB)
761 Downloads/Views

Sorry for my english, any problem understanding me, let me know, I will try to explain myself better! ;)

K
K2Joom

Nice Guide!!

I like this idea and see some good potential as basically it is simplifying the creation of Items in K2.
There are various ways to also adapt and expand on this, such as with a custom K2 template, in the category view the Add Item to this Category link could have the hyperlink changed to use this submission form.

Why do this, quite simply there is a lot of options in the New Item screen and if you are allowing users to have front end create access you can then use a custom form just to submit only the data you want them to access.

Can you confirm, how to you handle setting data such as category, author, user group, creation date?
Any thoughts on being able to display the correct K2 Extra Fields, based on the selected category?


Simon

Regards,

Simon

K
K2Joom

So I replicated the above step by step, this is what I found.

On submission, empty container.
Check K2 admin, no new items listed.
Check XXX_k2_items table and two new IDs are created, no title, no alias and other data fields are empty too, because they were not set with any data.

Will carry on testing.

Regards,

Simon

BNDragon

Hello Simon,

Unfortunately I stopped using K2 for some time, despite being a powerful CCK, the SEBLOD have greater integration with Joomla! and takes better advantage of the features provided by Joomla!.

But I think I can tell you how you can do what you want.
Attention is mere speculation which I speak unto thee, that is, you have to confirm that I'll say, because at the moment I do not have time to confirm all the steps, but I think it is something simple.

The question of the fields to add, is to follow the steps that are in the toturial. Diferene what is the solution if you want filled automatically with user data, or is the user input.

If the user, I advise you to use fields unfilled, as drop down list, or radio fields.

Should it be automatic, become quite simple, just use js.

There is a class of joomla that you can search and get user data (do not remember is if the user ID of Joomla are the same as K2 users, if not maybe take a little more work).

Here's an example:

				$ user = JFactory :: getUser ();

if (! $ user-> guest) {
echo 'You are logged in as: <br />';
echo 'User name:'. $ user-> username. '<br />';
echo 'Real name'. $ user-> name. '<br />';
echo 'User ID'. $ user-> id. '<br />';
}


Was removed here:
http://docs.joomla.org/JFactory/getUser

If you need anything just let me know and I will answer as soon as I can.
I hope I have been useful. :)

Sorry for my english, any problem understanding me, let me know, I will try to explain myself better! ;)

BNDragon

That's strange, I tested the sample before placing the toturial and it worked.

You completed the last step? (I noticed now that the last image is repeated, the number should be 10 and not 9)

And the fields are correct?

Sorry for my english, any problem understanding me, let me know, I will try to explain myself better! ;)

K
K2Joom

Hey There,

No problem, I saw K2 and had to play.
I was thinking about using Joomla getuser too or query the k2 user table for specific group to display users in a drop.

Last step was done too in the custom code and image 10 is loaded at the bottom of the guide.

No problem, I will play until I fix it.

Thanks for your time.

Regards,

Simon