solved Custom Form Design

alt=
@rsandnes
8 years ago
6 posts
Hey all. I could use a little guidance in how to approach this problem I'm having=)

I have used the form designer to create all the fields I need and am able to navigate to: http://www.MYSITE.com/createissue/create

The form is there, but now what I need to do is take 4 fields at a time and place them in a nice javascript slider. creating jrCore_form_field_elements.tpl in my skins directory overrides exactly as one might hope, but that also is going to effect every form on my site which I don't want. I need it to only effect the "xxCreateIssue" module's form.

Also, I need to be able to wrap a div around every 4th field so the slider is able to place them properly, which I presume I would have to override the php function that calls the form_field_elements.tpl file in a loop (somewhere).

I hoped it might be as simple as placing skins/MyTemplate/xxCreateIssue/form_field_elements.tpl, but no go on that one either.

Any direction on what I need to do to have it call a different .tpl file for form_fields and how it loops through each field would be wonderful. I've spent some time on this and can't find anything in the documents.

Thanks!
updated by @rsandnes: 05/12/16 09:26:30AM
michael
@michael
8 years ago
7,715 posts
Give me a bit, I setup to check this out for you. Its easy to see that you've tried.

back soon.
michael
@michael
8 years ago
7,715 posts
ok, got something.

There are probably multiple ways to do this, but this one works. The concept is, look for an 'event' that is firing when the form_field_elements.tpl is firing, AND we are in our module, then use a 'listener' to redirect to our custom version of that file for just our module.

Docs: "Events and Listeners"
https://www.jamroom.net/the-jamroom-network/documentation/development/1011/events-and-listeners

So the first step is to register the listener for the event we want, the one I chose was 'template_file', so in the _init() function for the module:
/modules/xxCreateIssue/include.php

add:
jrCore_register_event_listener('jrCore', 'template_file', 'xxCreateIssue_template_file_listener');

The whole thing probably looks something like:
/**
 * init
 */
function xxCreateIssue_init(){
    jrCore_register_module_feature('jrCore', 'quota_support', 'xxCreateIssue', 'on');

    // catch the template_file even and fire a function
    jrCore_register_event_listener('jrCore', 'template_file', 'xxCreateIssue_template_file_listener');
    return true;
}

Then under that add in this function:
function xxCreateIssue_template_file_listener($_data, $_user, $_conf, $_args, $event)
{ if ($_data['template'] == 'form_field_elements.tpl') { $flag = jrCore_get_flag('xxCreateIssue_use_custom_tpl'); if ($flag) { $_data['directory'] = 'xxCreateIssue'; $_data['template'] = 'form_field_elements.tpl'; jrCore_delete_flag('xxCreateIssue_use_custom_tpl'); } } return $_data; }

Then copy the form_field_elements.tpl file from the core folder to:
/modules/xxCreateIssue/templates/form_field_elements.tpl
(it doesnt have to be called this, but for ease of remembering its easy)

You can see in that function above that we are looking for a flag that has been set, xxCreateIssue_use_custom_tpl. Thats just a name I chose, it could be anything, but something unique so we know its the right one in our listener.

The last thing we need to do is set that flag during the _create() function or the update function if you use that too.

in /modules/xxCreateIssue/index.tpl in the view_xxCreateIssue_create() function, just before the jrCore_page_display() function set that flag:
     jrCore_set_flag('xxCreateIssue_use_custom_tpl', true);
     // Display page with form in it
     jrCore_page_display();

Now when the page is showin the custom version of the form_field_elements.tpl will show.

(actually thinking about it now, might need to wait longer to delete the flag if you have many page elements. Suspect you can take it from here.)

You can set a session counter or a flag to do the "count to 4 then wrap div" part.

Great to see developers working on this level. Great question. :)
alt=
@rsandnes
8 years ago
6 posts
Wow, I typed a response to this and never sent it. Thank you very much for your help on this Michael. The solution worked Phenomenal!

The only thing to add should anybody need this in the future is that I needed to add: if(stristr(jrCore_get_current_url(), 'createissue/create')) otherwise all forms are overridden.
michael
@michael
8 years ago
7,715 posts
Great to hear! :)

Would have expected 'create' would have come in in the $_args, but if its working no need to over-think :) many ways to do the same thing.

Well done.

--edit--
or
 global $_post;
would contain it too.
updated by @michael: 02/11/16 01:39:53AM

Tags