Formula URL button - save and redirect

  • 0
  • 2
  • Question
  • Updated 2 months ago
  • Answered

Hi there

I’ve created a form accessible to “everyone on the internet” for our clients to submit service requests. I added “&ifv=20” to the url to hide the qb branding. However, doing this causes the save button to become hidden. I created a formula url button that will save it  using this javascript I found on the forum:

var text URL = "javascript:void(DoSaveAdd())";var Text Image = "<a id='saveButton' class='Vibrant Success' onclick='DoSaveAdd()' href='#'>Submit</a>";"<b href =" & $URL &">" & $Image & "</b>"

My problem now is how do I get the page to redirect after the form is saved. Here’s a link to the form, you can try it and see what happens.

I'd like it to redirect to an external webpage. If that is not natively possible than I'd like it to redirect to a rich text page I've created in quickbase.

Any help with this would be greatly appreciated!

Photo of Elisha Tenenbaum

Elisha Tenenbaum

  • 214 Points 100 badge 2x thumb

Posted 10 months ago

  • 0
  • 2
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,434 Points 20k badge 2x thumb
Submit the form with script using FormData:

var editform = document.getElementsByName("editform")[0];
var formData = new FormData(editform);
formData.set("subact", "save");

window.onbeforeunload = null;

fetch("bnzwm7ykp?a=FinishEditRecord", {
  body: formData,
  method: "POST",
  credentials: "include"
}).then(function(response) {
  document.location.href = "";

This script (1) creates a FormData object equivalent to the QuickBase form, (2) sets the subact hidden field to "save" and (3) submits the from via fetch which returns a promise. When the promise resolves, the page redirects to

Speaking of promises, I got to get me a one of those big async yard signs:

You can add a redirect in your formula by replacing $URL with

$URL & "&rdr=" & $URLTWO

You'll then need to add another variable for URLTWO (var text URLTWO = )

You are correct that you cannot redirect outside of QuickBase, so URL TWO would be something like this (where the pageID=3 is replaced with your pageID).

URLRoot() & "db/" & Dbid() & "?a=dbpage&pageID=3"; 


I was recently asked about the code I provided here and I have a better alternative using the onclick method below.

var text SAVE = "onclick=\"$('#saveButton').click()";
var text REDIRECT = URLRoot() & "db/" & Dbid() & "?a=dbpage&pageID=2"; 

"<a class='Vibrant Success' & " & $SAVE & "; window.location.href=' "& $REDIRECT &" '\">SAVE & Go to Page</a>"
Photo of Brian Cafferelli

Brian Cafferelli, Quick Base Technical Marketing Manager

  • 1,698 Points 1k badge 2x thumb
You can actually do this without using JavaScript as well.

You'll need to use the table setting called "Save parent record automatically when a child record is created." When this box is checked for your table, any time has the form open for adding / editing a record, and they click a link, they won't get the pop-up window asking if they want to save the record first. Instead, the user will see the "Saving" message briefly, then they will be redirected based on whatever link they clicked.

You can use standard a Formula - URL here, which essentially becomes your own custom save button. Without needing to call DoSaveAdd.

Thanks Brian!

I was actually working with someone who had a Save & Redirect formula that was working that did not explicitly have Save included... I was baffled for a bit then realized they had this setting you mentioned engaged. 

Great call out!
Photo of Elisha Tenenbaum

Elisha Tenenbaum

  • 214 Points 100 badge 2x thumb
Thanks Dan!

I'm getting a syntax error on the period in the first line of the script.
Is there a change that needs to be made to the code?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
I pasted the code into the console and it worked for me unchanged:
Elisha, there is possibly an easier solution.

Your "add record" can specify where to go to upon Save.  ie the NextURL.

var text ADD = URLRoot() & "db/" & [_DBIDxxxx] & "?API_GenAddRecordForm&ifv=1":

var text RedirectTo = the url to redirect to;

& "&NextURL=" & URELEncode($RedirectTo )

Photo of Tate Forgey

Tate Forgey

  • 712 Points 500 badge 2x thumb
I've never quite understood how redirects work and I could not get any of these solutions to work for me.  I created a URL button intended to be used in the edit view of a form that has "ifv=0" added.  No matter what I try to put in the "&NextURL" portion of this I am always just redirected to the dashboard of the app.  I don't know why.  Why?!?!

HOWEVER, if I make sure that the "Save parent record automatically" is checked in the table's advanced settings I simply put the URL I want to redirect to in the button.  The record saves on it's own because that setting is engaged and I end up at the redirect page.  Great!  BUT.....

These buttons do not work on mobile.  The last button I describe with the URL I want end up shows in the edit view in mobile (I haven't seen any buttons that shows up in a report) and successfully redirects to the URL. but for reasons I don't understand the record does not save.  Why?!?!

Any ideas about how I can get a save and redirect to work in mobile?
I can't help you for the mobile question but if you have a question about Desktop mode i can try to help.  I'm not sure from your post above what specific question you have what your current non working code is.
Photo of Tate Forgey

Tate Forgey

  • 712 Points 500 badge 2x thumb
Thanks, Coach.  Let's start with the code that is your response here.  Is this a button you would put on a dashboard?  That API is going to generate the form to add a record, right?  So, it seems like it doesn't make sense to put it on a record, but maybe I'm wrong about that.

I'm looking for a situation where I open the edit view of a record, then someone edits the record and I replace the save button with a button that saves and redirects to a rich text page I have created.  Is this type of code the way I would do that?
Photo of Elisha Tenenbaum

Elisha Tenenbaum

  • 214 Points 100 badge 2x thumb

Hi there

My apologies for the delayed response. I'm new to javascript & quickbase and at the time of my initial posting these responses were beyond my skill level. 

I've advanced a little and decided to give these solutions another go. I’m not sure how & where to plug in these different lines of code. 

I tried putting Dan’s code 
1) directly into a formula-url field and I get a syntax error. 
2) directly into a formula-rich text I’d be redirected to whenever I viewed a record
3) into a javascript page and loading it via iol and it would save the record but the redirect wouldn’t work

Similar challenges with Sharons & QBChampions solutions. I'm no sure how/where to put together and plug in the code.

I've had a bunch of success using some IOL scripts for other issues.

Any guidance on how to plug in your answers?

Both my and Mark's (QB Coach) suggestions work in the Formula URL field.

Here is the formula I suggested more explicitly written out using your inital formula as a base:

var text URL = "javascript:void(DoSaveAdd())";
var text URLTWO = URLRoot() & "db/" & Dbid() & "?a=dbpage&pageID=3"; 
var Text Image = "<a id='saveButton' class='Vibrant Success' onclick='DoSaveAdd()' href='#'>Submit</a>";
"<b href =" & $URL & "&rdr=" & $URLTWO &">" & $Image & "</b>"

(where the pageID=3 is replaced with your pageID).

My suggestion was this

Do not make a custom save button, but rather have the user launch the Add Record off this formula URL button

var text ADD = URLRoot() & "db/" & [_DBIDxxxx] & "?API_GenAddRecordForm":

var text RedirectTo = the url to redirect to;

& "&NextURL=" & URELEncode($RedirectTo )

You can build that button on a any record and copy the generated code and paste it into a dashboard button.  The formula with them calculate the URLEncoding.

Try my suggestion, it’s stupid simple.