
Print form and submit to database at the same time
Reported by BJ Kline | June 13th, 2015 @ 12:43 PM | in User issues
Is there a way I can have the user print the data they've entered into a form and at the same time, save that data to the database?
Comments and changes to this ticket
-
dleffler June 14th, 2015 @ 06:10 PM
- Tag set to form module
- Assigned user changed from expNinja to dleffler
As always some questions to ensure I'm on the same page...
We do NOT 'print' anything from Exponent, though we do provide some 'printer-friendly' views and pdf downloads. Therefore I'm a bit confused by what you mean by 'print the form data'. We DO provide a view AFTER the user clicks on the 'Submit' button which details all the form entries...this is also the same 'view' an admin can bring up later.
You can also optionally have Exponent sent an email to the 'user' once their form is submitted...though at this time its a admin entered message and NOT the form data...though the admin can optionally be sent an email with the data. E.g., I've used the form module to pre-register for an event, After entering the details about the parent being registered, the parent is presented a detailed summary of all form entries before actually submitting the registration. When they 'confirm' the form data, we send them a 'Submission Response Email' if the form had a field named 'email' and they entered a valid email address...and we email the admin the form responses based on Report single-record view configuration.
-
BJ Kline June 15th, 2015 @ 05:29 PM
"We DO provide a view AFTER the user clicks on the 'Submit' button which details all the form entries...this is also the same 'view' an admin can bring up later"
This is what I want to print. My client doesn't want to go to online ordering yet. So what they've done in the past is have a simple HTML form, but instead of submitting it to a database or email recipient, the end user prints it off and writes their CC info on the printed page and snail mails it to my client.
I think I need to add an onsubmit to framework/modules/forms/views/forms/confirm_data.tpl line #48 to make this happen?
-
dleffler June 16th, 2015 @ 07:46 PM
You can try, you'll need to remember to continue on any remaining code in the 'submit' event or at least go back in expHistory. What sort of 'code' are you using to force a browser print? Or are you simply wanting a 'printer friendly' view presented to print from?
-
BJ Kline June 17th, 2015 @ 02:34 PM
I tried changing line 48 to this:
{form onclick="window.print();" action=submit_data}
But it doesn't bring up the print dialog, the onclick is completely ignored.
-
dleffler June 17th, 2015 @ 05:48 PM
Ok, a couple of problems with that:
- I don't think you want the 'onclick' event since that would fire anytime you click inside the form object (not even sure it's available)
- Exponent doesn't recognize the 'onsubmit' param but that would be the correct event to watch for
Perhaps what you want is more like adding this to the bottom of the confirm_data.tpl file, though it attempts to print the entire web page
{script unique=confirm jquery=1} {literal} $(document).ready(function(){ $('#form').on('submit', function(e){ window.print(); }); }); {/literal} {/script}
-
BJ Kline June 17th, 2015 @ 06:50 PM
I should be able to use that and then create a print stylesheet to only display what I want have the user print.
-
BJ Kline June 18th, 2015 @ 12:45 PM
That code, along with my print style sheet work as long as a user is logged into the site. If not logged in, the print dialog doesn't appear, the form just gets submitted. The page the form is on is set to Public and Active.
Here is my print stylesheet
@media print { body { font-size: 12pt; color: #000000; } #main-menu, #sidebar { display: none; } a.triggerlogin { display: none; } #main { width:100%; } .print { display: block; } .col-xs-6 { width: 100%; } a[href]:after { content: none !important; } }
-
dleffler June 18th, 2015 @ 06:07 PM
It's likely conflicting with another form (login?) on the page when no one is logged on...I'll experiment, but we may have to add a name or id (param) to the {form} and change the javascript to attach to t.
-
BJ Kline June 18th, 2015 @ 06:25 PM
Adding an id fixed it.
Here is the working code.
{form action=submit_data id="orderconf"} {foreach from=$postdata item=data key=name} {control type=hidden name=$name value=$data} {/foreach} {control type=antispam} {control type=buttongroup submit="Submit Form"|gettext cancel="Change Responses"|gettext} {/form} {script unique=confirm jquery=1} {literal} $(document).ready(function(){ $('#orderconf').on('submit', function(e){ window.print(); }); }); {/literal} {/script}
-
dleffler June 18th, 2015 @ 07:27 PM
- State changed from new to resolved
- Milestone set to User issues
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Bug Tracker for Exponent CMS