Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Two submit buttons on a grid page with two different target pages. A tested solution

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Two submit buttons on a grid page with two different target pages. A tested solution

    I have been obsessed with putting a second submit button on an a5w page with a standard grid component, with each submit button saving the data and then loading a different page depending on which button was pressed by the user. This would allow one button to reload the same page (save and continue) and the other button to load a menu (save and exit). Using Ajax I have been able to do this and I have tested this code on a localhost and a remote server using the WAS ver 9. It requires several files on the server and does carry some overhead but the results seem worthwhile.
    Create a standard grid component and place it on an a5w page (in this example called g_onepg.a5w and the grid component name is grd_one) but set the target page after submit to a particular file, which I call redirect.a5w (instead of <self>). The file redirect.a5w, refers to a session variable and contains nothing but the following code added to the head and body section (title, link and meta name section were unchanged and not included here):

    <html><head>
    <%A5
    target = "window.location.replace("+s_quote(session.redtarget)+");"
    ?"<script type='text/JavaScript'>"
    ?"function doRedirect()"
    ?"{"
    ?target
    ?"}"
    ?"</script>"
    %>
    </head>
    <body onload="doRedirect()">
    </body></html>

    When the application server sends that file it first writes it as a file containing standard javascript. When the user presses the grid submit button that file loads and immediately redirects to the file named in the session variable. The screen does flash momentarily. The session variable is set using Ajax. In the a5w page (g_onepg.a5w) containing your component, place the following code in the head section:

    <script type="text/javascript">
    var xhr1 = false;
    if (window.XMLHttpRequest) {
    xhr1 = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    xhr1 = new ActiveXObject ("Microsoft.XMLHTTP");
    }
    xhr1.open("GET", "setg_onepg.a5w", false);
    xhr1.send(null);
    </script>

    In this case I want to reload the same page so the file setg_onepg.a5w contains the code:

    <html>
    <head>
    <meta name="generator" content="Alpha Five HTML Editor Version 9 Build 2095-3264">
    <title></title>
    </head>
    <body>
    <%A5
    delete session.redtarget
    dim session.redtarget as c = "g_onepg.a5w"
    %>
    </body></html>

    When the app server sends this file it sets the session variable, which redirect.a5w will read later, in this case the name of the page with the grid component.

    I also have another file on the server to set the session variable to a different target in this case called set_onemenu.a5w with the code:

    <html>
    <head>
    <meta name="generator" content="Alpha Five HTML Editor Version 9 Build 2095-3264">
    <title></title>
    </head>
    <body>
    <%A5
    delete session.redtarget
    dim session.redtarget as c = "onemenu.a5w"
    %>
    </body></html>

    Back in the a5w file (g_onepg.a5w) containing the component the following code is placed in the body section (at the bottom after the grid component, named grd_one):

    <script type="text/javascript">
    function settarget(){
    var xhr2 = false;
    if (window.XMLHttpRequest) {
    xhr2 = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    xhr2 = new ActiveXObject ("Microsoft.XMLHTTP");
    }
    xhr2.open("GET", " set_onemenu.a5w ", false);
    xhr2.send(null);
    }
    </script>

    <div align=center>
    <input type="button" value="Submit and Exit" onClick="settarget();document.forms['grd_one'].grd_one_Button_Submit.click()" style="BORDER-BOTTOM: 1px solid; BORDER-LEFT: 1px solid; BACKGROUND-COLOR: #f9ead6; BORDER-RIGHT: 1px solid; BORDER-: 1px solid">
    </div>

    You can check the name of the component and the submit button by reading the source code of the web page downloaded to your browser. I have left in my design for the button. When the user presses this button the onclick event first calls settarget which requests a file from the server which also sets the session variable to the name of the new target such as the menu screen. The onclick event then continues (the order of the two calls does matter) to simulate a click of the standard submit button in the grid. This allows validation and data update to take place. The redirection then follows.

    I have tested this code but cannot assure that it is bullet-proof. It does check to see if the browser is new or older than IE7 but does not use try-catch or other error routines. The open(�GET�false) means that the javascript waits for the server to return the file instead of the more popular asynchronous method, but there is nothing to do but wait anyway.

    I hope you find this useful and I really look forward to hearing the results of others testing this code and improvements that I am sure they will add . If you see or foresee bugs or problems please post them. I expect these two buttons will prevent users from losing data by exiting a grid without a save.

    #2
    Re: Two submit buttons on a grid page with two different target pages. A tested solu

    Irwin - I know from firsthand experience that it takes a lot of time and perseverance for what you did. Thanks for all of that, and taking the additional time to share.
    -Steve
    sigpic

    Comment


      #3
      Re: Two submit buttons on a grid page with two different target pages. A tested solu

      Hey I found a bug (of course) but I think I found a fix (I hope). It has to do with the browser cache. As the user presses the �Submit and Continue� and the �Submit and Exit� buttons, the files setg_onepg.a5w and set_ onemenu.a5w are sent from the server and eventually end up in the browser cache. At that point the browser no longer asks the server to re-send them and so the server never changes the value of session.redtarget and the redirection fails. There are a few solutions. We can turn off browser caching (as I had in my testing) but we can not force users to do that so that�s out. The cache-control no-cache directive should work, but I could not get it to work. Finally we can make the browser think it�s requesting a different file with each request and it is not in the cache so the request is sent to the server every time. That seemed to work. I did that by appending a query string to the name of the requested file. So setg_onepg.a5w became setg_onepg.a5w?1234 and the same for set_onemenu.a5w. The query string in this case is ignored by the WAS and the requested files are returned from the server. The number in the query string is a random number so the copy of the file in the cache is never used

      The script at the top of the a5w file (g_onepg.a5w) gets a random number (rn1) and addition of the query string to the requested file name and becomes:

      <script type="text/javascript">
      var xhr1 = false;
      var rn1 = Math.floor(Math.random()*1000);
      if (window.XMLHttpRequest) {
      xhr1 = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
      xhr1 = new ActiveXObject ("Microsoft.XMLHTTP");
      }
      xhr1.open("GET", "setg_onepg.a5w?"+rn1, false);
      xhr1.send(null);
      </script>

      Likewise the script at the bottom of the file becomes:

      <script type="text/javascript">
      function settarget(){
      var xhr2 = false;
      var rn2 = Math.floor(Math.random()*1000);
      if (window.XMLHttpRequest) {
      xhr2 = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
      xhr2 = new ActiveXObject ("Microsoft.XMLHTTP");
      }
      xhr2.open("GET", "set_onemenu.a5w?"+rn2, false);
      xhr2.send(null);
      }
      </script>

      That tested well with table updates and redirection.

      As an aside I added the text �Please wait �.� for output in the body section of the file redirect.a5w. This made the screen flash less jarring.

      And thank you Steve for your kind comments. It is people like you and others in this forum that have helped me countless times. And sharing here is a little self-serving. I want to put this code in production and if others find bugs or have suggestions I would really appreciate it.
      Thanks,
      Irwin

      Comment


        #4
        Re: Two submit buttons on a grid page with two different target pages. A tested solu

        Hi,

        I know this is an old thread, but does anyone know what this section should look like? It appears that the question marks should not be there...

        <html><head>
        <%A5
        target = "window.location.replace("+s_quote(session.redtarget)+");"
        ?"<script type='text/JavaScript'>"
        ?"function doRedirect()"
        ?"{"
        ?target
        ?"}"
        ?"</script>"
        %>
        </head>
        <body onload="doRedirect()">
        </body></html>

        Thanks,

        Denis

        Comment


          #5
          Re: Two submit buttons on a grid page with two different target pages. A tested solu

          Hi Denis
          The question marks are real and should be there.
          As the server creates the actual page to send to the client it finds the <%A5…%> section and in this section the sever actually writes the javascript function code to include in the page, using xbasic. The question mark acts just like in the interactive window as an xbasic print command. So the following code:

          <html><head>
          <%A5
          target = "window.location.replace("+s_quote(session.redtarget)+");"
          ?"<script type='text/JavaScript'>"
          ?"function doRedirect()"
          ?"{"
          ?target
          ?"}"
          ?"</script>"
          %>
          </head>
          <body onload="doRedirect()">
          </body></html>

          produces a web page that reads:

          <html><head>
          target = "window.location.replace("+s_quote(session.redtarget)+");"
          <script type='text/JavaScript'>
          function doRedirect()
          {
          target (this will be the value of the session.redtarget variable)
          }
          </script>
          </head>
          <body onload="doRedirect()">
          </body></html>

          But although this code works as described I have found an easier and more flexible way to do the same thing. That is in the thread: A custom control that can access the data on a form using javascript
          (https://forum.alphasoftware.com/show...ing-javascript)

          That post describes a custom control that can set the value of another control on the component and then submit the form. In the validate and after validate sections the value of the control can be read and the response.redirect("somepage.a5w") set as you wish. The same type of inline javascript can be included in the free form section below the grid. I now use this extensively to have several buttons on a component which close the component with different processes or target pages. If you wish I could make a sample db with that code to send you. But is not what you asked so I will leave it up to you.
          Thanks for your interest,
          Irwin

          Comment


            #6
            Re: Two submit buttons on a grid page with two different target pages. A tested solu

            Hi Irwin,

            Thank you for confirming the code.

            I have a tabbed gridlinker. If a user updates the grid and then selects another tab before the form is submitted, the data is lost due to the refresh. The only reasonable option I can think of is the user can have a button called 'Save and Continue', this way the user can update the form then save then select another tab.

            I think what you are proposing will do the trick, as in addition I will need a 'Save and Exit' button. If you have a mini db that demonstrates this, would be really useful.

            Denis

            Comment


              #7
              Re: Two submit buttons on a grid page with two different target pages. A tested solu

              Hi Denis
              I put together a sample db with a two a5w pages that have examples of multiple buttons to 1) Save and Continue, 2) Save and Exit and 3) Quit, No Save

              I put a folder in the webroot called demo2button and made that the target folder.

              Page0 is the "main menu" which for this example I call manually in the browser with http://localhost/demo2button/page0.a5w

              Form1 on page1 is a grid component
              Here I used javascript in the free form edit region below the grid.

              Form2 on page2 is a dialog component
              Here I used javascript in the 2 custom controls.
              You could also include some in the free form edit region below the grid.

              Since a custom control appears on every line of a grid, you can only use the custom controls for grids where only one record is shown.

              You can put all sorts of code in the after validate event based on which button was pushed as indicated by the value in the control, signal or signal1. That in addition to setting the target page after the save.

              I do not know why but I had to use different names for the fields in the two forms else there were some weird interactions if one was run before the other and signal was a control in both. Watch out for case as javascript cares about that.

              I hope this is helpful and of course let me know of any bugs.
              Irwin
              Attached Files
              Last edited by irwincohen; 08-08-2012, 10:17 AM. Reason: Changed the uploaded db. Found css error.

              Comment


                #8
                Re: Two submit buttons on a grid page with two different target pages. A tested solu

                Thanks for your time Irwin. It is very much appreciated. I did try to get this working in my tabbed grid linker without success. I will keep trying and let you know the outcome.

                Denis

                Comment

                Working...
                X