Data Validation and Redirect to page in a SharePoint New form

Posted: August 1, 2010 in SharePoint, SharePoint Designer
Tags: , ,

Hi !

You now that you can use a Data view to create SharePoint Forms. You choose your columns and select insert as new item and …

But there is a problem here that some validation does not work in this mode. for example DropDown or radio button required fields buttons does not validate correctly. In the other hand the good thing is that you can use your custom form action and for example commit the changes and navigate to another page.

When you use a custom web part ( Inser -> SharePoint Controls -> Custom List Form ), the good thing is that all validations work fine but you can’t redirect to another page after submitting data. The RedirectUrl property of the button also didn’t work for me. I don’t know why.

So the question is how can we have a form with complete validation and redirecting after submit ?!

I searched a lot find some solutions. I solved my problem by combining a custom form web part with a custom action button and changing in it’s code like this :

  1. You use Custom List Form and Use NewItem form. Now your validation works fine and you do not need to use custom JavaScript validations.
  2. to navigate to another page after submitting data don’t use the RedirectURL property of the form button.
  3. Insert a Form Action button in the page and change the hide property of the previous submit button to True. Now we can use the “Navigate to page” action of the new form action button. BUT it does not validate the form correctly so you should do a little change in the code. you have access to it’s java script code.
  4. the original code is like this :
    onclick=”javascript: {ddwrt:GenFireServerEvent(‘__commit’)}”
    you should change it and add this code in the middle :
    onclick=”javascript: if (!Page_ClientValidate()) return false; {ddwrt:GenFireServerEvent(‘__commit’)}”
  5. for the “navigate to page” action if it didn’t work correctly. You should also change the URL in the code like this. in my case:
    onclick=”javascript: if (!Page_ClientValidate()) return false; {ddwrt:GenFireServerEvent(‘__commit;__redirect={/en/Documents/Forms/Upload.aspx}‘)}”

now save and preview your page. I did it and everything worked like a charm. GOOD LUCK !

Advertisements
Comments
  1. Sandeep says:

    I am able to save with out entering required fields

  2. Eduardo Ferreira says:

    Its not Working here too!!!

  3. Clem says:

    Page_ClientValidate is not a valid function. Throws javascript error.

  4. Apparently it does not work on newer sharepoint versions, like 2013.

  5. nadeem says:

    Worked like a charm for me in 2010 – I spend 4 days trying everything from PreSaveAction to JQuery to all sorts of other scripts and nothing would work – before giving up searched google one last time and came across this page.. You are a savior – kudos !!!! thanks.

  6. shweta says:

    any solution for sharepoint 2013

  7. any solution for sharepoint 2013

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s