puting forms into a helper..

Hi there, just looking for some advice on best practice..

I would like to move my forms out of my views to clear things up a
bit..

I was thinking of creating a UDF in the include folder which would
contain all the different forms, for example

    <!---Add artist Form--->
   <cffunction name="showArtistForm" output="false" returntype="string"
access="public" hint="allow user to insert new artist">

   <!---Artist Id Argument--->
   <cfargument name="formAction" required="yes" type="any" hint="action
variable for form">

   <cfset addArtistForm = '<form name="setArtName"
                                     action="#rc.xehArtEdit#"
                                     method="post">

                                        <fieldset>
                                       <legend>edit artist</legend>
                                        <div>
                                     <label for="artist name">artists
name</label>
                              <input name="name"
                         type="text"
                       value="#event.getValue('rc.name','#rc.name_art#')
#">
                                  </div>
                                 </fieldset>
                                <input type="submit"
                                name="submit_me"
                     value="submit" />
                               <!---Hidden form field--->
                                <input name="name_art"
                            type="hidden"
                            value="#rc.name_art#" />

                                  </form>

      <cfreturn addArtistForm>

                  </cffunction>

Then i could call the form in the view like so...

#showArtistForm(rc.ex.addArtistAction)#

Is this best practise? Or maybe I should move forms into seperate
viewlets to clear things up?

Thanks

Not sure about best practice, but all of my forms are views in a ‘forms’ folder. Then I use RenderView(‘forms/forminclude’) within my base view.

so you have a separate form in each seperate view in the 'forms'
folder?

Do you execute any events within these form views?

Thanks

Namtax,

Keep it simple. So create a view for a form, maybe a view which
renders multiple views etc.
Personally, I would never use a cffunction to generate a form for me.

Ernst

@namtax

I don’t know what you mean by executing events within my views. But yes, I keep each of my forms in a separate view template. This way I can re-use them. For example, I have a ‘sign up’ form that is included on the homepage of my site, and there is also a ‘sign up’ page. I use renderView(‘forms/signup’) in both places. I think you hit the nail on the head with ‘viewlets’.

In viewlets...you can execute events...

eg

<cfset runEvent(event='viewlets.artistForm'.private=true)>

In case you need to use some query variables in the forms hidden form
fields etc, etc..

Just wondered if you did this

Yes, this is the route I am taking..

Thanks