Saving Form Data in Client-Side Storage

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
rpierce
Veteran Member
Posts: 283
Joined: 2018-11-26 13:55
Location: Washington State

Saving Form Data in Client-Side Storage

Post by rpierce » 2024-07-08 23:49

Hi AppGini Friends,

I have a new request for information that may not be within the boundaries of AppGini. But you folks are where I generally always find an answer. Here is my scenario:

I've been using AppGini for several years and love it. It has greatly expanded my knowledge to the point that I keep coming up with things I want to do but have no idea how to proceed. I have built a system for managing construction project information. We report injuries and incidents to our hiring clients. We are doing this in AppGini. I call it the Project Diary. So, let's say there is an incident involving a crane. Someone will start writing the report in the Project Diary and run into some bits of information they need to obtain before continuing with the report. So they would logically want to save the data they have entered. This is where my quandary comes into play, I have created a table_name_after_insert hook that sends an email to key individuals that details the incident.

My question to the group: how do we save the form data and send out the report when we're satisfied with everything?

I hope I've given you enough to go on.

Ray

User avatar
zibrahim
Veteran Member
Posts: 162
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Saving Form Data in Client-Side Storage

Post by zibrahim » 2024-07-09 04:25

Hi Ray,
Not sure if I totally understand your quest. Just to share a similar (may be) experience that I have encountered.
I have an application that report machines breakdown to the maintenance team by the production members.

Whenever, production members submit the report of machine breakdown, an event record is created.
At this point (record INSERT), the status field is set as default, "REPORTED" and other status radio button (In PROGRESS & COMPLETED) are hidden.
SCR-20240709-laqa.png
SCR-20240709-laqa.png (56.12 KiB) Viewed 1238 times
The maintenance team will keep updating the record (their findings, corrective action, preventive action) according to the respective repair stages/time.
At this point, maintenance team will select the status field as, "IN PROGRESS". (record UPDATE)
SCR-20240709-lblz.png
SCR-20240709-lblz.png (120.3 KiB) Viewed 1238 times
Once they have completed the repairs and satisfied with the contents, they will select the status as "COMPLETED" and update the record.
At this point, maintenance team will select the status field as, "COMPLETED". (record UPDATE)

In the TABLENAME_after_update hook, the code is like this

Code: Select all

function TABLENAME_after_update($data, $memberInfo, &$args) {
	if ($data['status'] == 'COMPLETED') {
    		// your code to send the report/email etc.
	};
	return TRUE;
}
As long as the status is not set to COMPLETED, maintenance team can update their findings and maintenance notes as many times they like without the report/email being sent out.
SCR-20240709-lbvn.png
SCR-20240709-lbvn.png (131.82 KiB) Viewed 1238 times
Once the status is selected as COMPLETED, other status (REPORTED and IN PROGRESS) are hidden.

Hope this helps.
Zala.
Appgini 24.19, MacOS 15.2 Windows 11 on Parallels.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1897
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Saving Form Data in Client-Side Storage

Post by jsetzer » 2024-07-09 09:37

Thanks for sharing, Zala! Just one small hint: When saving a record, having status "COMPLETED", multiple times, the after-update function will be executed every time. This means reporter will get an email notification on every update even if status hasn't changed again.

If we need to avoid this, we can hook into before-update and check if current status != 'COMPLETED' and new status == 'COMPLETED'.

Another idea: additional checkbox 'reporter_notified',
integer, default 0. When sending the email, set value to 1 to indicate notification already sent. Before sending again, check that value. That gives some more options like notifying the reporter again after unchecking that checkbox.

Just ideas.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.14 Revision 1665 + all AppGini Helper tools

rpierce
Veteran Member
Posts: 283
Joined: 2018-11-26 13:55
Location: Washington State

Re: Saving Form Data in Client-Side Storage

Post by rpierce » 2024-07-09 20:26

In my Incident and First Aid reports, I have a button to print a PDF version of the report. If anyone could help me to configure a button to "Submit" the report which would send the PDF out to a specified list of recipients. That would be a great way to solve this. I'm just not any good at the coding that would go into that.
Capture.JPG
Capture.JPG (35.73 KiB) Viewed 1190 times

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1672
Joined: 2018-04-01 10:12

Re: Saving Form Data in Client-Side Storage

Post by pbottcher » 2024-07-10 20:22

Hi,
as a starting point, you could use the dompdf library to convert the print-preview page into a pdf and send it via e-mail.
The print-preview can be adjusted to you needs via the template.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

rpierce
Veteran Member
Posts: 283
Joined: 2018-11-26 13:55
Location: Washington State

Re: Saving Form Data in Client-Side Storage

Post by rpierce » 2024-07-12 15:24

Hi Pascal,

I've been using tdpdf ever since you introduced it to me. Do you think dompdf is a better tool to use?

rpierce
Veteran Member
Posts: 283
Joined: 2018-11-26 13:55
Location: Washington State

Re: Saving Form Data in Client-Side Storage

Post by rpierce » 2024-07-12 15:31

The following script works well in the after_insert hook. Can anyone help me configure this to work with a button instead of the after_insert hook?

Code: Select all

	function incident_after_insert($data, $memberInfo, &$args){
	    

        foreach($data as $field => $value){
        $messageData .= "$field: $value \n";
    }
    $authName = sqlValue("select custom1 from membership_users where memberID='{$memberInfo['username']}'");
    
    $projectname = sqlValue("select name from project where project_id='{$data['project']}'");
    
    //***************************************************************************    
	// This code selects email addresses from the contacts table for a project where
	//the recipient is marked yes for notifications
	
        $response =sql("SELECT email_address FROM contacts WHERE notify = 'Yes' AND project = '{$data['project']}'",$eo);
        	while ($row = db_fetch_assoc($response)) {
	            $receipt[] = $row['email_address'];
	}
	//****************************************************************************	   
     
    $msgTEXT = "The following Incident Report was submitted by $authName.<br> This is a preliminary report, details may change."."

<p><strong>Project: </strong>$projectname
<p><strong>Date of incident: </strong>{$data['date']}
<p><strong>Time of incident: </strong>{$data['time']}
<p><strong>Type of Incident: </strong>{$data['type']}
<p><strong>Incident Summary: </strong>{$data['summary']}
<p><strong>How did it happen: </strong>{$data['how']}
<p><strong>Objects involved: </strong>{$data['object']}
<p><strong>What were people doing: </strong>{$data['activity']}
<p><strong>Behavior Based Safety Factor: </strong>{$data['bbs']}
<p><strong>BBS Comments: </strong>{$data['bbs_comments']}
<p><strong>Additional Comments: </strong>{$data['add_comments']}
<p><strong>Witnesses: </strong>{$data['witness']}
";
    
    
  	foreach ($receipt as $address){
    
    sendmail(array(
	
		// mail recipient
		'to' => $address,
		
		'name' => "",

		// subject
		'subject' => "An incident report has been submitted for " . sqlValue("select name from project where project_id='{$data['project']}'"),
		
		// message
		'message' => nl2br (stripcslashes($msgTEXT)),
        
    // sender address
        "From: [email protected]"
    ));
	}
    
    //end email code

		return TRUE;
	}

Post Reply