{"id":46984,"date":"2019-10-29T03:01:33","date_gmt":"2019-10-28T17:01:33","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=46984"},"modified":"2019-10-29T12:28:40","modified_gmt":"2019-10-29T02:28:40","slug":"ajax-formdata-object-no-body-php-pdf-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/ajax-formdata-object-no-body-php-pdf-tutorial\/","title":{"rendered":"Ajax FormData Object No Body PHP PDF Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Ajax FormData Object No Body PHP PDF Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body_email_pdf.jpg\" title=\"Ajax FormData Object No Body PHP PDF Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Ajax FormData Object No Body PHP PDF Tutorial<\/p><\/div>\n<p>Continuing on with the sharing ideas emanating from yesterday&#8217;s <a title='Ajax FormData Object No Body PHP Email Tutorial' href='#afdonbphpet'>Ajax FormData Object No Body PHP Email Tutorial<\/a> sharing (or accountability) &#8230;<\/p>\n<ul>\n<li>emailing HTML attachment functionality &#8230; today <font size=1>(shame about the spoiler alert in the blog posting title &#8230; but nevertheless &#8230; <a target=_blank title='?' href='https:\/\/www.youtube.com\/watch?v=F-t8PngHgWY'>the show must go on<\/a>)<\/font> we involve &#8230;<\/li>\n<li>PDF functionality &#8230; a tabular representation of that HTML look &#8230; allowing for emails with both a PDF and HTML attachment<\/li>\n<\/ul>\n<p> &#8230; still all with no need for a webpage document.body (ie. body tag) with any content.<\/p>\n<p>As you would surmise &#8230;<\/p>\n<ul>\n<li>you need a serverside language like PHP in order to be able to do this &#8230; yes, web server files are involved (even if the client document.body is not) &#8230; and &#8230;<\/li>\n<li>you need, within that serverside language you use (in our case, PHP), to have written or access PDF Writing capable code (or class), for which we are eternally grateful to (the open source) <a target=_blank title='Fpdf PHP class' href='HTTP:\/\/www.fpdf.org\/'>Fpdf<\/a> regarding &#8230; in particular, Rick van Buuren and Cl\u00e9ment Lavoillotte&#8217;s HTML table to PDF work starring at <a target=_blank title='Useful link' href='HTTP:\/\/www.fpdf.org\/en\/script\/script50.php'>this useful link<\/a><\/li>\n<\/ul>\n<p>A bit of &#8220;value add&#8221; this PDF tabular approach has <font size=1>(let alone down the track)<\/font> is that the left hand side of our two column table could now be dedicated to offering the user some personalization to the exercise, offering to them when deciding on their email address definition &#8230;<\/p>\n<p><code><br \/>\n  emailto=prompt('Email to?   A mixing of case here also outputs a PDF form of the conversation.   A pseudo email address of a form like Leo Max &lt;Rmetcalfe15@gmail.com&gt; would email rmetcalfe15@gmail.com HTML and PDF attachments, the PDF tabular look indicating that the conversation was between Leo and Max. ', '');<br \/>\n<\/code><\/p>\n<p>See for yourself what we mean here by trying out <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php--GETME\" title=\"no_body.php\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php--GETME\" title=\"no_body.php\">no_body.php<\/a> PHP <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php\" title=\"Click picture\">live run<\/a>.  A view source will still not show a body tag with any content, as per the pledge of this blog posting thread.  How does that work with PDF data shown to the webpage?<\/p>\n<p>&lt;?php<br \/>\n<code><br \/>\n $pdf=new PDF();<br \/>\n $pdf->AddPage();<br \/>\n $pdf->SetFont('Arial','',12);<br \/>\n $pdf->WriteHTML($thtml);   \/\/ $thtml is some HTML table code collected earlier on<br \/>\n header('Content-type: application\/pdf');<br \/>\n $pdf->Output();<br \/>\n exit;<br \/>\n<\/code><br \/>\n?&gt;<\/p>\n<hr>\n<p id='afdonbphpet'>Previous relevant <a target=_blank title='Ajax FormData Object No Body PHP Email Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/ajax-formdata-object-no-body-php-email-tutorial\/'>Ajax FormData Object No Body PHP Email Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Ajax FormData Object No Body PHP Email Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body_email.jpg\" title=\"Ajax FormData Object No Body PHP Email Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Ajax FormData Object No Body PHP Email Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a title='Ajax FormData Object No Body PHP Primer Tutorial' href='#afdonbphppt'>Ajax FormData Object No Body PHP Primer Tutorial<\/a> kept the pledge of the project to only have webpages with no document.body (ie. body tag) content.  But it was a closed book, so to speak.  We equate &#8230;<\/p>\n<ul>\n<li>sharing (and\/or collaboration) talk regarding web applications &#8230; with &#8230;<\/li>\n<li>accountability<\/li>\n<\/ul>\n<p> &#8230; in that yesterday&#8217;s incarnation of the web application, at least the &#8220;user experience&#8221; of using it, could not be shared (or accounted for) using the web application&#8217;s own functionality.<\/p>\n<p>But because we have used a serverside language like PHP as the programming language of choice with this project, there are ways to make it accountable <i>and<\/i> keep our pledge.  The first of these &#8220;sharing&#8221; mechanisms is email, using PHP&#8217;s <a target=_blank title='PHP mail method information' href='http:\/\/php.net\/manual\/en\/function.mail.php'>mail<\/a> function.<\/p>\n<p>How do we derive what PHP mail needs to construct an email to share this &#8220;Speech Bubble&#8221; web application, as in a snapshot of time?<\/p>\n<ul>\n<li>email (to) address &#8230; get that off the user (again via Javascript <a target=_blank title='Javascript prompt window information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/met_win_prompt.asp'>prompt<\/a> window(s)) &#8230; and &#8230;<\/li>\n<li>subject line &#8230; will hardcode as &#8220;Speech Bubbles&#8221; &#8230; and &#8230;<\/li>\n<li>HTML <b>content<\/b> (avoiding the Spam weakness of needing to perform any Javascript with it) &#8230; as per (the Javascript snippet within <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php-GETME\" title=\"no_body.php\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php-GETME\" title=\"no_body.php\">no_body.php<\/a> PHP <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php\" title=\"Click picture\">live run<\/a>) &#8230;<br \/>\n&lt;?php<br \/>\n<code><br \/>\n  function doemail() {<br \/>\n  ezhr=new XMLHttpRequest();<br \/>\n  eform=new FormData();<br \/>\n  eform.append('to', '\" . $emailto . \"');<br \/>\n  eform.append('subject', 'Speech Bubbles');<br \/>\n  eform.append('html', <b>'&lt;html&gt;&lt;head&gt;' + document.head.innerHTML.split('&lt;sc' + 'ript')[0].replace(' 49px',' -400px') + '&lt;\/head&gt;&lt;!--body&gt;&lt;\/body--&gt;&lt;\/html&gt;'<\/b>);<br \/>\n  ezhr.open('post', '\/\/www.rjmprogramming.com.au\/HTMLCSS\/emailhtml.php', true);<br \/>\n  ezhr.onreadystatechange = showEStuff;<br \/>\n  ezhr.send(eform);<br \/>\n  }<br \/>\n<\/code><br \/>\n?&gt;\n<\/li>\n<\/ul>\n<p> &#8230; that tad less complex a task as it might have been had we been allowed any document.body (ie. body tag) content.  Yet another useful way PHP and Javascript (this time with <a target=_blank title='Ajax information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Ajax_%28programming%29'>Ajax<\/a> and the use of <a target=_blank title='FormData object information' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/FormData'>FormData<\/a> objects) can combine in their powerful ways!<\/p>\n<p>How do we differentiate functionality parts to the PHP?  As we quite frequently do, we differentiate the &#8230;<\/p>\n<ul>\n<li>single user (no sharing) Ajax\/FormData POST method that navigates within the first instantiation of the webpage &#8230;<br \/>\n&lt;?php<br \/>\n<code><br \/>\n  foreach( $_POST as $name=&gt;$val ) {<br \/>\n    if ($one == \"\") {<br \/>\n      $one=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    } else if ($two == \"\") {<br \/>\n      $two=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    } else if ($three == \"\") {<br \/>\n      $three=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    } else if ($four == \"\") {<br \/>\n      $four=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    } else {<br \/>\n      $one=$two;<br \/>\n      $two=$three;<br \/>\n      $three=$four;<br \/>\n      $four=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    }<br \/>\n  }<br \/>\n<\/code><br \/>\n?&gt;<br \/>\n &#8230; as distinct from &#8230;<\/li>\n<li>email location.href URL GET arguments (Javascript call) method &#8230;<br \/>\n<code><br \/>\n  if (emailto.indexOf('@') != -1) {<br \/>\n  location.href=document.URL.split('#')[0].split('?')[0] + '?to=' + encodeURIComponent(emailto) + '&rest=' + encodeURIComponent(document.title);<br \/>\n  }<br \/>\n<\/code><br \/>\n &#8230; that navigates to a new instantiation of the webpage &#8230; and we do <b>extra checks<\/b> as per &#8230;<br \/>\n&lt;?php<br \/>\n<code><br \/>\n  foreach( $_GET as $name=&gt;$val ) {<br \/>\n    if ($one == \"\") {<br \/>\n      $one=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      <b>if (strpos($one, \"@\") !== false) {<br \/>\n        $emailto=$one;<br \/>\n      } else {<\/b><br \/>\n        $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n        $title.=\"|\" . $val;<br \/>\n        $nextone++;<br \/>\n      <b>}<\/b><br \/>\n    } else if ($two == \"\") {<br \/>\n      $two=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      <b>if (strpos($two, \" ... |\") !== false) {<br \/>\n        $one=\"\";<br \/>\n        $fields=explode(\"|\", explode(\"... |\", $two)[1]);<br \/>\n        $two=\"\";<br \/>\n        $gats.=\"  You can email to an entered email address what you have so far.\";<br \/>\n        for ($ii=0; $ii&lt;sizeof($fields); $ii++) {<br \/>\n          if ($one == \"\") {<br \/>\n            $one=$fields[$ii];<br \/>\n          } else if ($two == \"\") {<br \/>\n            $two=$fields[$ii];<br \/>\n          } else if ($three == \"\") {<br \/>\n            $three=$fields[$ii];<br \/>\n          } else if ($four == \"\") {<br \/>\n            $four=$fields[$ii];<br \/>\n          } else {<br \/>\n            $one=$two;<br \/>\n            $two=$three;<br \/>\n            $three=$four;<br \/>\n            $four=$fields[$ii];<br \/>\n          }<br \/>\n          $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $fields[$ii] . \"\\\");\\n\";<br \/>\n          $title.=\"|\" . $fields[$ii];<br \/>\n          $nextone++;<br \/>\n        }<br \/>\n      } else {<\/b><br \/>\n        $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n        $title.=\"|\" . $val;<br \/>\n        $nextone++;<br \/>\n      <b>}<\/b><br \/>\n    } else if ($three == \"\") {<br \/>\n      $three=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    } else if ($four == \"\") {<br \/>\n      $four=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    } else {<br \/>\n      $one=$two;<br \/>\n      $two=$three;<br \/>\n      $three=$four;<br \/>\n      $four=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    }<br \/>\n  }<br \/>\n<\/code><br \/>\n?&gt;\n<\/li>\n<\/ul>\n<hr>\n<p id='afdonbphppt'>Previous relevant <a target=_blank title='Ajax FormData Object No Body PHP Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/ajax-formdata-object-no-body-php-primer-tutorial\/'>Ajax FormData Object No Body PHP Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Ajax FormData Object No Body PHP Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.jpg\" title=\"Ajax FormData Object No Body PHP Primer Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Ajax FormData Object No Body PHP Primer Tutorial<\/p><\/div>\n<p>We think the combination of <a target=_blank title='Ajax information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Ajax_%28programming%29'>Ajax<\/a> and the use of <a target=_blank title='FormData object information' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/FormData'>FormData<\/a> objects interesting as a &#8220;navigation in midair&#8221; concept.  In fact, today, we got to use it, with PHP, to the point where we construct a webpage of some little functionality and interactivity that does not have any content in its <i>body<\/i> tag.  This webpage has &#8230;<\/p>\n<ul>\n<li><i>html<\/i> tags<\/li>\n<li><i>head<\/i> tag consisting of &#8230;<\/li>\n<ol>\n<li><i>title<\/i> tag<\/li>\n<li><i>style<\/i> tag<\/li>\n<li><i>script<\/i> (type=&#8217;text\/javascript&#8217;) tag<\/li>\n<\/ol>\n<\/ul>\n<p> &#8230; and that&#8217;s it.  And yet, we ask for interactive input in a Javascript <a target=_blank title='Javascript prompt window information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/met_win_prompt.asp'>prompt<\/a> window, and change content in four &#8220;speech bubble&#8221; like places within a webpage.  So take a look at the PHP <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php_GETME\" title=\"no_body.php\">no_body.php<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php\" title=\"no_body.php\">live run<\/a>, dynamically constructing (HTML\/)CSS\/Javascript via <a target=_blank title='Ajax information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Ajax_%28programming%29'>Ajax<\/a> and the use of <a target=_blank title='FormData object information' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/FormData'>FormData<\/a> object returns that are &#8230;<\/p>\n<p><code><br \/>\n document.write([Ajax_FormData_return_content]);<br \/>\n<\/code><\/p>\n<p> &#8230; never leaving the initial webpage.  We try to trick you thinking otherwise perhaps, by adding to <i>document.title<\/i> the last interactively entered data snippet.  And through all this, still no need for content in any webpage <i>body<\/i> tag.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d46947' onclick='var dv=document.getElementById(\"d46947\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/style\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d46947' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d46963' onclick='var dv=document.getElementById(\"d46963\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/email\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d46963' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d46984' onclick='var dv=document.getElementById(\"d46984\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/pdf\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d46984' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Continuing on with the sharing ideas emanating from yesterday&#8217;s Ajax FormData Object No Body PHP Email Tutorial sharing (or accountability) &#8230; emailing HTML attachment functionality &#8230; today (shame about the spoiler alert in the blog posting title &#8230; but nevertheless &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/ajax-formdata-object-no-body-php-pdf-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[2098,69,111,1604,257,281,352,380,2730,2430,2212,576,652,738,849,913,932,997,1761,1133,1137,3125,1209,1238,1319,1418],"class_list":["post-46984","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-accountability","tag-ajax","tag-attachment","tag-collaboration","tag-content","tag-css","tag-document-write","tag-email","tag-formdata","tag-fpdf","tag-head","tag-html","tag-javascript","tag-mail","tag-object","tag-pdf","tag-php","tag-programming","tag-prompt","tag-share","tag-sharing","tag-spam","tag-style","tag-table","tag-tutorial","tag-webpage"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/46984"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=46984"}],"version-history":[{"count":7,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/46984\/revisions"}],"predecessor-version":[{"id":47009,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/46984\/revisions\/47009"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=46984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=46984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=46984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}