Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Pre-Validate Form Field Contents Before formmail Processes Submit

  1. #1
    Join Date
    Apr 2010
    Posts
    20

    Default Pre-Validate Form Field Contents Before formmail Processes Submit

    How do I call a function to validate my form contents "before" formmail processes the form?

    Currently, I have set onSubmit to call a validate() function. But this never executes as it appears formmail does it's own processing (i.e. processing required fields) before my function gets called.

    MJS

  2. #2
    Join Date
    Dec 2003
    Posts
    3,980

    Default Re: Pre-Validate Form Field Contents Before formmail Processes Submit

    Hi,

    Any JavaScript (JS) you want to use is fine, and it's called within the browser before FormMail receives the form submission.

    If your JS code is not being called then it's a problem with your HTML or you JS code. FormMail cannot influence this in any way because it's not involved until the form submission is actually performed and data is sent to the server.

    We recommend you use JS code for "user friendliness", but use FormMail's "required" and/or "conditions" features to provide real validation of the submission.

    This is because users can switch off JS in their browser, so JS validation is not real validation.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  3. #3
    Join Date
    Apr 2010
    Posts
    20

    Default Re: Pre-Validate Form Field Contents Before formmail Processes Submit

    My onSubmit="validated();" which returns true or false if all my validations work (or not) in my form's properties never executes. So while I shouldn't have had to do this, I instead used an onFocus event handler on my Submit button which seems to trigger as expected and the resulting code executes properly.

    However, I'm still getting an error from the form submission itself. Despite the fact that I have a recipients text field in my form, it is being set to something valid, and it is set in my TARGET_MAIL field in my php, I get an email saying this value is not set.

    What am I missing?

    MJS

  4. #4
    Join Date
    Dec 2003
    Posts
    3,980

    Default Re: Pre-Validate Form Field Contents Before formmail Processes Submit

    Hi,

    My onSubmit="validated();" which returns true or false if all my validations work (or not) in my form's properties never executes. So while I shouldn't have had to do this, I instead used an onFocus event handler on my Submit button which seems to trigger as expected and the resulting code executes properly.
    This isn't a FormMail question, of course....but, from memory, I think the onsubmit goes in the <form> tag, not on the submit button. To put it on a button tag, it should be "onclick".

    However, I'm still getting an error from the form submission itself. Despite the fact that I have a recipients text field in my form, it is being set to something valid, and it is set in my TARGET_MAIL field in my php, I get an email saying this value is not set.
    It doesn't tell lies...so, if it's saying it's missing, then it is. The question is why?

    Since FormMail is a free product, we don't provide free support.

    I recommend you either post your question on the Community Support forum to get some help from the community of FormMail users, or purchase a support subscription and we'll help you sort it out.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  5. #5
    Join Date
    Apr 2010
    Posts
    20

    Default Re: Pre-Validate Form Field Contents Before formmail Processes Submit

    Well I am still unclear as to why my form's onSubmit event doesn't execute my validation routine but my Submit button's onFocus event handler does. But at least it is executing.

    As to the recipients not being set. I didn't pay close enough attention to the error. It was saying that a "valid" recipient was not set and I guess my mask in my target_email was not set correctly. (I'm in development mode and as a result, my domain is still being used but an old provider until I'm ready to go live with the new web site, new provider, but old domain name. So my target_email is being set to suit my development environment until then. And I did not understand the masking correctly.)

    In any event, I have another question. My form is set to receive uploaded files but only if a particular subject is chosen. However, it appears formmail "expects" a file attachment regardless.

    So while the form submits successfully, I still receive another email (besides the form submission) saying there were no files attached. Am I supposed to be doing something special to indicate a file does not "have" to be attached to the form submission?

    MJS

  6. #6
    Join Date
    May 2008
    Posts
    1,291

    Default Re: Pre-Validate Form Field Contents Before formmail Processes Submit

    Quote Originally Posted by mseiferl View Post
    Well I am still unclear as to why my form's onSubmit event doesn't execute my validation routine but my Submit button's onFocus event handler does.
    Russell gave you the answer. The onSubmit goes in the form tag. The reason that it doesn't work when you use it on the submit button is exactly that. The form is being submitted when you click the submit button and formmail is immediately executed. There's no chance for the javascript function to be executed. The reason it works when you just use the onFocus event handler is because the form hasn't been submitted yet. I used to get confused about this too. However, if you call the validation routine by using the onSubmit event handler in the form tag, the validation routine will be run prior to the form submission.

    You need to post the question about the upload error in the Community Support forum. This forum is for users to post "how-to" guides and tips. When you do, you should include the code you're using to enforce that an upload is only required in certain situations.

  7. #7
    Join Date
    Apr 2010
    Posts
    20

    Default Re: Pre-Validate Form Field Contents Before formmail Processes Submit

    FYI, I'm not sure why you (and Russell) keep saying the onSubmit must go in the form. That's what I've been saying. It "is" in the form "not" the Submit button. But the function call does not execute onSubmit but does appear to work when I instead trigger it from the Submit button. To illustrate,

    <form id="whatever" action="mydomain/formmail.php" method="post" onSubmit="return validated();">
    form elements
    <input type="submit" value="Submit" onFocus="validated();">
    </form>

    As I've been saying, onFocus (as above) seems to work but onSubmit as above) does not.

  8. #8
    Join Date
    Mar 2004
    Posts
    2,224

    Default Re: Pre-Validate Form Field Contents Before formmail Processes Submit

    try this:
    HTML Code:
    <form id="whatever" action="mydomain/formmail.php" method="post"  onSubmit="alert('Submit happening');">

  9. #9
    Join Date
    May 2008
    Posts
    1,291

    Default Re: Pre-Validate Form Field Contents Before formmail Processes Submit

    Sorry, I misunderstood.

    If you post your javascript code we might be able to see why it's not working.

    ginger

  10. #10
    Join Date
    Sep 2010
    Posts
    11

    Default Re: Pre-Validate Form Field Contents Before formmail Processes Submit

    I was hoping someone would have posted an answer to the original question.

    I'm having the same issue and was wondering why.

    Just so there is no mistake, the onSubmit is in my <form> tag.

    Code:
    <form method="post" action="formmail.php" name="<?php echo $itemID ;?>" onSubmit="return mastervalidate(this);">
    mastervalidate() is a function within _validate.js. This javascript code has been verified to be working fine when called by other means.

    However, for some reason this function is NOT called when the Submit button is clicked. Formmail is triggered to validate based on required fields in my .ini file (as opposed to the hidden 'required' field).

    Replies to the other poster's question suggest that he had onSubmit in the Submit button field as the problem. This does not appear to be the case as it does not work for me in the <form> field.

    Does it appear that I'm using onSubmit incorrectly?

    Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sample HTML Form Using FormMail
    By russellr in forum FormMail
    Replies: 1
    Last Post: 21-Mar-2007, 06:49 AM
  2. Error when submit is clicked
    By thall1908 in forum FormMail Subscription Support
    Replies: 6
    Last Post: 11-Nov-2004, 11:28 PM
  3. CPU Maxed after (maybe?) double click of submit?
    By OKUser in forum FormMail Subscription Support
    Replies: 6
    Last Post: 23-Jun-2004, 07:33 PM
  4. Problem with Form Field
    By joe3366 in forum FormMail Subscription Support
    Replies: 5
    Last Post: 13-Jun-2004, 09:02 PM
  5. Redirect to my page on submit
    By insight in forum FormMail Subscription Support
    Replies: 21
    Last Post: 09-Apr-2004, 12:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •