Forum Discussion

BetsyBetsy's avatar
BetsyBetsy
Qrew Member
12 years ago

How can I save and redirect to a home page

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.

    • StephanieHarris's avatar
      StephanieHarris
      Qrew Assistant Captain
      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?
  • Try this

    onclick='var url = [insert your homepage url here]; document.getElementById(\"RedirectURL\").value = url; DoSave();
  • 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>
  • 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.
  • 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>

    • MikaelAndreasso's avatar
      MikaelAndreasso
      Qrew Member
      Is there any special consideration to be taken when I am attemping to save and then redirect into an API call?

      I am trying to save a grid edit report that is placed inside a from and then create a new record in another form.

      ------------------------------
      Mikael Andreasson
      ------------------------------
      • MarkShnier__You's avatar
        MarkShnier__You
        Icon for Qrew Legend rankQrew Legend
        The easiest way is to have this syntax for the initial edit button

        var text EDIT = the url to edit

        var text Next = the url where you want to go to

        $EDIT
        & "&NextURL+" & URLEncode($Next)

        ------------------------------
        Mark Shnier (YQC)
        Quick Base Solution Provider
        Your Quick Base Coach
        http://QuickBaseCoach.com
        mark.shnier@gmail.com
        ------------------------------