Skip to main content
Inspiring
April 15, 2008
Answered

Moving from Validation to Submit

  • April 15, 2008
  • 4 replies
  • 472 views
I've created my cfform, set validation for pertinent cfinput fields with custom messages and all is well. Here's my question. What statement is the best to use to start my cfif block that executes my cfmail or query code?

I started with ... cfif IsDefined ("form.firstname"), but is the use of cfif IsDefined ("form.SubmitButton.y") a better idea?

Is there a 'best practice' on this type of thing?

Thank you in advance!

PF
    This topic has been closed for replies.
    Correct answer Newsgroup_User
    not sure about 'best practice', but i definitely would not rely on
    isdefined('form.textfield') - ext fields are ALWAYS defined, even if empty.

    i usually, if submit is possible only from button click, use <cfif
    isdefined('form.submitbuttonname')>. then do my server-side validation,
    doing cfset err=1 if some data does not validate. THEN, cfif err eq 0,
    do required action (cfmail, insert/update, etc), otherwise return to
    form and show errors.

    server-side validating is paramount. DO NOT rely on just client-side
    (javascript) validation.

    hth

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/

    4 replies

    OfeargallAuthor
    Inspiring
    April 15, 2008
    Thank you, Dan,

    I'm using the following form conventions:

    <label for="firstname">*First Name:</label>
    <cfinput type="text" name="firstname" required="yes" maxlength="60" validateat="onsubmit" message="Looks like you may have forgotten to add your First Name...">

    I noticed something you had written about using some custom tags to validate here
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=1&catid=3&threadid=1313794&highlight_key=y&keyword1=validation

    That would be a server-side validate, yes?
    Inspiring
    April 15, 2008
    client side validation is generally done with cfform/cfinput and maybe some extra js. For example, let's say you want a valid date.

    on the client <cfinput name="mydate" validate="date">
    on the server <cfif IsDate(form.mydate) is true>
    OfeargallAuthor
    Inspiring
    April 15, 2008
    Azadi,

    Thanks for the information. It sounds like I could use little education on server-side VS client-side validation.

    Since I don't want to do a cross post I'll open that discussion on another thread. Or, it may be that the subject has been done to death elsewhere. I haven't done a search on the forum for that yet.

    Regarding the submit function, what other ways can I get the form to submit that are efficient, effective and validation proof?

    Thank you for your insight.

    PF
    Newsgroup_UserCorrect answer
    Inspiring
    April 15, 2008
    not sure about 'best practice', but i definitely would not rely on
    isdefined('form.textfield') - ext fields are ALWAYS defined, even if empty.

    i usually, if submit is possible only from button click, use <cfif
    isdefined('form.submitbuttonname')>. then do my server-side validation,
    doing cfset err=1 if some data does not validate. THEN, cfif err eq 0,
    do required action (cfmail, insert/update, etc), otherwise return to
    form and show errors.

    server-side validating is paramount. DO NOT rely on just client-side
    (javascript) validation.

    hth

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/