locked
Infopath close form dilemma RRS feed

  • Question

  • I have an infopath form browser enabled. The last step is to validate data input and either camcel or submit form based on validation result.

    1. I tried to use Submit button with customer action code. 

    The problem is that when my validation returns false and I wanted to cancel the submission, I get 'There has been an error while processing the form'.   I can't customize the error message. I tried 'e.CancelableArgs.Message'.  It seems not working on the browser version

    2. I tried to use button to send form.

    2.1 I can't close form after submission using C# code. this.Application.Quit not working on browser version. I tried to redirect to another page. I used response.redirect and sputility.redirect.  Infopath doesn't allow you to fully redirect page. I can redirect to external site, but not sharepoint. And even it redirects to an external page, but the url will remain the same.

    2.2 I tried to use rule to close form. But rule is always executed before my code. The validation code is totally ignored.

     


    • Edited by lcha Monday, June 6, 2011 9:55 PM
    Monday, June 6, 2011 4:21 PM

Answers

  • Do you really need code for this?  InfoPath already validates data when you submit, and if validation passes, it submits (and closes if you tell it to).  If the validation doesn't pass, then it shows an error with the invalid field and lets the user continue.  Isn't that the same thing you're trying to do with code?

    What I do is add conditional formatting to my submit button so that it's not even active unless all validation is met so that my users can never submit mistakenly.


    SharePoint Architect || Microsoft MVP || My Blog
    Planet Technologies || SharePoint Task Force
    • Marked as answer by Leoyi Sun Tuesday, June 14, 2011 9:21 AM
    Tuesday, June 7, 2011 4:37 AM
  • That's why I asked if code was needed, because he hasn't mentioned what else the code does.  If the code is only for validating the submit, then maybe it can be avoided.
    SharePoint Architect || Microsoft MVP || My Blog
    Planet Technologies || SharePoint Task Force
    • Marked as answer by Leoyi Sun Tuesday, June 14, 2011 9:21 AM
    Tuesday, June 7, 2011 1:33 PM

All replies

  • Have you tried the plain old:

    this.close();

    That's what I typically use, but I haven't tried it on a browser form yet.

    Monday, June 6, 2011 5:19 PM
  • I tried this.Application.close.  It is not working on browser enabled form.
    Monday, June 6, 2011 9:57 PM
  • don't use the "application" part.  If you think about it they're not actually in a client application - they're in the browser, so you don't want to close an application.  Just try (don't add anything to it):

    this.close();

     

    Tuesday, June 7, 2011 12:00 AM
  • Do you really need code for this?  InfoPath already validates data when you submit, and if validation passes, it submits (and closes if you tell it to).  If the validation doesn't pass, then it shows an error with the invalid field and lets the user continue.  Isn't that the same thing you're trying to do with code?

    What I do is add conditional formatting to my submit button so that it's not even active unless all validation is met so that my users can never submit mistakenly.


    SharePoint Architect || Microsoft MVP || My Blog
    Planet Technologies || SharePoint Task Force
    • Marked as answer by Leoyi Sun Tuesday, June 14, 2011 9:21 AM
    Tuesday, June 7, 2011 4:37 AM
  • Clayton, it sounds like the issue is that lcha has code on the submit button that does other things.  And if you use a rule to close the form on the button the code doesn't get executed since rules are always ran before the code.  I like your idea of making the submit button inactive until all validation is met.
    Tuesday, June 7, 2011 12:25 PM
  • That's why I asked if code was needed, because he hasn't mentioned what else the code does.  If the code is only for validating the submit, then maybe it can be avoided.
    SharePoint Architect || Microsoft MVP || My Blog
    Planet Technologies || SharePoint Task Force
    • Marked as answer by Leoyi Sun Tuesday, June 14, 2011 9:21 AM
    Tuesday, June 7, 2011 1:33 PM
  • I had that problem and resolve with:

    - Disable the ribbon or toolbar.

    - Create a button with action submit, and put the code that I want in the "Perform custom action using code". You can also select "After submit" with "Close the form"

      In the code, if tha submit was made with sucess, add the next line:

      "e.CancelableArgs.Cancel = false;"

    - The button is only enabled with rules created with conditions based in others fields (like field xxxxx is not blank, etc).

     Carlos

    Tuesday, June 7, 2011 10:55 PM
  • I've used a bit of a workaround in a similar situation, I wasn't validating but I had to run code on pressing the submit button and then close. Of course you can't close from the code, and if you have a close rule on the button it (usually) closes the form before the code executes.

    So I cheated, and when the button is pressed I run my code, it submits the form, and then I switch to a different view in the form which displays something like "The form has been submitted, thank you" and a close button underneath which just uses the standard close form rule. I thought the users would complain about the extra click, but they were unanimously delighted with the extra feedback confirming that the form was submitted rather than it just dissapearing. I'm considering using this even when I don't really need to :)

    Wednesday, June 8, 2011 4:27 PM