Forums

Chronoforms4 integration with K2

BNDragon 25 Feb, 2014
Answer
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 ) :
[attachment=0]ChronoFormsK2-1.png[/attachment]

Element configuration (neatly):
Note: In this example just set the tab "General"!
[attachment=1]ChronoFormsK2-2.png[/attachment]
[attachment=2]ChronoFormsK2-3.png[/attachment]
[attachment=3]ChronoFormsK2-4.png[/attachment]
[attachment=4]ChronoFormsK2-5.png[/attachment]

And then the result should look something like:
[attachment=5]ChronoFormsK2-6.png[/attachment]

In the event, suffice two actions:
[attachment=6]ChronoFormsK2-7.png[/attachment]

And just configure the DB Save:
[attachment=7]ChronoFormsK2-8.png[/attachment]

Give a name and Save&Close!
[attachment=8]ChronoFormsK2-9.png[/attachment]

In the Forms Manager click on the form name (K2ItemForm).
In the Code tab should appear something like this:
[attachment=8]ChronoFormsK2-10.png[/attachment]

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;)
K2Joom 08 Jul, 2014
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
K2Joom 08 Jul, 2014
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.
BNDragon 08 Jul, 2014
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.🙂
BNDragon 08 Jul, 2014
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?
K2Joom 08 Jul, 2014
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.
This topic is locked and no more replies can be posted.