Mobile app caches form post data

Mobile app caches form post data

by JJ Swanevelder -
Number of replies: 5

Hello,

I am using the mobile app on moodle3.5 to enable a custom plugin we have built. The issue that I am having is posted form data from a template is cached and refreshing the page will resubmit the same posted form data.

The dev structure that I am using is as per https://docs.moodle.org/dev/Mobile_support_for_plugins, using the php functions and templates with ionic components. I need a way to clear the form data somehow so that if the user refreshes the page no duplicate requests are handled.


Any help would be hugely appreciated smile

Average of ratings: -
In reply to JJ Swanevelder

Re: Mobile app caches form post data

by JJ Swanevelder -

Any updates on this one?

In reply to JJ Swanevelder

Re: Mobile app caches form post data

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi,

sorry for the delay in answering.

How are you sending the form data to the server?

Can you send me a link of the template so I can see what are you doing exactly?

Cheers,

Dani

In reply to Dani Palou

Re: Mobile app caches form post data

by JJ Swanevelder -

Hi Dani,

Thank you for getting back to me. I am sending data with a mustache template form that is using the 

core-site-plugins-new-content decorator. I will upload a basic template of this and the function that handles the form in mobile.php. The issue in this example is that when you create a new "discussion" all works fine but if you refresh the page it creates a duplicate.

I have tried unsetting the form post data and clearing the global $_POST variable on successful post but none worked.

Thank you again for any assistance.

In reply to JJ Swanevelder

Re: Mobile app caches form post data

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi,

I think you should use the directive core-site-plugins-call-ws-new-content or core-site-plugins-call-ws instead of core-site-plugins-new-content. These directives will call a WebService that should create the forum post (you will have to implement that WebService), and when the WS call is done you should then open a new view with the discussion. The new view will only fetch the discussion data, it won't send the post data, so the post won't be created over and over again.

Kind regards,

Dani

In reply to Dani Palou

Re: Mobile app caches form post data

by JJ Swanevelder -

Hi,

Great thank you for the feedback. I did see those directives but thought it would involve more code essentially in terms of what needs to be done and thought it to be over engineering. In hindsight it seems that it is the only way to properly post data without causing duplicates. 


Thought there was an easy way to clear the post data on successful post.


Thanks so much Dani smile