Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Form App

edited October 2012 in Apps

Hello strangers. :-) Question JB about the Form App. First question is...can I format the date picker to where it displays the date to be mm-dd-yyyy instead of yyyy-mm-dd? Second question do I produce a page to show the results of the entries? I need it to be in a tablular style format with the headings on top the columns. (pretty much like an excel sheet). I want to use it to where the person logs in to the site and only sees the home page and the listing page. I don't want them to be able to access the form entry page. It's a medical web app I am working on for my cousins business. Other than my lack of knowledge...the app is great!



  • The dates are stored in yyyy-mm-dd format, so once selected that's how they end up in the field. You would have to edit the source to change the format then convert it back behind the scenes.

    If you want to read the results of a form, you'll want to look at the form\Results class. For example:

    // Get all results from form with ID 1 from newest to oldest
    $results = form\Results::query ()
        ->where ('form_id', 1)
        ->order ('ts desc')
        ->fetch ();
    foreach ($results as $entry) {
        echo $entry->results->name . ' - ' . $entry->results->email . '<br />';

    Just change the form ID, and the field names in the loop correspond to the names of the fields you've created in the form.

  • Do I use this on a view page? Kind of how the blog app is built and setup?

  • You can paste that into the contents of any handler script. For example, save it to apps/test/handlers/myresults.php then visit /test/myresults in your browser and it should print out the results from form #1, assuming of course that it has name and email fields.

  • So what is the results.html file for thats in the /app/form/views folder? Is there a way to get it to be a dynamic object that I can select from the menu like the blog feed or post does? Or do I just point the page to the url /test/myresults?

    To better explain what I am doing is...eventually I need this to be multi user. Here is the scenario....

    A person enters jobs into the form. She selects the facility the job is for. The results get put onto a list page that has a menu item. The facility that the jobs were completed for only get to see the home page and list page and it will only show the results for their facility based on what was selected in the drop down box of the form. It then displays the results in an excel like format on the list page to those who work for that specific facility.

    Hope that clarifies the overall application I am trying to do.

  • One other thing...I don't want it to email to anyone. I just need it to display on the page. I tried what you said but it doesn't show me any results. The url /form/results?id=1 shows me the listing of all the results and then if I click on brings me to url /form/result?id=1 and says Browsing Result:1 and then list the results in an almost bulleted style list minus the bullets.

  • If you want to publish the form results to a page on your site, you'll need to make a custom handler for that. The results list in the form app is an admin-only screen. But form\Results is a Model object, so it's just a matter of querying it for the results you want to show, and displaying them to the user.

    Afterwards, to make your custom handler available in the wysiwyg editor, you would follow the steps here:

  • Reading it now and trying to make sense of it. I will let you know if I am successful or not. Thanks

  • I see there are 2 files in the handlers folder. I am assuming those both are for result views in the admin section of the site.

    If I create another handler named listresults and style it like I want using:

    ; <?php /* [appname/myhandler] label = My Label columns = 8 ; */ ?>

    Am I remotely close?

  • If you create a handler named apps/appname/handlers/listresults.php, your embed file would be named apps/appname/conf/embed.php and would look like this:

    ; <?php /*
    label = List form results
    ; */ ?>

    The label is the name the handler will appear under in the Dynamic Object menu, and the [appname/listresults] part points to the handler itself.

    I would also recommend creating a separate app for your own code, and not adding this to the form app. That will help keep it separate and make it easier to upgrade things down the road. If these are handlers that are only for one site, then you can even just name the app after the site name, for example on I would name the app "mysitename".

  • So is it safe for me to copy the forms app and then just rename the folder what I want as well as the places needed inside the files as well?

  • If you rename it, most of the links will refer to the original. But if you just need a piece of the functionality, you can leave the app as it is and just copy the handlers you want to customize into your own app then modify those. For example, you could take the results.php handler and modify it to output in the way you need it to for your site.

  • Got ya. Well...I have the dynamic object appearing in the menu and was able to add it to a new page. That part now I guess I need to modify the handler to output the data in the table format I want.

  • Here is what I have for my handler /form/listresults but I get a completely blank white page.

  • The first line should be changed to this:

    $res = new form\Results ($_GET['id']);

    Let me know how it works from there.

  • Alright...when I changed that line as you said....I get the following error

    Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.

  • A couple things going wrong here:

    $res = new form\Results ($_GET['id']);
    if ($res->error) {
        $this->redirect ('/form/listresults');

    First, you need to supply an ?id=1 in the URL or the redirect is going to happen every time. You could also just replace $_GET['id'] with a specific ID if you're trying to limit it to results from one form.

    Second, the redirect is simply sending you to the current page, so it's creating an endless loop. You may want to change it to something like this instead:

    if ($res->error) {
        $page->title = i18n_get ('No results found.');
        printf ('<p><a href="/">%s</a></p>', i18n_get ('Home'));

    Hope that helps.

  • edited October 2012

    So would I use $_Get['id=1"] to set it to a specific form? It is only one form that entries get added to and shows the results on the results page. Seems like it should be an easy process but for some reason I cannot figure it out.

    I like the no results deal now...thanks for giving me that. Its perfect solution for errors.

  • edited October 2012

    You would actually want to say this instead:

    $res = form\Results::query ()
        ->where ('form_id', 1)
        ->order ('ts desc')
        ->fetch ();

    This creates a query for all the results with form_id=1, basically the equivalent of this SQL:

    select * from results where form_id = 1 order by ts desc

    The other way ($res = form\Results (1);) would be more like this:

    select * from results where id = 1

    Then you would say:

    if (! $res) {
        // error code here

    Instead of checking for $res->error.

  • That gives me a page with just the page title on it. I have 2 entries in the db but nothing displays on the results page. My handler is called listresults.php. Any other ideas?

  • What's your current handler code and view template look like? I can try to recreate and see what's up from there.

  • On the road right now but will send it ASAP.

  • Here is the handler code

    Here is the view template code

  • Using ($res = form\Results (1);) or this $res = form\Results::query () ->where ('form_id', 1) ->order ('ts desc') ->fetch ();

    gives me a blank white page.

    The only thing that display no results (even though there are entries) is

  • I've put together a working example with comments explaining it here:

    I did use the new looping syntax in the template that's only in the beta releases though, but otherwise this should work. The looping change just eliminates hard-coding the fields into the template. Hope that helps!

  • Will check it out as soon as I get done working. Thanks J!!!

  • That's brilliant J! It works like a champ. Now I just need to modify it so it doesn't show ip address and date submitted. the admin section, if I press on the 1 under results, it gives a page could not be found error. Which file would I need to modify the link so it brings up the results for that entry?

  • So I went in listresults.html and removed the lines about the submitted and ip labels as well as the entry lines regarding the date and ip now I have it showing exactly what I want it to show.

    Now if I can fix the admin section where clicking on the number of the entry under results not working...that would be good.

    Also...I want to add a drop down to the form called facility. This is so when you click on a facility name, based on the user logged in...I want it only to bring up the results for that particular facility. Is there a simple way to do this?

  • I have added a Facility field to the form so that way the query can be done based on user connection to facility. I need to see how I would set it to where when I add a user to the system and specify which facility they belong to...they access the joblist and it runs a query and list only the results that are related to that facility.

  • It sounds like you may be trying to do more with the results than the form app was built to handle. Form results are stored as a JSON object in a text field in the database, which means it can't index by any given form field.

    Usually, for something like this you would want to create your own database table and have the form write to that instead of using the form app, which is more for one-off forms like a contact or feedback form. From there you would create a Model object based on your database table and query that in the listresults handler, which you could then easily add a couple lines to limit by a "facility" field, for example:

    // Fetch the results
    $q = myapp\MyModel::query ();
    $q->order ('ts', 'desc');
    if (isset ($_GET['facility'])) {
        $q->where ('facility', $_GET['facility']);
    $res = $q->fetch ($limit, $_GET['offset']);

    This assumes a model class defined like this:

    // apps/myapp/models/MyModel.php
    namespace myapp;
    class MyModel extends \Model {
        public $table = 'my_database_table';

    That's probably a better bet for a page requiring more complex output based on the form data.

  • My problem is that I am not sure how to write it to be secure. I tried writing a form one time in php that wrote to a database table and a developer I know was like I can intercept your information. So...are you saying I should write a add.php file that adds to the database...then take the listresults file and use it to query the information? I am really not a developer so its hard for me to understand.

Sign In or Register to comment.