Test's NAME FIELD, forward via php to empty form field on PDF file (pixel "x" by pixel "y")

  • Profile Image
    HPSteve
    Asked on November 15, 2011 at 04:21 PM

    I have a jotform test with 30 questions written up in it. Alongside this jotform, There are some php files on my server that pull the data the person is entering, and relates it to the answers. (answers which are given in the php code)

     

    When they have gotten 80% correct in the test, their name and the date they took the test AUTOMATICALLY goes from the index.php file that they took their test from, to the certificate.pdf file that has an empty name and date field. I'm assuming somewhere in the certificate.php file it tells the index.php file what PIXEL exactly (x and y coordinates) where to place the name and the date.

     

    If anyone out there is curious or has experience in this area PLEASE take a look at my source files, I have been scratching my brain as to why the test won't give the person a score or certificate anymore.

  • Profile Image
    Mike_T
    Answered on November 15, 2011 at 05:22 PM

    Thank you for contacting us.

    As far as I can see, your form is not configured to Send Post Data at this moment:

    Could you please turn it on to see if that makes any difference?

    Please let us know if you need any other assistance.

  • Profile Image
    HPSteve
    Answered on November 15, 2011 at 06:17 PM

    Wow I bet thats totally it.

     

    Sorry What happened was this test was on someone else's account so I just copied the test exactly and wasn't able to check the actual settings he had. I'll change it now and see what happens.

  • Profile Image
    HPSteve
    Answered on November 15, 2011 at 06:24 PM

    Ok I changed it to send post data and still nothing.

     

    I have the thank you page set as my custom url (the url of index.php) so that way it sets that code in motion (comparing your test to answers) then executing certificate.php upon 80% completion.

     

  • Profile Image
    fxr
    Answered on November 15, 2011 at 06:57 PM

    We dont have access to any of your php, so its impossible for us to even begin to help you debug your scripts.

    If you do provide them to us, we are happy to spend a bit of time having a quick look at what may be wrong, but you do have understand debugging php scripts is a little beyond our remit. 

     

  • Profile Image
    HPSteve
    Answered on November 16, 2011 at 12:29 PM

    No I know I TOTALLY understand that its pretty in depth its just a small thing that my boss has been hounding me for 3 months about now and I have minimal php experience.

     

    I'll paste the INDEX.PHP code below.

     

    <?php require("header.php"); ?>

    <?php

     

    $yoursite = "http://jotform.com/submit.php";

    $yoursite2 = "http://www.jotform.com/submit.php";

    $referer = $_SERVER['HTTP_REFERER'];

    if($referer == $yoursite || $referer == $yoursite2) {

    $isResponse = TRUE;

    } else {

        $isResponse = FALSE;

    }

    ?>

        <?php if ($isResponse == FALSE) {?>

        <h1 class="cf">HydroPeptide Certificate Program</h1>

            <script src="//www.jotform.com/jsform/12234253273"></script>

        <?php } else {

        //if ($isResponse){print_r($_POST);}

     

    $totalScore = 0;

    $emailAddy = $_POST['email6'];

    $company = $_POST['companyname'];

    $a1 = $_POST['peptidesare20'];

    $a2 = $_POST['peptideshelp'];

    $a3 = $_POST['peptidesin'];

    $a4 = $_POST['thereare'];

    $a5 = $_POST['peptideshelp24'];

    $a6 = $_POST['hydropeptideface'];

    $a7 = $_POST['hydropeptidelashs'];

    $a8 = $_POST['onepeptide'];

    $a9 = $_POST['hydropeptidepeel'];

    $a10 = $_POST['hydropeptidemoisturize29'];

    $a11 = $_POST['hydropeptidespf'];

    $a12 = $_POST['hydropeptidecleanse'];

    $a13 = $_POST['botanicalstem'];

    $a14 = $_POST['evenout'];

    $ab15 = explode(")",$_POST['howmany']); $a12 = $ab12[0];

    $ab16 =  explode(")",$_POST['whichof34']); $a13 = $ab13[0];

    $ab17 =  explode(")",$_POST['whyis']); $a14 = $ab14[0];

    $ab18 =  explode(")",$_POST['whichof']); $a15 = $ab15[0];

    $ab19 =  explode(")",$_POST['whatis']); $a16 = $ab16[0];

    $ab20 =  explode(")",$_POST['hydropeptidetone']); $a17 = $ab17[0];

    $ab21 =  explode(")",$_POST['whathydropeptide39']); $a18 = $ab18[0];

    $ab22 =  explode(")",$_POST['whichof40']); $a19 = $ab19[0];

    $ab23 =  explode(")",$_POST['whichof43']); $a20 = $ab20[0];

    $ab24 =  explode(")",$_POST['whyis44']); $a21 = $ab21[0];

    $ab25 =  explode(")",$_POST['howdoes45']); $a22 = $ab22[0];

    $ab26 =  explode(")",$_POST['hydropeptidepower']); $a23 = $ab23[0];

    $ab27 =  explode(")",$_POST['whatingredients']); $a24 = $ab24[0];

    $ab28 =  explode(")",$_POST['hydropeptidesouffle']); $a25 = $ab25[0];

    $ab29 =  explode(")",$_POST['whichof49']); $a26 = $ab26[0];

    $ab30 =  explode(")",$_POST['whichof49']); $a27 = $ab27[0];

    $ab31 =  explode(")",$_POST['whichof49']); $a28 = $ab28[0];

    $ab32 =  explode(")",$_POST['whichhydropeptide']); $a29 = $ab29[0];

    $ab33 =  explode(")",$_POST['whichhydropeptide']); $a30 = $ab30[0];

    $ab34 =  explode(")",$_POST['hydropeptidecleansing']); $a31 = $ab31[0];

    $ab35 =  explode(")",$_POST['hydrostem+6anti']); $a32 = $ab32[0];

    if ($a1 == "True") { $r1 = "<span class='g1'>correct</span>";$totalScore++;}else{$r1 = "<span class='red'>incorrect</span>";}

    if ($a2 == "False") { $r2 = "<span class='g1'>correct</span>";$totalScore++;}else{$r2 = "<span class='red'>incorrect</span>";}    

    if ($a3 == "True") { $r3 = "<span class='g1'>correct</span>";$totalScore++;}else{$r3 = "<span class='red'>incorrect</span>";}

    (There are 12 more true and false questions. I felt no need to post all the code just a few examples)

    if ($a15 == "A") { $r12 = "<span class='g1'>correct</span>";$totalScore++;}else{$r12 = "<span class='red'>incorrect</span>";}

    if ($a16 == "B") { $r13 = "<span class='g1'>correct</span>";$totalScore++;}else{$r13 = "<span class='red'>incorrect</span>";$ca13 ="B) Every product within HydroPeptide contains 21 peptides.";}

     

    (There are 20 more questions. I felt no need to post all the code just a few examples)

     

    $percent = round( (($totalScore / 35)*100), 0);

    $fname = $_POST['fullname1'][0];

    $lname = $_POST['fullname1'][1];

    $submissionID = $_POST['submission_id'];

    $ip = $_POST['ip'];

    $phone = $_POST['phonenumber5']['0'];

    $addy1 = $_POST['wherewould']['0'];

    $addy2 = $_POST['wherewould']['1'];

    $addy3 = $_POST['wherewould']['2'];

    $addy4 = $_POST['wherewould']['3'];

    $addy5 = $_POST['wherewould']['4'];

    $addy = "$addy1 $addy2 $addy3 $addy4 $addy5";

    ?>

    <h1>Hi there, <?php echo $fname?>!</h1>

    <?php if ($percent > 79) {?><h2 class="cf">Congratulations!</h2><?php }?>

    <p class="youscored y1">You scored <span class="xsnft"><?php echo $totalScore ?> out of 26</span> = <span class="percentage cf"><?php echo $percent ?>%</span></p>

    <?php if ($percent > 79) {

    $to = "signup@hydropeptide.com";

    $subject = "I passed the HydroPeptide Test!";

    $body = "Hi,\n\nThis is a friendly notification that $fname $lname of $company at $emailAddy has passed the HydroPeptide test with a score of $percent.\r\n\n They would like their Certificate to be mailed to: $addy \r\n\n There phone number is: $phone \r\n\n Application ID:  $submissionID \r\n\n IP Address: $ip";

    $headers = "From: $emailAddy\r\n" .

    "X-Mailer: php";

     if (mail($to, $subject, $body, $headers)) {

      //echo("<p>Message sent!</p>");

     } else {

      echo("<p>Message delivery failed... please call directly at 800.932.9873 with reference code: $submissionID</p>");

     }

    ?>

            <p style="color:#333; font-size:16px; margin: 20px 0"><strong>Great job!</strong> Here is your Certificate! Please be sure to "<strong>Right Click, Save As...</strong>" for printing out and your future refence!</p>

            <img src="certificate.php?fname=<?php echo $fname;?>&lname=<?php echo $lname?>" alt="HydroPeptide Certificate" />

        <?php }else{ ?>

            <p>In order to receive your HydroPeptide certification, you must score atleast in the 80th percentile. Would you like to retake the quiz now? Sure, let's <a target="_blank" href="http://anonym.to/?http://certificate.hydropeptide.com/" rel="nofollow noopener">Try Again</a>!<br /><br /></p>

        <?php }?>

    <p class="youscored y2">Let's take a quick moment to review your test, shall we?</p>

    <h2 class="green cf">True or False</h2>

    <dl>

            <dt><strong>Question #1:</strong> Peptides are small chains of amino acids that are capable of sending signals within the skin including boosting collagen and relaxing repetitive facial muscle contractions.</dt>

    <dd>Your answer was: <strong><?php echo $a1 ?></strong> which is <strong><?php echo $r1 ?>!</strong></dd>

            <dd><span class="exp">Explanation:</span>  Peptides are short chains of amino acids (or protein fragments) that act as signaling molecules within the body.  There are a variety of peptides that exist with specific functions.  Two  functions of peptides are the ability to boost collagen and relax repetitive facial muscle contractions that cause wrinkles.</dd>

            <dt><strong>Question #2:</strong> Peptides help to neutralize free radicals to prevent aging.</dt>

            <dd>Your answer was: <strong><?php echo $a2 ?></strong> which is <strong><?php echo $r2 ?>!</strong></dd>

            <dd><span class="exp">Explanation:</span> Peptides do not neutralize free radicals. Antioxidants neutralize free radicals.  HydroPeptide incorporates a very large number of antioxidants that neutralize free radicals within their products.</dd>

     

    (There are the rest of the answers explained all the way to question 36)

    </dl>

    <?php }?>

    <?php require("footer.php"); ?>

  • Profile Image
    HPSteve
    Answered on November 16, 2011 at 12:31 PM

    Then the CERTIFICATE.PHP goes as follows.

     

    <?php

            header("Content-type: image/png");

            $fname = $_GET['fname'];

    $lname = $_GET['lname'];

    $string1 = $fname . ' ' . $lname;

    $date = date('F j, Y');

            $im     = imagecreatefrompng("certificate.png");

            $blue = imagecolorallocate($im, 0, 0, 102);

            $px1     = (imagesx($im) - 12 * strlen($string1)) / 2;

    $font = 'Century.ttf';

    // Add the text

    imagettftext($im, 26, 0, $px1, 390, $blue, $font, $string1);

    imagettftext($im, 14, 0, 145, 580, $blue, $font, $date);

     

            //imagestring($im, 2, $px1, 400, $string1, $blue);

    //imagestring($im, 3, $px2, 9, $string2, $blue);

            imagepng($im);

            imagedestroy($im);

    ?>

     

     

    I have the thank you page set to the link public_html/certificatefolder/index.php and when the test is finished and submit is clicked, the test just restarts. Basically failing to initialize the script.

  • Profile Image
    fxr
    Answered on November 16, 2011 at 04:05 PM

    I will try and make a copy of your code if I find time at some point to test things out more fully, but first thing that strikes me that something looks wrong in these lines, this is probably why your form appears to be 'looping':

     

    $yoursite = "http://jotform.com/submit.php";

    $yoursite2 = "http://www.jotform.com/submit.php";

    $referer = $_SERVER['HTTP_REFERER'];

    if($referer == $yoursite || $referer == $yoursite2) {

    $isResponse = TRUE;

    } else {

        $isResponse = FALSE;

    }

    ?>

        <?php if ($isResponse == FALSE) {?>

        <h1 class="cf">HydroPeptide Certificate Program</h1>

            <script src="//www.jotform.com/jsform/12234253273"></script>

        <?php } else {

        //if ($isResponse){print_r($_POST);}

    I will see if i can get you better code for that, but just remove those lines for now, for a testing purposes.

     

    so your index.php starts:

    <?php

    $totalScore = 0;

    .. etc , etc 

     

    Let me know what effect that has, and repost your scripts on http://pastie.org/ select 'php' as the language.

     

    Also have these scripts ever worked?

     

     

     

  • Profile Image
    HPSteve
    Answered on November 16, 2011 at 05:34 PM

    I tried taking off the top code and still it just sends me back to the beginning. I tried removing one php line at a time (of the 4 before the PHP coding of the form)

     

    This use to be a working script with a 26 question Jotform test that it grabbed post data from. So now it is a 35 question test. So I simply added the questions to the code as they were written before (nothing changed but added questions)

     

    So it use to work with the jotform site but now it can't seem to transfer the data between jotform and the index.php script. Although it did seem to be "thinking" more when I did your suggested edit. Like it was actually trying to process the grading script but then halfway through it stopped and reset the form.

  • Profile Image
    fxr
    Answered on November 16, 2011 at 05:41 PM

    OK, can you post the full code for both php scripts to pastie.org? post them back as two seperate links.

    I will rebuild application here and try to work out whats going on. 

  • Profile Image
    HPSteve
    Answered on November 16, 2011 at 05:51 PM

    http://pastie.org/2874850 index.php

     

    http://pastie.org/2874854 certificate.php (pixel plotting i'm assuming)

     

    And thanks so much FXR!

     

    Also if easier. You can make like 3-5 form fields yourself and link to those instead of jotform? Then I can just paste the source code of my test and rewrite the script to grab THAT data. Actually thinking about it now that might be MORE work. But whatever works and is easiest for you would be helpful!!

  • Profile Image
    HPSteve
    Answered on November 16, 2011 at 06:38 PM

    AFter removing the top portion of the index.php like you said. the only change was now when I enter the url it pulls up the page saying my score is 0 out of 35.

     

    So essentially it lacks the jotform test filled out. Hence why it says I got 0 out of 35.

    Then upon click JOTFORMS submit button, the thank you page is then accessed. That being index.php, I think that might be where my problem is. What other settings could I use to where when I click submit, it will run the script to grade the test?

  • Profile Image
    fxr
    Answered on November 16, 2011 at 07:03 PM

    Yes, the top part of the code was causing the 'looping' issue, thats as far as i have got at the moment.

    The next thing you could do is check that the variables used in the php are getting populated properly.

    Start with these ones:

    $emailAddy = $_POST['email6'];

    $company = $_POST['companyname'];

    $a1 = $_POST['peptidesare20'];

    $a2 = $_POST['peptideshelp'];

    $a3 = $_POST['peptidesin'];

    $a4 = $_POST['thereare'];

    $a5 = $_POST['peptideshelp24'];

    $a6 = $_POST['hydropeptideface'];

    $a7 = $_POST['hydropeptidelashs'];

    $a8 = $_POST['onepeptide'];

    $a9 = $_POST['hydropeptidepeel'];

    $a10 = $_POST['hydropeptidemoisturize29'];

    $a11 = $_POST['hydropeptidespf'];

    $a12 = $_POST['hydropeptidecleanse'];

    $a13 = $_POST['botanicalstem'];

    $a14 = $_POST['evenout'];

     

    after those lines in the code, put in something like: 

    echo 'email address:'.$emailAddy.'\n';

    echo 'company :'.$company .'\n';

     

    and just run through all of 16 those, then do a test submission and make sure the right data is getting posted into your php scripts' variables from JotForm.

    I will get to this properly before I finish tonight, you can make a head start :)

  • Profile Image
    fxr
    Answered on November 16, 2011 at 09:13 PM

    Your variable names are all wrong. You use print_r( $_POST ); to work out what these are. 

    I have recovered the 30 correct variable names

    I have fixed the first 14 questsions in the test: the start of the code now looks like this > http://pastie.org/2875552 (this code is for up to the first if statement in the script. )

    The explode command is also not working properly, its supposed put the multiple choice answer, e.g a,b,c or d into $a15, $a16 etc.. I will have a look again at that tomorrow. 

    I dont know how this code used to work, someone must have done significant editing to the form for it to have 'broken' in so many place like this.

     

    Also ensure your form is Sending post data:

  • Profile Image
    fxr
    Answered on November 16, 2011 at 09:14 PM

    my cloned example/test form is here: http://www.jotform.com/form/13194417314

  • Profile Image
    HPSteve
    Answered on November 17, 2011 at 11:34 AM

    When I was adding the new questions all I did was use the other question entries for reference. I have no experience in php and assumed it was like html. THank you for taking the time to figure all that out for me, I do apologize if my information given on this script is minimal, however the guy who made it left this company and the door definitely hit him on the way out if you know what I mean. So he is of no help in this, its just a guessing game..

  • Profile Image
    HPSteve
    Answered on November 17, 2011 at 12:04 PM

    I don't get what the test is supposed to show me, or how I'm supposed to work it either. I will paste my full code into a Pastie.

     

    Also if it makes it easier I'll give you the ORIGINAL copy of the certificate files, index.php and all that. go to this link:

    www.hydropeptide.com/content/certificate.zip

  • Profile Image
    fxr
    Answered on November 17, 2011 at 03:53 PM

    I should be able to get this sorted for you Steve, It doesnt look too difficult from here on in. Basic Quiz's like this may well be a useful thing to have in our User Guide. So, It is a good thing for me to work with, even if it is takes a little more time to work through than most of our other support requests.

    I will get you an update in a few hours, once I get a few other things out of the way. 

  • Profile Image
    GPereira
    Answered on November 17, 2011 at 04:27 PM

    I need spanish help, but only find instruccions in english.

    Can you help me?

    Thanks.

  • Profile Image
    fxr
    Answered on November 17, 2011 at 05:00 PM

    Hello GPereira, 

    Post a new thread with your query, give as much detail as possible. We should be able to help in most cases.

  • Profile Image
    HPSteve
    Answered on November 17, 2011 at 05:52 PM

    Oh thats awesome! I'm glad to be a part of the teaching world as I was a teacher for 4 years.

     

    I agree that this is or WILL be a big part of websites, especially websites that sell things and have a lot of information. You have the source files so it should be pretty easy if you are as I'm assuming and know your way around a php page. Unlike myself :/.

     

    I tried posting before but someone said it is a very in depth script so it needs to be written by a professional. But seeing the script myself and knowing nothing about php it was pretty easy to read through and understand how it connects. 

    I look forward to hearing from you soon! And thank you so much again. Nerds are the nicest, best people around (I am a certified nerd minus the in depth scripting knowledge, just the basics)

  • Profile Image
    fxr
    Answered on November 17, 2011 at 08:15 PM

    php is one of the easiest languages to pick up, perservere ;) 

     

    I have sorted out that multiple choice stuff. Test seems to be working out the correct answers properly now.

    -> http://www.jotform.com/form/13194417314

    do a test submission and make sure all the questions look right and are getting answered properly. 

    certificate php looks like some kind of image rendering utility. I dont thinl we need to touch that. 

    I just need to tidy up some of the things I removed from my cloned test form, then you can test the new code in your server. 

  • Profile Image
    fxr
    Answered on November 17, 2011 at 08:20 PM

    Why does your form on certificate.hydropeptide.com  have a birthdate label on a phone number field?

  • Profile Image
    fxr
    Answered on November 17, 2011 at 08:40 PM

    You can try this code in place of your current php.

    Back up your current index.php first! 

    http://pastie.org/2881059

    I have left all the variable checking tests in the php, you can remove these bits of code eventually when code seems be working ok. There probably better commented out, that removed.

     

    Almost any change to the form can result in php $_POST variable names getting changed so you should check this if you do make any changes to the form.

    Let me know how you get on. 

  • Profile Image
    HPSteve
    Answered on November 18, 2011 at 12:08 PM

    Will I have to use that other form to submit it? I'm confused as to how I integrate it with my test? 

  • Profile Image
    fxr
    Answered on November 18, 2011 at 12:13 PM

    Replace your index.php code with the code I have given you above.

    backup your index.php first.

    Then, test it out. 

  • Profile Image
    HPSteve
    Answered on November 18, 2011 at 12:52 PM

    But my test is nowhere in that code.  When I type in the url certificate.hydropeptide.com this what comes up:

    www.hydropeptide.com/content/Testresults.jpg

     

  • Profile Image
    HPSteve
    Answered on November 18, 2011 at 01:14 PM

    SUCCESS I re did the code a little bit, added my header and footer. and got this

    www.hydropeptide.com/content/SUCCESSTEST.jpg

     

    So basically I gotta take off that top information from coming without messing up the data being sent.

  • Profile Image
    fxr
    Answered on November 18, 2011 at 02:10 PM

    Good stuff. Yeah just remove the testing stuff now 

    I have put comments around most of those lines. 

    There is 3 lines/blocks of code you need to remove. I'd just comment them out, They will probably be useful if you did need to change something or someone else needed to look at the script. 

     

    comments in php start with //

  • Profile Image
    fxr
    Answered on November 18, 2011 at 02:12 PM

    did it send the email on success test ok?

  • Profile Image
    HPSteve
    Answered on November 18, 2011 at 02:21 PM

    Two small problems, when the Certificate picture is saved it downloads as PHP but is a jpeg file. So unless you change the extension it won't save correctly.

    Is there a way to fix this? making it download just the final jpeg image.

     

    Second the image has the white as a faint grey when it prints out. It is a png image. I have tried coding the other image formats into the certificate.php file but they all don't show up. Only the .png file shows up with my name and date.

  • Profile Image
    HPSteve
    Answered on November 18, 2011 at 02:31 PM

    Yeah the email sent saying someone passed is going. It has errors with the info its pulling from the jotform but I can fix that later.

     

    I just need to figure out if I can use a different image than a png, and how to correctly code that. Cause it doesn't seem to work when I use any other format.

  • Profile Image
    fxr
    Answered on November 18, 2011 at 05:17 PM

    There should be a certificate.png on the web server. You may be able to edit that in Photoshop. 

    You may be able to save it as a jpg and change this line in your certificate.php :

    header("Content-type: image/png");

    ---

    The line in index.php responsible for generating that customisation to the png image is :

    <img src="certificate.php?fname=<?php echo $fname;?>&lname=<?php echo $lname?>" alt="HydroPeptide Certificate" />

    I would experiment a little with changing a few things in that, checking the source HTML on the webpage to see what file extension that image file has. 

     

    These issues are way beyond even anything to do with JotForm at this stage.

     

  • Profile Image
    HPSteve
    Answered on November 22, 2011 at 12:15 PM

    Oh of course I understand, you have helped me beyond what I even expected thank you so much.

     

    And I hope people in the future use what you saw in that script. I messed around with the extensions and the coding, tried changing it to jpeg and for some reason it just doesn't show up. tried it with .jpg and .jpeg. 

     

    In the end I made a GIF and that seemed to work, it has to be an encoded photo. So I have it updated how i want it and up and running. Thank you so much FXR.

  • Profile Image
    fxr
    Answered on November 22, 2011 at 12:32 PM

    Ah. I appreciate the thought of coming back with an update and the kind words.

    I am really glad to here you got everything sorted out as you would have wanted and maybe you are just that little bit (possibly a lot) wiser. :) 

     

    I will get round to turning bits of this code into an User Guide entry at some point. Definately feel it would be useful addition. Thank you.