{"id":3564,"date":"2026-11-16T16:50:20","date_gmt":"2026-11-16T21:50:20","guid":{"rendered":"https:\/\/xlinesoft.com\/blog\/?p=3564"},"modified":"2026-11-16T18:52:50","modified_gmt":"2026-11-16T23:52:50","slug":"save-phprunner-forms-offline-and-synchronize-them-later","status":"publish","type":"post","link":"https:\/\/xlinesoft.com\/blog\/2026\/11\/16\/save-phprunner-forms-offline-and-synchronize-them-later\/","title":{"rendered":"Save PHPRunner Forms Offline and Synchronize Them Later"},"content":{"rendered":"<p>Field work does not always happen where a reliable network connection is available. In this tutorial, we will modify a PHPRunner master-detail Add page so users can continue entering inspections after the connection is lost.<\/p>\n<p>The loaded page stores the inspection, its detail records, and selected photos in the browser. When the application server becomes available again, the queued submissions are synchronized automatically.<\/p>\n<p>This is not a fully offline application. The user must open the Add page while connected and keep that page open. Once it is loaded, the form can continue working without access to the server.<\/p>\n<p><a href=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2026\/11\/phprunner-offline-inspections-indexeddb.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2026\/11\/phprunner-offline-inspections-indexeddb-1024x551.png\" alt=\"PHPRunner inspection Add page with two offline submissions stored in IndexedDB\" width=\"810\" height=\"436\" class=\"alignnone size-large wp-image-3571\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2026\/11\/phprunner-offline-inspections-indexeddb-1024x551.png 1024w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2026\/11\/phprunner-offline-inspections-indexeddb-600x323.png 600w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2026\/11\/phprunner-offline-inspections-indexeddb-768x413.png 768w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2026\/11\/phprunner-offline-inspections-indexeddb-1536x826.png 1536w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2026\/11\/phprunner-offline-inspections-indexeddb.png 1922w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/a><br \/>\n<!--more--><\/p>\n<h3>1. Preparing the inspection form<\/h3>\n<p>Create the following MySQL tables and add them to the PHPRunner project:<\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"sql\" name=\"mshighlighter\" >\r\nCREATE TABLE `inspections` (\r\n    `inspection_id` int NOT NULL AUTO_INCREMENT,\r\n    `property_address` varchar(255) NOT NULL,\r\n    `inspection_date` date NOT NULL,\r\n    `notes` longtext NULL,\r\n    `submission_id` varchar(36) NULL,\r\n    PRIMARY KEY (`inspection_id`)\r\n);\r\n\r\nCREATE TABLE `findings` (\r\n    `finding_id` int NOT NULL AUTO_INCREMENT,\r\n    `inspection_id` int NOT NULL,\r\n    `room` varchar(40) NOT NULL,\r\n    `description` longtext NOT NULL,\r\n    `photos` longtext NULL,\r\n    PRIMARY KEY (`finding_id`)\r\n);<\/textarea><\/pre>\n<\/div>\n<p>Create a master-detail relationship between <strong>inspections.inspection_id<\/strong> and <strong>findings.inspection_id<\/strong>.<\/p>\n<p>Open the <strong>inspections Add page<\/strong> in Page Designer and add a Findings details preview. The Findings List page must allow Inline Add because each finding is entered as a detail row on the inspection form.<\/p>\n<p>Configure the Findings fields as follows:<\/p>\n<ul>\n<li><strong>room<\/strong>: Lookup Wizard with a static list such as Kitchen, Bathroom, Basement, Garage, and Other.<\/li>\n<li><strong>description<\/strong>: Text area.<\/li>\n<li><strong>photos<\/strong>: Document upload, with File-based Image as its View format.<\/li>\n<\/ul>\n<p>A static lookup works after the connection is lost because its values are already included in the loaded page. An AJAX lookup would need to contact the server.<\/p>\n<h3>2. Adding the server availability check<\/h3>\n<p>Open <strong>Editor &#8211; Custom files<\/strong>, create <strong>offline_ping.php<\/strong>, and add the following code:<\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"php\" name=\"mshighlighter\" >\r\n<?php\r\nrequire_once __DIR__ . '\/include\/dbcommon.php';\r\n\r\nheader('Content-Type: application\/json; charset=utf-8');\r\nheader('Cache-Control: no-store');\r\n\r\necho json_encode([\r\n    'ready' => true,\r\n    'scope' => 'home-inspection:demo'\r\n]);<\/textarea><\/pre>\n<\/div>\n<p>The browser&#8217;s online status does not guarantee that the application server is reachable. This file provides a small application-specific response that the synchronization code can verify. The request uses a four-second timeout and disables caching.<\/p>\n<h3>3. Saving submissions in IndexedDB<\/h3>\n<p>IndexedDB is a database built into modern web browsers. <strong>localStorage<\/strong> is useful for small text values, but IndexedDB can store structured records and binary objects such as the photos selected on this form. Its storage allowance is also generally much larger, although the exact limit is controlled by the browser and device.<\/p>\n<p>Open <strong>Events &#8211; Global events &#8211; custom_functions.js<\/strong> and add the following JavaScript:<\/p>\n<p><a href=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2026\/11\/phprunner-offline-form-custom-functions.zip\"><strong><i class=\"fas fa-link\" style=\"solid\"><\/i> Download custom_functions.js<\/strong><\/a>.<\/p>\n<p>The queue uses a generated ID for each submission and stores records under the <strong>home-inspection:demo<\/strong> scope. Change this scope consistently in both the JavaScript and <strong>offline_ping.php<\/strong> when adapting the example to another application.<\/p>\n<p>The runtime listens for the browser&#8217;s <strong>online<\/strong> and <strong>focus<\/strong> events. It also checks the server every 30 seconds as a fallback. Browser locks prevent two tabs from draining the same queue simultaneously.<\/p>\n<h3>4. Intercepting the Inspections Add page<\/h3>\n<p>Open the <strong>inspections Add page &#8211; JavaScript OnLoad event<\/strong> and add this code:<\/p>\n<p><a href=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2026\/11\/phprunner-offline-form-add-page-onload.zip\"><strong><i class=\"fas fa-link\" style=\"solid\"><\/i> Download the JavaScript OnLoad event code<\/strong><\/a>.<\/p>\n<p>PHPRunner normally uploads a selected file immediately. The event intercepts file selection and drag-and-drop before that request begins, keeps the File objects in the browser, and generates local previews with <strong>URL.createObjectURL()<\/strong>.<\/p>\n<p>The event also intercepts the page&#8217;s normal Save operation. It validates the master fields and visible finding rows, adds the complete submission to IndexedDB, and then clears the form without reloading the page.<\/p>\n<h3>5. Synchronizing queued inspections<\/h3>\n<p>When the server responds to <strong>offline_ping.php<\/strong>, the project-level JavaScript reproduces the required PHPRunner save sequence:<\/p>\n<ol>\n<li>Create the inspection through the generated <strong>inspections_add.php<\/strong> page.<\/li>\n<li>Read the new inspection key returned by PHPRunner.<\/li>\n<li>For each finding, upload its photos through <strong>mfhandler.php<\/strong>.<\/li>\n<li>Create the finding through <strong>findings_add.php<\/strong> using that inspection key.<\/li>\n<li>Delete the IndexedDB entry only after all responses have been confirmed.<\/li>\n<\/ol>\n<p>The synchronization checkpoint records the inspection key and the next detail row to send. If a write may have reached the server but its response was not confirmed, the entry remains queued instead of blindly repeating the write and possibly creating a duplicate.<\/p>\n<p>Status messages show whether submissions are waiting, being sent, successfully synchronized, or blocked by an error.<\/p>\n<h3>6. Testing the offline workflow<\/h3>\n<p>Build the project and open the Inspections Add page while connected to the server. In the browser&#8217;s developer tools, open the Network panel and select &#8216;Offline&#8217;.<\/p>\n<p>Enter an inspection, add one or more finding rows, select photos, and click &#8216;Save&#8217;. The form should remain open and display a message that the inspection was saved on the device.<\/p>\n<p>To inspect the queue in Chrome or Edge, open <strong>Developer tools &#8211; Application &#8211; IndexedDB &#8211; phprunner-offline-add-v1 &#8211; submissions<\/strong>.<\/p>\n<p>Add another inspection if required, then clear the Network panel&#8217;s &#8216;Offline&#8217; setting. The application should begin synchronization immediately. If the browser&#8217;s online event does not fire, the next 30-second server check will start it.<\/p>\n<p>Open the Inspections List page and confirm that the master records, finding rows, and uploaded photos were saved.<\/p>\n<h3>7. Current scope and possible next steps<\/h3>\n<p>The Add page must be loaded before the connection is lost. Do not reload or close it while offline. IndexedDB data belongs to the current browser profile and device, so opening the application in another browser will not expose the same queue.<\/p>\n<p>This approach can be extended in several ways. A Progressive Web App and service worker could allow the page itself to open offline. Lookup-table data could be cached in IndexedDB and refreshed while connected. Applications that require login could detect an expired session, ask the user to sign in again, and resume synchronization afterward. A dedicated REST API could also replace the generated-page requests when a more formal synchronization interface is required.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to let users complete a PHPRunner master-detail Add form without a connection, store records and photos in IndexedDB, and synchronize them later.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,8],"tags":[],"class_list":["post-3564","post","type-post","status-publish","format-standard","hentry","category-php-category","category-tutorials"],"_links":{"self":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/3564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/comments?post=3564"}],"version-history":[{"count":5,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/3564\/revisions"}],"predecessor-version":[{"id":3572,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/3564\/revisions\/3572"}],"wp:attachment":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/media?parent=3564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/categories?post=3564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/tags?post=3564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}