Formula URL button - save and redirect

  • 0
  • 1
  • Question
  • Updated 1 month 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.

https://sparkav.quickbase.com/db/bnzwm7ykp?a=nwr&ifv=20

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!

Thanks,
Elisha
Photo of Elisha Tenenbaum

Elisha Tenenbaum

  • 194 Points 100 badge 2x thumb

Posted 2 months ago

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

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 28,304 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 = "https://ibm.com";
});

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 ibm.com.

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"; 

-Sharon

Photo of Elisha Tenenbaum

Elisha Tenenbaum

  • 194 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

  • 27,694 Points 20k badge 2x thumb
I pasted the code into the console and it worked for me unchanged:

https://sparkav.quickbase.com/db/bnzwm7ykp?a=dr&r=p
(Edited)
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,842 Points 50k badge 2x thumb
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;

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

Photo of Elisha Tenenbaum

Elisha Tenenbaum

  • 194 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 ibm.com 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?

Thanks!
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).

-Sharon
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,842 Points 50k badge 2x thumb
Try my suggestion, it’s stupid simple.