Reply To: Prevent page reload

#4574
Stephen Sherrard
Keymaster

Maybe you need to explain a bit further:

Are you putting several individual sign-up sheet shortcodes on the same page so that you see several sheets worth of tasks on one page? Or are you just using the main shortcode but have a really long list of sign-up sheets? Or are you talking about one specific sign-up sheet that has a very long list of tasks that the user needs to scroll through?

Right now, any links that you click on for my plugin are adding arguments to the URL, so my plugin is checking the global GET variables to figure out sheet id, task id and date. The final signup form is a standard form that must is POSTed by clicking on the button to submit, and keeps you on the same page. If the form’s POST parameters are set, then my plugin processes the form data and gives you the success or error message on the same page. At that point, the URL in your browser has not changed.

The Go Back link uses a function to remove all my query arguments from the current URL, so that everything is reset and you see the main list of sheets again.

Unfortunately, as far as I know, there is nothing built into javascript that allows you to retrieve query parameters, but if you do a search for that, you can find some code snippets that others have written to get that from the window object. You would then need to search through the dom elements to find the links on the page (that were already generated by my plugin) and append your anchor fragment to the end of the links. It would also have to get that anchor fragment value from your page’s CSS, but then when you get to the next page, you have no way of knowing which of your forms generated the link that was clicked on.

If you have several of my plugin’s shortcodes generating different output sections on the main volunteer page you are using, my plugin has no way of being aware of any additional CSS elements you may have added to the page. Each one of those shortcodes calls a function in my plugin, and that function simply returns some html content that WordPress uses to replace where that shortcode was. My plugin has no way of knowing what is before or after the shortcode, unless it was already part of the global GET or POST variables.

There is also no direct communication between PHP (server side, all executed before returning html outpu) and javascript (browser side, all executed after the html content has alread been generated and downloaded to the browser). To communicate between javascript and PHP, you need to do an AJAX call, where the javascript posts some data back to the server, which runs a pre-specified PHP callback function that then returns a response back to the javascript.

Unfortunately, unless I’m totally misunderstanding what you want to do, there is no simple and easy solution to what you want to do.

I’m happy to talk with you privately if you want to discuss hiring me to code a custom solution for you, otherwise you could put your ideas into the feature request section.