How can I save and redirect to a home page

  • 0
  • 1
  • Question
  • Updated 5 months ago
  • Answered

I'd like to save data input into a form and then return users to a specific page after clicking "save" on a custom button. My button works great - just don't know how or where to add the code to then redirect url to the home page.

Photo of Betsy

Betsy

  • 0 Points

Posted 5 years ago

  • 0
  • 1
Photo of QuickBasePros_IDS

QuickBasePros_IDS, Champion

  • 2,908 Points 2k badge 2x thumb
Photo of Stephanie

Stephanie

  • 732 Points 500 badge 2x thumb
I have done this and it works great however I would also like to add the record ID of the saved record on the html page the person is redirected to, any insight on this?
Photo of Jeremy

Jeremy

  • 0 Points
Try this

onclick='var url = [insert your homepage url here]; document.getElementById(\"RedirectURL\").value = url; DoSave();
Photo of QuickBasePros_IDS

QuickBasePros_IDS, Champion

  • 2,908 Points 2k badge 2x thumb
Did you test this?
Photo of Jeremy

Jeremy

  • 0 Points
It's similar to a button I've set up with the code below (which works), so should work:

<div class='button' onclick='var url = \"[url for a page]\"; document.getElementById(\"RedirectURL\").value = url; DoSave();'>Save</div>
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 29,664 Points 20k badge 2x thumb
I don't think the above code will work. The hidden field RedirectURL is only used to control the redirection process when the hidden field rl is empty (and if you are coming from a report listing page it will not be). So you also have to set the rl field to an empty string to make the redirection process work. Complicating this somewhat is the fact that the RedirectRUL <input> has and id attribute while the rl <input> has only a name attribute. All these oddities combine to make forcing JavaScript into the formula language a small nightmare to edit without creating a typo.

You are better off using the UNOB technique to make your QuickBase formula dead simple and throw all the logic and processing into module.js using the image onload technique.

UNOB Technique
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=371

If you have not familiar with this approach you may think I am complicating the problem - nothing could be further from the truth. Once you set up the image onload technique all you future customizations become easy to implement. You will be amazed at what these techniques can do for you - all  problems solved in a few lines of script.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 29,664 Points 20k badge 2x thumb
I still think you should use the UNOB technique but if you are dead set on using an onclick attribute here is a nice trick to get the redirect to work in all circumstances.

It is a little know fact but all modern browser automatically create global variables for every element with an id attribute. This means that there is already a global variables for RedirectURL and you don't even have to call getElementByID("RedirectURL"). You can just set its value with this simple statement:

RedirectURL.value=[insert your homepage url here];

Browsers do not automatically create a global variable for all elements with a name attributes - but they do for named forms (and a few others). So you can access the hidden rl name attribute as follows and set it to an empty string:

editform.rl.value="";

These are the two conditions you need to setup to gain full control of the redirection process QuicBase uses. So if you are dead set on using an onclick handler this should work under all conditions:

<div class='Vibrant Success' onclick='RedirectURL.value=[insert your homepage url here];editform.rl.value="";DoSave();'>Save</div>