Limit Find Fields/ Options

A place for users and developers of the Xataface to discuss and receive support.

Postby moj0rising » Thu Jan 25, 2007 3:27 pm

I need to set things up so upon logging in to my Dataface application, users are presented with a limited search page -- one that only has 2 fields/ criteria to search by instead of the standard form that allows users to search by any field in a given table (hopefully that makes sense).

The hardest part seems to be finding a way to limit what users can search by -- I have checked high and low and looked through the code and can't figure it out. I also still want to keep the existing find form where it is so it could be used later so I just need to create a new trimmed-down one.

Can anyone give me a push (or shove) in the right direction on how I should go about this?

Steve, thanks a lot for putting out this incredibly awesome tool! It has helped me incredibly.


Mike
moj0rising
 
Posts: 26
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Jan 25, 2007 4:21 pm

Hi Mike,

There are a few ways to attack this problem. Honestly, the easiest way is to exploit Dataface's url conventions (http://framework.weblite.ca/documentation/link/introduction-to-dataface-urls/view) and just make your own form on a custom action.

If your form puts the proper field names to what the user is searching, then it will automatically put him in the right place. You could add this search box to the left column and make it always available (using a block), or create a custom action and have this search box as the main content for that action.

I know this is conceptual and perhaps requires some examples, but hopefully it gets you on the right track. If you want clarification or examples, let me know, and I'll see what I can come up with.

If there are things about the Dataface search form that you like, and you'd rather use it trimmed, down, there is a df_create_search_form() function that allows you to programmatically create a search form with only specific fields.. If you want more info about that, I can give examples too - but it sounds like the first option will probably be the easiest.

Best regards,

Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby moj0rising » Thu Jan 25, 2007 5:45 pm

