List View Filtering/ Multiple fields.ini Files?
10 posts
• Page 1 of 1
OK. Now I'm told my application has to be able to show different fields depending on certain criteria.
I want to do this my having 2 - 4 different buttons on the bottom of the page. As an example, when a user clicks on button 1, the list view comes up showing fields A, B, and C (and all other fields are not visible in list view). When the user clicks on button 2, the list view instead shows only fields D, E, and F. This seems like it could be done by using multiple fields.ini files but I don't know and I don't know how that would be done if it is possible. Can someone tell me what the best (hopefully an easy) way to do this is? Thanks, Mike
OK.. this is possible.Ê All of the information from the fields.ini file is loaded into an associative array at run-time.Ê You can modify this information using PHP to suite your needs. You just need to:
if ( *button 1 was pressed*){ ÊÊÊ $table =& Dataface_Table::loadTable('mytable'); ÊÊÊ $fields =& $table->fields(); ÊÊÊ foreach (array_keys($fields) as $fieldname){ ÊÊÊÊÊÊÊ if ( in_array($fieldname, array('A','B','C') ){ Ê Ê Ê ÊÊÊÊÊÊ $fields[$fieldname]['visibility']['list'] = 'visible'; Ê ÊÊÊÊÊ } else { Ê Ê Ê ÊÊÊÊÊÊ $fields[$fieldname]['visibility']['list'] = 'hidden'; Ê ÊÊÊ } } else if (*button 2 was pressed*){ ÊÊÊ //.. same thing, but changing the visiblity of different fields according to what you want. }
As I'm sure you have noticed by now, I'm pretty new to PHP.
How can I track which button was pressed w/ GET variables? In other words, what goes in-between the *'s in the line, if ( *button 1 was pressed*){ ? Mike
hello,
in order to utilize the 'GET' superglobal array, simply append key/value pairs to the url associated with each of your buttons, for example: http://www.dfapp.com/index.php?-choice=button1 for button 1 http://www.dfapp.com/index.php?-choice=button2 for button 2 I used a '-' before the variable name to keep in line with Steve's set-up. Then in your conditional statement, you can access the value of 'choice' in a number of ways. Example: $mychoice = $_GET['choice'] will assign the value to the local variable '$mychoice', which you can then use to test in the if/else statements. The key here is to note that all values that are passed via the url string are available inside the $_GET[] array. if( $mychoice == 'button1' ) { //do stuff } else if ( $mychoice == 'button2') { //do other stuff }
quick fix, it should be: $mychoice = $_GET['-choice']
sorry about that... hello,
$table =& Dataface_Table::loadTable('certifications');
thats the line that is giving this error: Fatal error: Undefined class name 'dataface_table' in ........index.php on line 28
Thanks a ton, that helped a great deal, got that working and just realized I need to further my sql query based on which button is pressed. Is there an easy way to do this?
Right now I have my form that has 2 drop down's and 2 submit buttons (type="submit" name="button") for both. in the index.php I use the GET to see which value of "button" was sent, and based on that I modify the fields to be hidden/shown. Is there a way, now, to sort of add to the form. I need one button to filter the search to show only one type of media 'MediaType' in the table, and the other button to show all other types of media,but both searching based on the 2 drop down's. Thanks in advance! -Kurtis
I would do it with 2 separate forms.Ê Place hidden fields in each form to specify your search parameters with consideration for the dataface url conventions.Ê This will allow you complete flexibility as to what query parameters are sent with each button. One helpful tip: The Dataface_Application class has a method url() that will produce a url with all of the current query parameters intact, plus any changes you make. e.g. $app->url(''); Will return a full url to the current page. $app->url('-action=foo'); will return a url with all of the query parameters intact except it will change the -action parameter to foo. $app->url('-action=foo&-table=bar'); ... you can guess what this will return. Note that this method will skip parameters beginning with '--'. Why is this helpful?Ê Because you may want your form to simply maintain the current user settings and query parameters aside from the specific query terms that your form introduces.Ê In this case, your form's action parameter may be: $app->url(''); Just a small tip that you may or may not choose to use. -Steve
Thanks for the help, the last bit confused me a little because I could not figure out becaues I couldn't relate it to my situation. However, I came up with a solution that turned out to be something we needed anyways. I added a field to the table for Media Category and added it to the form a third dropdown, so now that filters the search for me and allows more options in the future without cluttering up with several submit buttons.
Thanks again for the help!
10 posts
• Page 1 of 1
Who is onlineUsers browsing this forum: No registered users and 31 guests |