lost password?

home
•  xaraya +
•  rails
•  django
•  webdev
•  xamp
•  musings

rss
Tag this page
   

ยป Blogs that link here
last modified: Feb 19, 2007
(first posted: Feb 06, 2007)
(1465 Reads)
keywords: pageform
Permalink

Another Neat Example of Pageforms

I had a need for a form and function solution, and pageforms provided a quick and easy way

Rather than describe my application directly, I give a generic (hopefully not lame) example.

Suppose you need to perform an operation on your site with specific inputs, and show specific results, and you can implement the operation as a php function.

A. Let's put the api function in modules/xarpages/xarcustomapi/myfunc.php (although it could go in your own module). The api accepts a set of args, and returns a hash array with results.

/* myfunc
* args 'a'=>$a, 'b'=>$b, 'c'=>$c
* returns array: 'x'=>$x, 'y'=>$y
*/
function xarpages_customapi_myfunc( $args )
{
extract($args);
	... do your thing... 
	return array( 'x' => $x, 'y' => $y );
}

B. Create 2 DD objects, say 'objf' and 'objr' (for the form and results fields respectively). Define the dynamic properties of objf as 'a', 'b', and 'c'. Similarly define the properties for objr object as 'x' and 'y'. Set the field types and validations as needed.

C. Create a pageform tree like this

'page' type:html
|-- 'pagef' type:pageform
|-- 'pagea' type:pageaction
|-- 'pager' type"pageform

the 'page' page can be status:empty

the 'pagef' page has data item:objf. Perhaps set required:a,b,c as needed

the 'pagea' page has processing php:

$outvalues = xarModApiFunc('xarpages', 'custom', 'myfunc', $values );  

the 'pager' page, has data item:objr, and give it template 'displayonly'

If you don't have a displayonly template, create one by copying xarmpages/xartemplates/pageform.xd to pageform-displayonly.xd. Remove the <form> tag and all inside it, and replace it with this:

<xar:if condition="!empty($current_page.dd.formlayout)">
<xar:data-display object="$pageform['object']" layout="$current_page['dd']['formlayout']" />
<xar:else />
<xar:data-display object="$pageform['object']" />
</xar:if>

That's it! Now you have an input form to the function, and display the results.

 

 

 

There are no comments attached to this item.

Post a new comment

: This is not spam

Name :