Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Prevent CFFORM from submitting

LEGEND ,
Apr 19, 2011 Apr 19, 2011

Hello, everyone.

I've tried disabling a CFFORM by using ' onLoad="this.disabled = true;"' and ' onLoad="this.submit.disabled = true;"' and other things, but no matter what I do I cannot seem to prevent a CFFORM from being submit (there is no submit button; there's a text link that runs some JavaScript when needed).

How can I either disable the CFFORM or prevent it from being submit?

Thanks,

^_^

3.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 19, 2011 Apr 19, 2011

Leave the submit button off or <input type="Submit" disabled>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 19, 2011 Apr 19, 2011

LyndonPatton wrote:

Leave the submit button off or <input type="Submit" disabled>

I've tried disabling a CFFORM by using ' onLoad="this.disabled = true;"' and ' onLoad="this.submit.disabled = true;"' and other things, but no matter what I do I cannot seem to prevent a CFFORM from being submit (there is no submit button; there's a text link that runs some JavaScript when needed).

There isn't a submit button.

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 19, 2011 Apr 19, 2011

I can't understand why you would submit a

form using a link, but if you must....

The form element, which cfform inherits from, does not have a disabled property so onLoad="this.disabled = true;" is not valid. See http://www.w3schools.com/html/html_forms.asp for a property, object, and method list for the form element.

If your link is doing your form submit work then it needs to be be disabled until your condition becomes true. The <a> link element also does not have a disabled property; you would want to set it's display property to none untill the condition is met.

If you shared more code this would be easier...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 19, 2011 Apr 19, 2011

You don't "DISABLE" a form.

If you don't want the form submitted you RETURN false from any function that would submit the form.

VERY SIMPLE example.

<form...>

<input type="submit" onClick="return False">

</form>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 19, 2011 Apr 19, 2011

Sorry.. I was in a big rush when I was trying to explain things.

The issue was due to the ENTER key submitting the form when I didn't want it to (the <a> was supposed to handle submitting the form, but the ENTER key would do it, anyway.)

The solution was to use JavaScript / onKeyDown(event) to prevent the ENTER key from working (there are no textareas or anything else that would require use of the ENTER key - just one simple input/text and three radio buttons - so disabling the ENTER key is sufficient.)

Thank you for your input and advice, everyone.

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 19, 2011 Apr 19, 2011

What you did is not necessarily the best idea.  Causing the browser to work differently than expected creates upleasant user experiences.

Since you have all this javascript written anyhow, you could always call it with the form's onsubmit event.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 20, 2011 Apr 20, 2011

Preventing the enter key from working onSubmit will submit the form.  Preventing the enter key onKeyDown prevents the form from being submit.

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 20, 2011 Apr 20, 2011

Yeah, I gotta agree with Dan.  Users get seriously pissed when you break the functionality they're used to.

That being said - are you _ever_ submitting the form?  Or is it just posting data via Ajax for the save?

If you never submit the form - then remove the action from the form tag, don't have a <input type='submit' /> and use a link or other some such device to post via Ajax.

If you shared more code this would be easier for us all...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 21, 2011 Apr 21, 2011

cfsilence wrote:

Yeah, I gotta agree with Dan.  Users get seriously pissed when you break the functionality they're used to.

That being said - are you _ever_ submitting the form?  Or is it just posting data via Ajax for the save?

If you never submit the form - then remove the action from the form tag, don't have a <input type='submit' /> and use a link or other some such device to post via Ajax.

If you shared more code this would be easier for us all...

This is for an internal web app for a large corporation, not a publically available site, so the users kind of expect certain things.

The form should not actually submit, the action has already been removed, in IE7 it will submit anyway - even without the action or an input submit.

It is set to do something similar to Google's instant search - starts retrieving data with each keystroke.  But the ENTER key was screwing things up.

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 21, 2011 Apr 21, 2011
LATEST

Well, I hate to say this, but the enter key does submit the form on Google instant.  Go try it, you'll see the page actually refreshes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources