Domanda

Folks,

In the Mura plugin I am developing, I have two pages under displayObjects:

myinput.cfm
myaction.cfm

In myinput.cfm, I am using cfform to gather input:

<cfform action="myaction.cfm" method="post">
...
</cfform>

After I add my plugin to a page, the form from myinput.cfm comes up as expected. However, when submit is clicked, I get an error that myaction.cfm is not found.

I think the way I am defining action is not correct. Recall that my plugin is just a small part of a bigger page. Form submit should actually go back to the same page except that the rendering should somehow use myaction.cfm instead of myinput.cfm.

I guess the problem is more general in nature that how to define a navigational link that points to a different page within a plugin.

Thank you in advance for your help.

Regards,
Peter

È stato utile?

Soluzione

All DisplayObjects have to be added directly to a page, so unless you added myaction.cfm to the page as well, it would never be found.

If you really needed to, you can get the mapping to files in your plugin using:

<cfinclude template="/#$.getPlugin('MyPluginPackageName').getDirectory()#/...">

Typically you can assign $.getPlugin('MyPluginPackageName') to an object variable at the beginning of a DisplayObject so that you can re-use it without having to repeatedly call the function.

However, this is not best practice for mapping your "view" files in a Mura Plugin.

A more recommended way of doing this is to have the same DisplayObject display the form and process the form results. You can wrap your form in a conditional like:

<cfif StructKeyExists(form,"some_field_in_my_form")>
... action code
<cfelse>
... form code
</cfif>

...to determine whether or not the form has been submitted yet (obviously adjusted if you are doing server side validation or the like). One thing I'll recommend is that you don't use StructCount("form") or similar as there might be other forms on the page that have been submitted.

If you want to separate your code to keep it more organized, just use your DisplayObject as a container and use includes/function calls/etc.

Display Object: [your plugin folder]/displayObjects/myform.cfm

<cfif StructKeyExists(form,"some_field_in_my_form")>
    <cfinclude template="./inc/myaction.cfm">   <!--- [your plugin folder]/displayObjects/inc/myaction.cfm --->
<cfelse>
    <cfinclude template="./inc/myinput.cfm">    <!--- [your plugin folder]/displayObjects/inc/myinput.cfm --->
</cfif>

If you are really determined to have two display objects, you would have to either a) assign them both to the same Mura content page, but wrap them with conditionals to make sure they only appear in the proper context, or b) assign them to different Mura pages and have your form post point to the Mura page that contains the myaction.cfm display object.

Finally, I'd recommend checking out the FW/1 sample plugin at https://github.com/blueriver/MuraFW1 ... once you get the hang of FW/1 (the easiest CFML framework to learn) it will make building your plugins much, much easier.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top