I have created a form.. done this many times, but today's form takes advantage of the theme('table',...) concept, allowing me to do something I've done for quite some time in standard php.
Goal: Display multiple rows in a table like form
I've dummy downed the form here...
function programs_overview() {
$form['header'] = array(
'#type' => 'value',
'#DANGEROUS_SKIP_CHECK'=>true, // To prevent drop downs from generating false errors..
'#value' => array(
array('data' => 'Action'),
array('data' => t('Title'), 'sort' => 'asc', 'field' => 'title'),
array('data' => t('Schedule'), 'field' => 'programs_stype'),
)
);
$r = db_query("SELECT node.nid AS .... [REMOVED FROM SNIPPET]
// Define a populate my drop down array
$soptions = array();
$soptions = listschedule(); // simple function returns an array of drop down items
$i = 0; // index to establish UNIQUE name for fields...
foreach ($rows as $v) { // loop through data and generate the form rows...
$nids = "<a href='/node/".$v->nid."/edit'>Edit</a>";
$form['nids'][$v->nid] = array('#type' => 'markup', '#value' => $nids);
$form['title'][$v->nid] = array('#type' => 'markup', '#value' => $v->title);
$sindx = 'soption'.$i;
$form['programs_stype'][$v->nid] = array('#type' => 'select', '#name' => $sindx, '#default_value' => array_search($v->programs_stype,$soptions), '#options' => $soptions, '#multiple' => FALSE, '#id' => $sindx, );
$i++; // Increment
}
// Old fashion counter
$form['num_rec'] = array('#type' => 'hidden', '#name' => 'num_rec', '#value' =>$i);
$form['submit'] = array('#type' => 'submit', '#value' => 'Update');
return $form;
}
function theme_programs_overview($form) {
//Prepare Page Header
$output = "<p>Below you will find.... [REMOVED FOR CODE SNIPPET]</p>";
// Loop through to create individual rows..
foreach (element_children($form['title']) as $key) {
$row = array();
$row[] = drupal_render($form['nids'][$key]);
$row[] = drupal_render($form['title'][$key]);
$row[] = drupal_render($form['programs_stype'][$key]);
$rows[] = $row;
}
$output .= theme('table', $form['header']['#value'], $rows);
$output .= drupal_render($form['num_rec']);
$output .= drupal_render($form); // Process any other fields and display them
$output .= "<p><i>If there is no data above this line - Synchronize Programs</i></p>";
return $output;
}
The form generates without error. And the submit works well. However, I anticipated being able to view my form submission select data in my programs_overview_submit() function by referencing entries as follows...
while($i<$form_state['values']['num_rec']) {
// get the select value results ... I plan on running an update query here, but those details are unimportant.. So I will simple assign the value
$wheresmyselect = $form_state['values']['soption'.$i]
$i++;
} // End OF WHILE
So, here's the weird part, when I do a data dump on $form_state['values'] the select boxes are NO WHERE to be found. The correct data is found
$form_state['clicked_button']['#post']['soption'.$i]... but something tells me I shouldn't use this...
So, pretty long winded after all.. but I'm hoping to find an answer to
Where is my $form_state['values'] data...
any insight would be greatly appreciated...
Comments
First it is a good idea to
First it is a good idea to test the form first without the theme function, it removes a possible source of errors.
As an aside to the casual observer you could do this using views 2 and a table view.
Here is one approach that takes advantage of the form api.
Lets replace the foreach loop in programs_overview() putting the data in a tree structure and removing the need to track the number of records.
Now in theme_programs_overview($form) we rewrite the loop to use the new data structure.
And in your submit handler you can do something like
views2 and table!!
Nevets...
Well golly! (smile)
That's what I originally wanted to do. I had created this using views, as a strict table display. But couldn't find documentation that described how to do this with drop downs as a form...
so.. if you PLEASE...
1. Thank you for the information - I'm off to go try your suggestions.
2. Can you point me to the right place to read about the view2 and table view, that allows updated forms...
Here is a link to a view I've made..
http://sports.admininternet.net/plist_sched
If I wanted to make the round column a drop down that would update.. can i do that with a view?
Oh and did I say...
thank you thank you thank you??
- Scott
Scott Baetz
Web Developer
sbaetz@admininternet.net
AdminInternet
http://www.admininternet.net
Looking at the page I am not
Looking at the page I am not sure what "round column" is but here is something that might help with views.
It sounds like you know how to make a table view, in this case under fields you want the fields that represent Schedule, Schedule Type, Round and Game Date. For the edit link look under fields for 'Node: Edit link'.
You can then add filters on these and/or other fields. To make them something the user can select you use the "Expose" button on the filter.
back to the views concept..
Nevets..
Yes, I can make the table view. My problem was making an element of the table view an editable field. I did find the Node:Edit Link field, that would take someone to an individual page to edit an individual node. I'm more interested in the TABLE of ROWS concept (where rows represent many nodes of data) And providing the end-user the ability to update several nodes at once.
I couldn't figure out how to make a field an interactive field.
Sounds like the key is FILTERS? I thought that would only operate on presenting the data, not updating...
I realize there is a great learning curve, and that forums are probably not the best place to learn. Further, the fact that you've helped me TREMENDOUSLY already means I don't want to bug you more...
Can you point me to a good primer on using views to create editable interfaces? I promise, I'm a good reader...
Thanks!!!
Scott Baetz
Web Developer
sbaetz@admininternet.net
AdminInternet
http://www.admininternet.net
with minor mod.. that worked
Nevets..
Thanks again.. I applied your suggestions above... I did have to make the following modification... (don't know if this is good code or not)..
In theme_programs_ovierview() I found that with the foreach you had suggested above, I was looping through the parameters of the form, and generating a warning message. If I converted to the below, it appears not to loop through the parameters, only the data.
Otherwise... this works!
- Scott
PS. Thanks..
Scott Baetz
Web Developer
sbaetz@admininternet.net
AdminInternet
http://www.admininternet.net