I read the presentation you linked me to and attempted to follow it but I must be messing something up -- it says "no records found." :(

I get no records found when I try to follow you examples in the link you sent. :(
There are a bunch of fields in my database. I need to give users the ability to refine by "jurisdiction" and "status." So a user who logs in from California can search for all records for California with a status of approved.

I followed the example, Index.php?-action=list&-table=People&FirstName=Bob with -action=list&-table=certifications&Jurisdiction=California

The output is "No records matched your request."

I also tried the -search parameter with the same results.

It also seems like I might need to pursue your second option. I'm not sure -- if the first is the easiest, then that's the one for me though.

Would you mind throwing in a quick example on what I should do to get a search page with only those two fields upon login?

Sorry I didn't get that one on the first try. I really appreciate your help.


Mike
moj0rising
 
Posts: 26
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Jan 25, 2007 6:07 pm

The examples that you cite should work. One thing to make sure is that for field and table names, capitals matter. Also, if you are using valuelists for any of the fields, you should be searching on what is actually stored in the database, not the associated label for that value.

E.g. if your Jurisdiction field stores integers and uses a valuelist like:
[jurisdictions]
1=California
2=Washington
3=Oregon

Then your query should include Jurisdiction=1 and not Jurisdiction=California.

Let me know if this is not the case... otherwise if you can give me a link to the app, I can take a closer look.

Best regards

Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby moj0rising » Thu Jan 25, 2007 6:26 pm

Cool. That part works. I knew I was doing something wrong there.

I used the value name (e.g California) instead of the value on the left of the = (CA).

Now how can I put this together in a way people can use?
moj0rising
 
Posts: 26
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Jan 25, 2007 8:12 pm

All you need to do is add a form somewhere on the page that allows the user to enter the search criteria, .
e.g.
Code: Select all







<:input type="submit" />



An easy way to play around with this to see how it works (see if it works), is to put it in the Dataface_Application_Menu.html file in your templates directory. (This will get included in the left column of your application on all pages).

Alternatively you can create a custom action and place this in the content (see the getting started tutorial for info about custom actions).

I suspect that it will be about 2 seconds before you want to be able to use your jurisdictions valuelist to make a pull-down menu. A tip: The Dataface_Table class has a getValuelist() method that will return a valuelist by name as an associative array. e.g.:

$table =& Dataface_Table::loadTable('certifications');
$jurisdiction_options = $table->getValuelist('jurisdictions');
// will return an associative array like array('CA'=>'California', 'WA'=>'Washington', etc...).

Then you can take this array and loop through it to form a select list - in either smarty or direct PHP.

However, once your into that, you may just want to use the df_create_search_form() function as follows:
Code: Select all
$form = df_create_search_form('certifications', array(), array('jurisdiction','another_field'));
if ( $form->validate() ){
    $form->process();
}
echo $form->display();


Best regards

Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby moj0rising » Thu Jan 25, 2007 8:59 pm

I know I am so close now!

I did mess something up, though.

Now, when I go to my site, I get this message instead, "Fatal error: Class 'actions_list' not found in /var/www/dataface/Dataface/Application.php on line 763"

I added the form elements you printed above to Dataface_Application_Menu.html in my application's templates directory and edited my actions.ini file to say:

[list]
template=Dataface_Application_Menu.html


Trying to work through it. I'm gonna take a break for now.

I would point you to my site but it is on an internal network right now. I'll try to change that soon so I can at least work on it from any location easier.


Thanks, again,

Mike
moj0rising
 
Posts: 26
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Jan 25, 2007 11:36 pm

OK.. One thing. The 'list' action is predefined in Dataface to be the list view. You don't need to redefine it in your actions.ini (nor should you). I used the Dataface_Application_Menu.html example for a template because it is set to automatically be included in the left column if it exists. You wouldn't even need to create a new action if you placed the form in that file.

If you create a new action, just call it something else:
e.g.

[my_action]
template=my_action_template.html

Then to access this action, you would just include -action=my_action in the get params of the url.


-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby moj0rising » Fri Jan 26, 2007 11:19 am

OK. Now my site comes up when I go to its URL but when I attempt a search, I get:


Fatal error: No template found for action '-list'.On line 48 of file /var/www/dataface/actions/default.php in function printStackTrace()
On line 801 of file /var/www/dataface/Dataface/Application.php in function handle(array(array(-list,-list)))
On line 1152 of file /var/www/dataface/Dataface/Application.php in function handleRequest()
On line 19 of file /var/www/torpedo/index.php in function display()
in /var/www/dataface/actions/default.php on line 48


I'm poking around to see what I changed that shouldn't have been changed.


Mike
moj0rising
 
Posts: 26
Joined: Wed Dec 31, 1969 5:00 pm

Postby moj0rising » Fri Jan 26, 2007 12:11 pm

Progress! The above message stopped appearing when I took the "-" out from this statement just before list.



was changed to



Now I don't get any error message but I get "No results found" when I search.

Still checking around.


Mike
moj0rising
 
Posts: 26
Joined: Wed Dec 31, 1969 5:00 pm

Postby moj0rising » Fri Jan 26, 2007 12:12 pm

For some reason my code didn't show up there. Oh, well.

Mike
moj0rising
 
Posts: 26
Joined: Wed Dec 31, 1969 5:00 pm

Postby moj0rising » Fri Jan 26, 2007 12:20 pm

I think I'm getting no results because it wants the "code" for the jurisdiction and can't search by the name -- the database field type is VARCHAR. I'm trying to do the drop-down menu thing now. Is there any documentation on that I can follow?

Thanks,
Mike
moj0rising
 
Posts: 26
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Jan 26, 2007 12:50 pm

Note that Dataface uses Smarty for its templating and extends upon it. This means that you can use all of Smarty's built-in tags to make stuff happen in your templates.

For example, you can use {html_options} to produce a select list with an array of options.
http://smarty.php.net/manual/en/language.function.html.options.php

Here's a simple example. Let's say you have an action called my_action, and you create an action controller for this class (my_action.php in the actions directory of your app). (See the Actions section of the getting started tutorial for more on action controllers).
Code: Select all
class actions_my_action {

    function handle(&$params){
        $app =& Dataface_Application::getInstance();
        $query =& $app->getQuery();
        $table =& Dataface_Table::loadTable($query['-table']);

        $options = $table->getValuelist('jurisdictions');
       
        df_display(array('jurisdictions'=>$options), 'my_action.html');
    }
}

See http://dataface.weblite.ca/df_display for information about the df_display function.
The first 3 lines load the application object, the user's query parameters and the Dataface_Table object for the current table.

The call to getValuelist() returns an associative array of options defined in the jurisdictions valuelist (from your valuelists.ini file.

Then in your my_action.html template (in the templates directory, you could do something like:
Code: Select all
{use_macro file="Dataface_Main_Template.html"}
  {fill_slot name="main_section"}
   

   
   
    Jurisdiction: {html_options options=$jurisdictions name="Jurisdiction"}

   
   

  {/fill_slot}
{/use_macro}


See http://framework.weblite.ca/documentation/tutorial/customizing-the-dataface-look-and-feel/extending for information about the {use_macro} and {fill_slot} tags.
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Jan 26, 2007 12:56 pm

Alternatively you could just use the df_create_search_form approach, in which case your action controller would look like this:
Code: Select all
class actions_my_action {

  function handle(&$params){
    $app =& Dataface_Application::getInstance();
    $query =& $app->getQuery();
    $form =& df_create_search_form($query['-table'], $query, array('Jurisdictions', 'another_field'));
    if ( $form->validate() ){
      $form->process();
    }
    ob_start();
    $form->display();
    $form_html = ob_get_contents();
    ob_end_clean();
    df_display(array('form'=>$form_html), 'my_action.html');
  }
}

Then your my_action.html would look something like:
Code: Select all
{use_macro file="Dataface_Main_Template.html"}
  {fill_slot name="main_section"}
    {$form}
  {/fill_slot}
{/use_macro}


You may also want to check out the actions/find.php file in the dataface distribution for an example of the full find action controller to see how it works.

Best regards

Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby moj0rising » Fri Jan 26, 2007 4:23 pm

Sorry for asking so many questions. This part is a little tough for me.

I followed your example and reviewed the Smarty documentation. The only exception I made is that I put the form elements in my Dataface_Application_Menu.html file.

The drop-down menu appears but it does not seem to be getting the menu items from my valuelists.ini file. I checked capitalization and spelling, et cetera and all that looks the same across all files and the database tables.

Any ideas on what I could be doing wrong??


Thank you!

Mike
moj0rising
 
Posts: 26
Joined: Wed Dec 31, 1969 5:00 pm

Next

Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 13 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved