Validate form on Submit - InfoPath Dev
in

InfoPath Dev

Validate form on Submit

Last post 10-30-2013 10:04 AM by ehaze. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 05-21-2007 01:19 PM

    Validate form on Submit

    I am trying to validate a form when a user clicks on the Submit button.  I studied this post http://www.infopathdev.com/forums/thread/11721.aspx but the script did not work for me.  Let me first explain the Rules that run when a user clicks on the Submit button.

    My Rules run as follows on Submit:

    1. Change a boolean expression box to True from False.  Once this expression box reflects True then the section containing the Submit button is hidden so that it is no longer visible within the submitted form and email attachment to prevent users from "accidently" re-submitting when reviewing the attachment in email.
    2. Submit form to SharePoint library.  This library is used to keep a copy of submitted forms as a back up strategy in case emails are lost.  (autosave is deselected as a form option so that incomplete or manually closed forms are not saved to the library)
    3. Submit form to email.
    4. Close form.

    The difficulty I am having is that when a user clicks on the Submit button and there are validation errors he/she receives two messages depending on the action taken, but for whatever reason the users are ignoring or not reading the error messages and just closing the form manually;

    1. Some rules were not applied  if the user opens the dialoge box then it tells them there are validation errors, but when a user clicks on OK then the dialoge box goes away as designed.  At this point the first Rule I have above now hides the section containing the Submit button since it was already clicked by the user.
    2. If the user then tries to re-submit using the Submit button on the toolbar he/she is given the following error message, InfoPath cannot submit the form becuase it contains validation errors.  Errors are marked with either a red asterisk (required fields) or a red, dashed border (invalid values).

    When the user ignores these messages and closes the form manually then nothing is submitted, but they think a request has been submitted and they ask why no email has shown up...."There must be an issue with the request form becuase the email request was never received."    **I roll my eyes**

    Any ideas on how to "outsmart" the users and force them to submit a completed form or if they manually close the form give them a dialoge box message telling them that nothing has been submitted?  I thought I had my bases covered her, but I guess not.  Some ideas would be welcome.

    Maybe I just need smarter users  *lol*               Quite frustrating really.

  • 05-21-2007 11:48 PM In reply to

    Re: Validate form on Submit

    In my oppinion the best practice for these situations always is to not enable the submit button unless all other required actions are performed or mandatory fields are filled. Set conditional formatting on your button and check there if this is the case and then enable the button.

    Would this help in your scenario as well.

    Listen to Motörhead cos they play Rock'n Roll :)
  • 05-22-2007 02:59 PM In reply to

    Re: Validate form on Submit

    Thanks nukkumatti. 

    Anyway to do this so that I don't have to have the Submit button look at every required field independently to ensure it is completed?  My thought was to not even have the section containing the Submit button visible until all validation errors are cleared, but is there a way to do this easily?  Again witout looking at each required field independently?

  • 06-27-2007 12:26 AM In reply to

    Re: Validate form on Submit

    Yes there is a way to do this easily. From within you button OnClick event use something like the following: var error; error = XDocument.Errors.Count; if(error != 0) XDocument.UI.Alert("You have not filled all requried fields"); else.... Errors.Count won't be zero until all your fields which are set to mandatory or have data validation on it are filled correctly. Hope this helps, sorry for the late reply.
    Listen to Motörhead cos they play Rock'n Roll :)
  • 07-03-2007 03:09 PM In reply to

    Re: Validate form on Submit

    Nukkamati's code worked great.  I got the message pop-up just like I wanted.

    Does anyone now know how I can use the error = XDocument.Errors.Count; if(error != 0) and Conditional Formatting to also disable the Submit button until the error count = 0?

    The reason I am asking is becuase I will want to change views on Submit and I don't want to changes views unless the form is validated and Submitted.  I tried creating a text field to capture the error count and then have the Submit Button conditional formatting look at that field, but I couldn't get it to work.

  • 07-03-2007 10:37 PM In reply to

    Re: Validate form on Submit

    Add a dummy field to your datasource and set its default value to disabled. in the operation where you check if error != 0 set the value of the dummy field to enable if error = 0. set  conditional formatting on you button and disable it if dummy is equal to disabled. 
    Listen to Motörhead cos they play Rock'n Roll :)
  • 07-06-2007 09:06 AM In reply to

    Re: Validate form on Submit

    Thanks nukkamatti

    I understand how to create the dummy field, but when you say "disabled" do you mean "read-only" or something else?  Also, when I set the dummy field switch to "enabled" if errors = 0 how do I do that, via rules or using code?  If using code it would be something like;

    function ErrorChecking()

    {

    var DummyField = XDoucment.DOM.selectSingleNode("//my:txtDummyField");

    var error; error = XDocument.Errors.Count;

    if(error != 0) XDocument.UI.Alert("You have not filled all requried fields") DummyField = "disabled";

    if(error= 0) DummyField = "enabled"

    }

    Excuse my ignorance, but I am still learning so I don't know the proper syntax for how to set the DummyField to be disabled or enabled.  A little help would be great there.

    Thanks again.

  • 07-08-2007 11:15 PM In reply to

    Re: Validate form on Submit

    Hi, set the default value of your dummy field to "disabled". Add conditional formatting to your button which says "If dummy is equal to disabled" then disable this control. now in your function ErrorChecking you say if(error == 0) XDocuemnt.DOM.selectSingleNode(my:myFields/my:dummy).text = enabled; this should work I guess. Just let me know if you have any further problems.

    Listen to Motörhead cos they play Rock'n Roll :)
  • 07-09-2007 12:35 PM In reply to

    Re: Validate form on Submit

    Hi Nukkamatti,

    Vielen dank für die Hilfe.  It took some work getting the code just right, but I finally got it.  Here is how it turned out:

    function CTRL613_5::OnClick(eventObj)

    {

    var error; error = XDocument.Errors.Count; if(error != 0) XDocument.UI.Alert("You have not filled all requried fields");

    if(error == 0) XDocument.DOM.selectSingleNode("/my:myFields/my:Error").text = "enabled";

    }

    I created a new button named "Check for errors" this button is visible as long as the "dummy" field is disabled then once error count = = 0 then the dummy field = enabled, the Check for Errors button (it is within a section) is hidden and then the section containing the Submit button is then visible.  :)

    Tchüß

  • 07-10-2007 01:22 AM In reply to

    Re: Validate form on Submit

    Good work. Glad I could help. Cheers
    Listen to Motörhead cos they play Rock'n Roll :)
  • 07-13-2009 04:58 PM In reply to

    Re: Validate form on Submit

    I am not able to pass text to the button using this approach. If anyone using this approach, please let me know.

  • 10-30-2013 10:04 AM In reply to

    • ehaze
    • Top 500 Contributor
    • Joined on 12-11-2007
    • Posts 49

    Re: Validate form on Submit

    is there a way to access XDocument.Errors.Count without using code? my hope is to set a fields default value to XDocument.Errors.Count.
Page 1 of 1 (12 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.