9 Replies Latest reply on Feb 9, 2013 11:14 AM by mbraendle

    How to add HTML code via a FileMaker field?

    mbust

      Hello,

       

      Here's what I hope is an easy question: I can easily add text to a web page via PHP from a Filemaker field, but how do I add HTML code from a FM field to a web page and render it properly?

       

      I have a shopping cart that generates AddToCart code for its button (i.e., <form>...</form>), which I'm supposed to paste to the web page of the actual product. But the page is dynamically generated and so should the button. So what I did was to put the html button code in a FM field for the related product and would like the web page to generate the button.

       

      Problem is, when the page is generated, I can only succeed at entering the html code as text, not as code. So the PHP echo or print commands actually show to the user the code, eg., "<form action=. . . </form>" and not the button.

       

      Any way to make the button show up properly?

       

      Thanks!!

        • 1. Re: How to add HTML code via a FileMaker field?
          jml

          Have you tried prefixing your HTML code with:

           

          "data:text/html, <!DOCTYPE HTML> "

          • 2. Re: How to add HTML code via a FileMaker field?
            mbust

            Like this:  <?php  echo "data: text/html, <!DOCTYPE HTML> " . $AddToCart ; ?>? Where $AddToCart is the field with the code, "<form> ...</form>".  I just tried it and got the same problem:  the page displays the text, "data: text/html,  <form action . . . </form>" and not the actual button.  I can go for a much less elegant way by creating a file with the code and then using PHP include, but I would rather do it directly from the database.

             

            Thanks for your help!

            • 3. Re: How to add HTML code via a FileMaker field?
              jml

              I was thinking more like:

               

              "data:text/html, <!DOCTYPE HTML>" & $AddtoCart

               

              where $AddtoCart is a variable with the code: <html>…your html code…</html>

               

              but this may not be applicable to your use of PHP.

              • 4. Re: How to add HTML code via a FileMaker field?
                mbust

                Is "data:text/html" HTML or PHP?  If HTML, I would need a tag, and if PHP, it needs <?php.  No?

                • 5. Re: How to add HTML code via a FileMaker field?
                  jml

                  Neither.  That's why it may not be applicable to your needs.

                   

                  When the web address of the FileMaker webviewer is set to data:text/html, <!DOCTYPE HTML>, the webviewer executes the appended text as HTML code.

                  • 6. Re: How to add HTML code via a FileMaker field?
                    mbust

                    Right.  It is not working with CWP.  Using the Include command works, though.  Not pretty, but it works.

                     

                    Thanks.

                    • 7. Re: How to add HTML code via a FileMaker field?
                      beverly

                      mbust (and jml) let's try to clarify:

                       

                      1.     the data URL is meant to be a SNIPPET of html AND if included inside another page definitely does NOT get the !DOCTYPE nor any of the head parts. Body is not used here either. You are already declaring the MIME-type

                           :text/html

                      and further declarations are unnecessary.

                      <http://en.wikipedia.org/wiki/Data_URI_scheme>

                      You should not get a page (dynamic or otherwise) that was:

                           html
                                head
                                /head
                           body
                                html
                                     head
                                     /head
                                     body
                                     /body
                                /html
                           /body
                           /html
                      

                      If I was a browser I'd have a fit at this.

                       

                      2.     We do not know what is serving the page(s) from FMP fields other than "PHP". Is Joomla, Drupal, OSCommerce, WordPress, or other framework being used? frameworks may have "code" turned off to prevent users from entering "code" in form fields. Some allow the use of a module or plug-in to turn it back on and/or have a master switch for this when code is entered from an admin console.

                       

                      3.     "code" inside a field (FileMaker, MySQL or SQL) can get often get encoded by PHP configuration. Please research the use of these PHP functions to see if they help:

                           htmlspecialchars()

                           urlencode()

                      *these two lead to other functions that may be helpful

                            

                      <http://www.php.net/manual/en/faq.html.php>

                       

                      HTH,

                      Beverly "web ma'am" Voth

                      • 8. Re: How to add HTML code via a FileMaker field?
                        mbust

                        Right.  The double declaration would not help at all.  From a quick look htmlspecialchars() with ent_html401 might do the trick. I'll look into that. For now, I've created an AppleScript to take the code for each of the related fields, automatically generate an HTML file (without any declarations), and upload it to the server. That makes the code available as a PHP include.  Like I said, not very elegant, but now that it is done, it works very fast.  And since button updates are not needed every day, it should work for now.  Once I finish with other details currenly pressing on my time, I will return to this and clean it up. 

                         

                        Thank you very much!