Save button redirect

Dec 22, 2010 at 9:48 PM

I have a custom list where I want to change the behavior of the "Save" button in newform.aspx based on the contents of a dropdown box.

Basically, if this field = A, redirect to PageA when they click "Save" or if the field = B, redirect them to PageB.  Can this be done?  Im running SP2010.

Dec 23, 2010 at 1:08 AM
Edited Dec 23, 2010 at 1:09 AM

If you are using the OOTB form or a custom form that is not an xslt data view, you can declare a JavaScript function called 'PreSaveAction()' on the page. This function is called natively by the "<SharePoint:SaveButton..." so you can perform your validation within that function. Returning true saves the form, false cancels the save, ostensibly to allow the user to review error messages and make corrections.

If you are using a custom form that you have converted to a data view, you can append your function to the existing onclick() function of the button in the html, and call a function that performs the validation. i.e. onclick="javascript: {ddwrt:GenFireServerEvent('__commit')};redirectFunctionGoesHere()"

I'm running WSS 3 and haven't tested this in 2010 yet, but this should work.

Dec 23, 2010 at 1:47 AM

Good stuff, mrSPARQLE.

The complication would be if mpeterson79 wanted to pass the newly-created item ID to PageA or PageB. That would mean adapting SPRedirectWithID to contain the logic, or at least to have some post-processing for it.


Dec 23, 2010 at 1:55 AM

Very good point, Marc. Thanks for pointing that out. 

Dec 23, 2010 at 2:16 PM

Yes, I will want to redirect to another newform.aspx in another list with the same ID. 

I have 4 Lists:  RMA Entry, Rental Return RMA, Customer Serivce RMA, Customer Complaint.  User fills out the form in the RMA Entry list and selects the type of RMA, Rental Return, Customer Service Return or Customer Complaint.  I have a field within this form that assigns a unique RMA # to the item once the form is saved.  If someone selects "Rental Return" for the RMA type and they click 'Save', I want it to redirect them to the newform.aspx in the list called 'Rental Return RMA' so they can enter in the details.  I want the RMA ID that was assigned to be automatically transferred over to this form.  If someone selects "Customer Service Return" as the RMA type, I want it to do the same thing, just redirect them to the newform.aspx in the 'Customer Service RMA' list.

Dec 24, 2010 at 4:03 AM

I'm wondering if it doesn't make more sense to have one list with three Content Types (Rental Return RMA, Customer Serivce RMA, Customer Complaint). You could build a base Content Type of RMA and then have all three of the other Content Types inherit from it. That way you ensure consistent based metadata, with the customized metadata for each of the three variants.


Mar 13, 2011 at 4:02 AM

Here's a method posted on Alexander Bautz's blog:

Mar 13, 2011 at 8:24 AM

I just saw this and have to agree with Marc on this. This is what content types are good for and they really work!