Printing Form Post Values

koolie 13 Oct, 2008
Hello,
I am trying to print out the form fields and values after a form has been posted. I can get the fields to display on the default thank you page, but there isn't a nice print button available. If the user uses File->Print, then they get the entire website.

Any suggestions to cleanly print this?

Thanks
Max_admin 13 Oct, 2008
Hi Pat, I don't think there is some way to do this, but I will look for one

Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
koolie 13 Oct, 2008
I'm open to other suggestions. It doesn't need to be the standard Joomla print button. Just something so it prints cleanly.
GreyHead 14 Oct, 2008
Hi koolie,

A couple of half-baked thoughts,
[list]
  • You could try using a pop-up window of some kind with the form contents formatted in it.
  • Or maybe redirect to a page with the index2.php that omits the template framework
  • Or maybe create a new 'form' containing the content and use the plugin/mambot to put that into a content page
  • Or maybe find the print button code and include that in your form page.
  • [/list]I haven't tried any of these and they may not work . . . or they may.

    Bob
    Max_admin 14 Oct, 2008
    Hi koolie,

    to print the results you will need the print version of the page and the best is to have a popup, lets walk to this step by step, first create a new form or even add this code in the onsubmit after email :

    
    <script type="text/javascript">
    	function OpenAddWin()
    			{
    				var AddWin;
    				AddWin = window.open('index.php?option=com_chronocontact&chronoformname=form1' + CouponID,'AddWindow','menubar=no,resizable=no,scrollbars=yes,status=no,top=200,left=200,width=710,height=750');
    				if (!AddWin.opener){
    					AddWin.focus();}
    				else{
    					AddWin.focus();}
    			}
    	</script>
    
    
    <a href="javascript:OpenAddWin()">Print</a>
    


    let me know what can you see after the form is submitted now and if its a print link then click it and let me know the results!

    Cheers,

    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    koolie 14 Oct, 2008
    When using your code verbatim, the window failed to open. I got a JS error that said 'CouponId is not defined'. I'm not sure which variable you were trying to pass, so I simply tried removing it. My updated code was:

    <script type="text/javascript">
       function OpenAddWin()
             {
                var AddWin;
                AddWin = window.open('index.php?option=com_chronocontact&chronoformname=MemForm','AddWindow','menubar=no,resizable=no,scrollbars=yes,status=no,top=200,left=200,width=710,height=750');
                if (!AddWin.opener){
                   AddWin.focus();}
                else{
                   AddWin.focus();}
             }
       </script>
    <a href="javascript:OpenAddWin()">Print</a>

    This allowed the window to open, but it basically opened the unfilled-out form.
    I think this idea will work, I'm just not sure what you were trying to do with the CouponID.
    Max_admin 14 Oct, 2008
    Hi Pat,

    yes, I just copied this from an old project code with some couponid thing😉

    ok, can you point this to another form which has the profile plugin enabled and configured to load the last added record values ? you will need to have the data stored of this form.

    Cheers,

    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    koolie 14 Oct, 2008
    I will try this right now, but can you explain a little further on the "point this to another form which has the profile plugin enabled"? I havent ever used this plugin, but I will start looking at it and see if I can walk myself through it. Also, by pointing, do you mean redirect the thank you page?
    koolie 14 Oct, 2008
    Ok...I think I understand what you are getting at, but am having trouble getting the value I need to pass. I want to go to the print form with a value in the address bar like 'last=34'. However, I cant seem to get the id right now. Here is my current code for 'On Submit code - after sending email:' - but the page dies with an error of: 'Parse error: syntax error, unexpected T_STRING in httpdocs/components/com_chronocontact/chronocontact.php(537) : eval()'d code on line 12'

    <?php
    echo "<h4>E-mail message</h4>
    <div style='border:1px solid black; padding:6px;margin:6px;'>
    <p>From: $fromname [$from]<br />
    To:  ".implode($recipient,', ')."<br />
    Subject: $subject</p>
    $html_message<br /></div>";
    
    $q = mysql_query(SELECT max( `cf_id` ) FROM `jos_chronoforms_1`) or die(mysql_error());
    $rs = mysql_fetch_array($q);
    $last_id = $rs[0];
    ?>
    
    <script type="text/javascript">
       function OpenAddWin()
             {
                var AddWin;
                AddWin = window.open('index.php?option=com_chronocontact&chronoformname=print_reg&last=<?php echo $last_id; ?>', 'AddWindow','menubar=no,resizable=no,scrollbars=yes,status=no,top=200,left=200,width=710,height=750');
                if (!AddWin.opener){
                   AddWin.focus();}
                else{
                   AddWin.focus();}
             }
       </script>
    <a href="javascript:OpenAddWin()">Print</a>
    


    Is there something wrong with my code, or is the program having trouble parsing?
    GreyHead 14 Oct, 2008
    Hi koolie,

    I think you need quotes round the SQL string
    $q = mysql_query("SELECT max( `cf_id` ) FROM `jos_chronoforms_1`") or die(mysql_error());

    better practice it to use the Joomal code here (assumes Joomla 1.5)
    $db = & JFactory::getDBO();
    $sql = "SELECT MAX( `cf_id` ) FROM #__chronoforms_1";
    $db->setQuery($sql);
    $last_id = $db->loadResult();
    NB : not tested may need debugging.

    Bob
    koolie 14 Oct, 2008
    Yes it was the quotes...boy do I feel sheepish :-)

    I realize the bad practice, but I am not very familiar with the code structure for Joomla. Do you by chance know what code I would use for 1.0?
    koolie 14 Oct, 2008
    Success!!!

    I had to do a little work around - and i need about 10 forms like this - but I should be good to go now.

    Here's what I did.

    1. Made a blank template with nothing more than a javascript print button that gets hidden by the CSS when printed
    2. Made a menu that doesnt appear anywhere on the site to place the "print forms"
    3. Created a component menu item that goes to the print form - this was simply so I could specify what pages to use the blank template
    4. Changed the 'On Submit code - after sending email:' popup window to go to:
    index.php?option=com_chronocontact&Itemid=77&last=<?php echo $last_id; ?>
    - aka: the menu item link
    5. And voilà printable form results!

    Thank you so much for your help! This project has been a pain for the last couple weeks and I have been putting off making the forms - because I knew it would be rough. I certainly have some work to do, but at least it is attainable!

    btw, I would still like the Joomla 1.0 best practice code for dB queries if you know it. Thanks again...Wahoo!!
    GreyHead 14 Oct, 2008
    Hi koolie,

    From memory I think that Joomla 1.0 woudl be
    global $database;
    $sql = "SELECT MAX( `cf_id` ) FROM #__chronoforms_1";
    $database->setQuery($sql);
    $last_id = $database->loadResult();
    just the call to the database object is different.

    Bob
    koolie 14 Oct, 2008

    From memory I think that Joomla 1.0 woudl be...


    Worked perfect. Thank you!
    Max_admin 14 Oct, 2008
    Hi Pat,

    was this a Joomla 1.0 or 1.5 site ?

    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    Max_admin 15 Oct, 2008
    Ok that's fine, I was going to present another J1.5 solution.

    cheers

    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    koolie 15 Oct, 2008
    If you have another idea, I'm sure it wouldn't hurt to mention it. For my company personally, we are not using 1.5 yet - but should be soon. So, I might run into a need to do this in 1.5.

    Someone else might too :-)

    Thanks again for all your help.
    Max_admin 15 Oct, 2008
    Hi Pat,

    I would say that you can load another form with the profile plugin enabled which will get the last record too as you did, however I would show the J1.5 version of code to get the last record, that's all😉

    Cheers

    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    altnetwork 16 Oct, 2008
    I am also using J1.5 and trying to print to a custom form with post values.

    I see that users are printing values from posts submitted into a database. Is there a way to have a submitted form not posting into a database still open a custom form with the post values to print. If so what do I need to do?

    Thanks
    Doyle
    Max_admin 17 Oct, 2008
    Hi Doyle,

    I'm afraid this is not possible unless you want to show print screen after submit and lose your site template, the print screen will open in a new window and show the print results and so it must load the data from somewhere.

    OR if you can get some JS code to open a window popup with contents from a div in the parent window then we can get this working, but I don't have this JS myself!

    Cheers
    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    altnetwork 17 Oct, 2008
    Ok, then how do I get it to work in J1.5???

    Thanks
    altnetwork 17 Oct, 2008
    This is what I get when I click on print.

    ERROR:
    There is no form with this name or may be the form is unpublished, Please check the form and the url and the form management

    This is the code I am using under On Submit code - after sending email:

    <?php
    echo "<h4>Name:</h4>
    <div style='border:1px solid black; padding:6px;margin:6px;'>
    <p>$text_0<br />
    <div>";
    
    $q = mysql_query("SELECT max( `cf_id` ) FROM `jos_chronoforms_pt_setup_forms`") or die(mysql_error());
    $rs = mysql_fetch_array($q);
    $last_id = $rs[0];
    ?>
    
    <script type="text/javascript">
       function OpenAddWin()
             {
                var AddWin;
                AddWin = window.open('index.php?option=com_chronocontact&chronoformname=print_reg&last=<?php echo $last_id; ?>', 'AddWindow','menubar=no,resizable=no,scrollbars=yes,status=no,top=200,left=200,width=710,height=750');
                if (!AddWin.opener){
                   AddWin.focus();}
                else{
                   AddWin.focus();}
             }
       </script>
    <a href="javascript:OpenAddWin()">Print</a>


    The information for the name is also not passed. It shows blank. I am only entering 1 field.
    GreyHead 17 Oct, 2008
    Hi altnetwork,

    Do you have a form called print_reg?

    Bob
    koolie 17 Oct, 2008
    First, did you make a form called "print_reg". Second, make sure you setup the profile plugin. Also, make sure that within the "print_reg" form you have 'Profile Page' plugin checked.
    koolie 17 Oct, 2008
    One other note related to last_id. For some reason, the last id really isnt the last id. I had to add a +1 to the variable. So in On Submit after Email I have

    
    <?php
    global $database;
    $sql = "SELECT MAX( `cf_id` ) FROM #__chronoforms_1";
    $database->setQuery($sql);
    $last_id = $database->loadResult();
    $last_id = $last_id + 1;
    ?>
    
    altnetwork 17 Oct, 2008
    I am missing someing.....am I using two forms or one form - the one being the form that the info is submitted?
    koolie 17 Oct, 2008
    Two.
    The first form collects your data. Then, on your default "thank you" page (DO NOT REDIRECT only use the on submit after email area) you add code for the popup window.

    That will go to another form...a print form. My print forms look like this
    
    <tr>
    		<td><div align="right">Name</div></td>
    		<td colspan="3"><div align="left">{name}</div></td>
    	</tr>
    	<tr>
    		<td><div align="right">Home Address </div></td>
    		<td colspan="3"><div align="left">{addy1}</div></td>
    	</tr>
    	<tr>
    		<td><div align="right">Apt/Suite</div></td>
    		<td colspan="3"><div align="left">{addy2}</div></td>
    	</tr>
    	<tr>
    		<td><div align="right">City</div></td>
    		<td colspan="3"><div align="left">{city}</div></td>
    	</tr>
    


    This page will have the profile plugin enabled and get the information from the last form created.

    Have you used the profile plugin before? My values for the plugin for the print form are as follows:
    Table Name: jos_chronoforms_1 (this will change depending on what form you want to retrieve data from)
    REQUEST Parameter name: last
    Target field name: cf_id
    altnetwork 17 Oct, 2008
    Ok this is what I have.

    Created form called form_1

    1. input text field Name: {text_0}
    2. On Submit code - after sending email:
    {text_0}<br>
    <?php
    $q = mysql_query("SELECT max( `cf_id` ) FROM `jos_chronoforms_form_1`") or die(mysql_error());
    $rs = mysql_fetch_array($q);
    $last_id = $rs[0] + 1;
    ?>
    
    <script type="text/javascript">
       function OpenAddWin()
             {
                var AddWin;
                AddWin = window.open('index.php?option=com_chronocontact&chronoformname=print_reg&last=<?php echo $last_id; ?>', 'AddWindow','menubar=no,resizable=no,scrollbars=yes,status=no,top=200,left=200,width=710,height=750');
                if (!AddWin.opener){
                   AddWin.focus();}
                else{
                   AddWin.focus();}
             }
       </script>
    <a href="javascript:OpenAddWin()">Print</a>

    3. Link to database: jos_chronoforms_form_1
    4. data is showing in database.

    Second, Created form print_reg
    1.created blank form
    2.On Submit code - after sending email:
    {text_0}

    3. Plugin table: Profile Page checked
    4. Profile Page:
    Table name: jos_chronoforms_form_1
    REQUEST Parameter name: last
    Target field name: cf_id

    This is what I get:
    1.Goto form and enter Name: and click submit
    2. Goes to page with the name output and shows link to print.
    3. When click on print it goes back to website with menu and header and a blank page.


    What am I missing????
    Max_admin 17 Oct, 2008
    Hi,

    Ok, starting from your last post here, this is what your code should look like :

    
        {text_0}<br>
        <?php
    global $row_jos_chronoforms_form_1;
    $last_id = $row_jos_chronoforms_form_1->cf_id;
        ?>
    
        <script type="text/javascript">
           function OpenAddWin()
                 {
                    var AddWin;
                    AddWin = window.open('index.php?option=com_chronocontact&chronoformname=print_reg&last=<?php echo $last_id; ?>', 'AddWindow','menubar=no,resizable=no,scrollbars=yes,status=no,top=200,left=200,width=710,height=750');
                    if (!AddWin.opener){
                       AddWin.focus();}
                    else{
                       AddWin.focus();}
                 }
           </script>
        <a href="javascript:OpenAddWin()">Print</a>
    
    


    at the 2nd form, add this code : {text_0} to the form HTML!

    Cheers
    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    altnetwork 20 Oct, 2008
    This did not work. When I click on print a page opens with the website again with the menu and logo and it only shows {text_0}.

    This is a clean install with the default theme with no extra stuff added.

    I don't understand why this is so hard to get working. I understand the coding that I am using and what I am trying to get from it, but it will just not work.

    What can I do??????
    koolie 20 Oct, 2008
    Just to verify, you removed the {text_0} code from the On Submit code - after sending email: and moved it to the HTML area of the print form. Your input field name is text_0 on the original form correct?
    altnetwork 20 Oct, 2008
    That is correct.

    The other issue is that when I click on print it opens a new windows with the website again and not a black page with(without) the data.
    altnetwork 20 Oct, 2008
    Does anyone have this working for Joomla 1.5.X???????
    altnetwork 20 Oct, 2008

    Hi,

    Ok, starting from your last post here, this is what your code should look like :

    
        {text_0}<br>
        <?php
    global $row_jos_chronoforms_form_1;
    $last_id = $row_jos_chronoforms_form_1->cf_id;
        ?>
    
        <script type="text/javascript">
           function OpenAddWin()
                 {
                    var AddWin;
                    AddWin = window.open('index.php?option=com_chronocontact&chronoformname=print_reg&last=<?php echo $last_id; ?>', 'AddWindow','menubar=no,resizable=no,scrollbars=yes,status=no,top=200,left=200,width=710,height=750');
                    if (!AddWin.opener){
                       AddWin.focus();}
                    else{
                       AddWin.focus();}
                 }
           </script>
        <a href="javascript:OpenAddWin()">Print</a>
    
    


    at the 2nd form, add this code : {text_0} to the form HTML!

    Cheers
    Max



    The code did not work due to the $last_id did not pass the var.

    This is what I did to get that working...
    {text_0}
    <?php
    $q = mysql_query("SELECT max( `cf_id` ) FROM `jos_chronoforms_form_1`") or die(mysql_error());
    $rs = mysql_fetch_array($q);
    $last_id = $rs[0] +1;
    ?>
    
    <script type="text/javascript">
       function OpenAddWin()
             {
                var AddWin;
                AddWin = window.open('index.php?option=com_chronocontact&chronoformname=print_reg&last=<?php echo $last_id; ?>','AddWindow','menubar=no,resizable=no,scrollbars=yes,status=no,top=200,left=200,width=710,height=750');
                if (!AddWin.opener){
                   AddWin.focus();}
                else{
                   AddWin.focus();}
             }
       </script>
    <a href="javascript:OpenAddWin()">Print</a>


    NOW, the problem is that when I click on the print link I get the information but it opens into a new window of the website and not into a black page.

    How do I fix this??????
    Max_admin 20 Oct, 2008
    Hi, change this :
    window.open('index.php?option=com_chronocontact&chronoformname=print_reg&last=<?php echo $last_id; ?>',


    make it:

    window.open('index2.php?option=com_chronocontact&chronoformname=print_reg&last=<?php echo $last_id; ?>',


    Cheers,
    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    altnetwork 20 Oct, 2008
    That worked....

    Is it possible to in the first place have the option to have the On Submit code - after sending email: goto index2.html?

    You would then not need to do all the other options when you don't want the information going to a database.
    Max_admin 20 Oct, 2008
    yes but when the user get a non template page it may be confusing for them ?

    add the url above to the action url and replace the form name with the main form you have and add the {field_name} to the onsubmit after email!

    Cheers
    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    This topic is locked and no more replies can be posted.