Load xforms in php - php

I am trying to load a xform in php application. When i put this code in php view file and its not showing submit button in the UI. How can load xform xml in php applications?
<h:html xmlns:h="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/2002/xforms">
<h:head>
<h:title>Search</h:title>
<model>
<submission action="http://example.com/search"
method="post" id="s"/>
</model>
</h:head>
<h:body>
<h:p>
<input ref="q"><label>Find</label></input>
<submit submission="s"><label>Go</label></submit>
</h:p>
</h:body>
</h:html>

XForms is not natively supported by browsers.
With PHP, it is not possible to use server-side implementations of XForms such as Orbeon or Betterform because they are written in Java.
You can give XSLTForms a try: it just require an XSLT 1.0 transformation which can be performed with PHP or directly by almost any browser, except for some limited mobile phones, using a processing instruction.
-Alain

Related

Dynamically create elements from unrendered code using jquery and/or php

I want to store html that isn't to be rendered until needed either within a tag that can hold raw html code without rendering it on page load or store it within a php or jquery variable for later use. I then want to be able to insert the html into the DOM on button click and have it render.
I've tried storing it within an xmp tag as that can store html code with the < and > characters without using character codes for them, but when trying to insert it into the DOM, the updated source shows it had been copied but it wouldn't render on screen. Also tried storing it within a code tag, which worked on a desktop browser but not in mobile safari. Since this is a webapp mobile browser compatibility is important.
Anyone know of a good method of doing this?
Try <script> tags with a type of text/plain or text/html:
<script type="text/plain" id="example">
<div class="example">
<h2>Hello</h2>
<p>World</p>
</div>
</script>
$(".button").click(function () {
var html = $("#example").text();
$("#destination").html(html);
});
It depends on where do you want to generate the content in question. If it's easier for you setup to generate it on the server side, you can use css to hide those parts (like display:none) and just remove the css property or grab the nodes with javascript and put them elsewhere with something like this:
$('.target').html($('.hidden_node').html());
If you want to generate the content on the js side, you can build it as a long string and just shove it into the target, or you can use jquery's node generation syntax like:
$('<div />').attr({
class: 'test'
}).appendTo("body");
Or you can use one of the various javascript templating solutions like mustache or handlebars.

how to convert dynamic contents of html page to pdf

In html page some tags are dynamically created using jquery and contents are loaded from msql db using jquery and php.
I want convert this dynamic page to pdf.
I have tried following code but it generate pdf of static part of html page.
<?php
ob_start();
?>
//html code and internal css, javascript used in external file with jquery library
<?php
include('dompdf/dompdf_config.inc.php');
$contents = ob_get_contents();
ob_end_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($contents);
$dompdf->render();
$dompdf->stream('file.pdf');
?>
So how to store contents of dynamic html page in a php variable after processing it ( using javascript/php ) and convert it to pdf usin dompdf or other converter.
I'd suggest you take a look at wkhtmltopdf. I've had good results with getting it to render google charts, which are built dynamically from a javascript api.
http://code.google.com/p/wkhtmltopdf/
As Marc said, you have to read generated DOM with javascript.. something like $('html').html() and then post it to php to generate pdf
This may not meet exactly what you are looking for, but wkhtmltopdf could be what you need. Since PHP is a server-side technology, you will have a difficult time getting it to process any client-side javascript. wkhtmltopdf scans the page, javascript and all, then generates a pdf file on the server. Hope this helps you out!
Consider using a tool like wkhtmltopdf to directly generate a page as a PDF. It will run javascript and generate the page as WebKit would render it.

How to update XML file with ajax?

I have xml storage with in this format
<Contacts>
<Contact>
<![CDATA["Some HTML"]]>
</Contact>
<Contact>
<![CDATA["Some HTML"]]>
</Contact>
</Contacts>
I am using XMLHttpRequest to read the data and put it inside a "div" on the page. Now I make some changes on it via JavaScript and I would like to know how can I update the changes made back to the XML file from where I took the data.
I've been googling a lot but I have problems understanding those forums because they are not describing examples similar like mine.
Try using a ajax call which you give the xml data. You can then save the data using simplexml http://nl.php.net/manual/en/book.simplexml.php or using http://nl.php.net/manual/en/book.domxml.php
Leave the "retrieving" your XML on JavaScript, and "saving changes" on PHP. Using jQuery you just $.get() your XML file, and when you save it (let it be .click, .live('click') etc.)
you $.post() strings you wrote in some input to something like save_xml.php. There are some tools for working with XML files in PHP. If you get on well with Smarty, I advise you to keep sort of my_xml_template.tpl , which after smarty->fetch you save in a file with file_put_contents(). Cheers.

Rendering HTML to PNG / JPEG

I am looking for a php library or an unix shell tool to render a HTML page into a single png/jpg image.
Is there any?
I found a promising project.
It rendered the following code in 0.133 seconds using the webkit plugin.
<html>
<body>
<b><u>abc</u></b>
<table><tr><td>abc</td></tr></table>
</body>
</html>
http://sourceforge.net/projects/cutycapt/
Unfortunately it works only for Windows.
There is another webkit implementation using python.
XServer-less webpage screenshot
http://www.insecure.ws/2008/09/16/xserver-less-webpage-screenshot

Displaying an XML file with XSL within an existing webpage

I'm trying to get an html page to display an XML file formatted with an XSL stylesheet. Whatever examples I see are either displaying it in a new page, with the XSL stylesheet taking care of the tags, but no examples where I can clearly see it being displayed as part of an existing webpage...
I'm using a PHP script to generate the HTML. And the XML data is being generated by another PHP function (not under my control). The XSL file is uploaded on the server and stored at: /xsl/1234567890.xsl
Here's what the php outputs:
<html>
...
<body>
...
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/xsl/1234567890.xsl"?>
...
<xml tags>
...
What am I doing wrong?
Two ways to transform the XML:
1 browser
Most browsers implement XSLT processors. You could use:
<iframe src="xml-source.xml"/>
The users will have to make three requests (page, xml, xsl) and unless you want inline scrollbars you'll need some Javascript to resize the iframe.
2 server
You can run a XSLT processor on the server side and return the transformed XML. There are many ways to do this, here is one in PHP. With caching you shouldn't run into any performance problems and also support browsers without internal XSLT processors (e.g. mobile devices).

Categories