SBUSA Question - Need a clean example for PostMessage functionality

  1. In the SBUSA site (still under development), I need some help with a clean example: I have looked through many posts with examples that talks about PostMessage, Onmessage and so on… but none of the examples provide a clear understanding of what portion of code goes where. (May be I am so naive with JS).
    Here is what I am trying to achieve :
    Page1 : I created several User Input fields to accept personal details such as name, phone, address and so on. Along with it I also added two more input fields Donation Amount, and Donation Frequency. Then there is a button called “Donate Now”. The idea is once the user enters the personal details and Clicks the Donate Button it must do two things:

  2. it should save the data in a dataset. This I could accomplish well - created a database table and connected the fields to it. So no problem there.

  3. it should open a PayPal link and passing the “Donation Amount”. - This I could not accomplish and need help . For this part I tried the following with no good outcome.

  • Added a Pay Pal link on the “Donate Now” button. But not sure how to pass the amount as parameter; Also it takes me to PayPal screen, but does not save the data in the dataset (seems like the link takes precedence over saving the data).

  • Trying to create a new Page (Page2) where I can display all the data from Page1 as read only and create another PayPal button. I guess this is where I must use PostMessage() and OnMessage() functionality, but I don;t know how to specify the data to be passed from Page1 to Page2; Can someone please give a clean complete code for passing data from Page1 and Page2?

About 2a (not saving): it sounds like you use a standard Submit Button (attached to the dataset). If this is the case, unbind it (turn it into a normal button) and on the onClick do a .save() of the dataset in code and redirect to paypal with wix.location. There is also the Wix Pay API and it supports PayPal, although I am not sure how to implement donations (never tried it)
About passing data from 1 page to another: this has come up many times, but the short story is: use local storage to save the data, then read them back on page 2, using wix-storage.

You do not need, as far as I can deduct from what you have written, postMesage. This kind of communication is a special use case, if you use the html-component, or, less likely, wix-window. Basically, it provides a way to let your Wix code communicate with non-Wix Code. But you can do all inside Wix, so there should be no need for this.
Hope this makes some sense. If not, I´m sure you will let us know. Also, search this forum: passing data between 2 pages has come up many times.