Content filter does not search drupal7 - drupal

I have added a drop down of my courses title at the filter second of the drupal - admin - content area.
http://www.XYZ.com/demo/admin/content
But when I select any of the title and hit Filter nothing gets appear. The data which showed previously it shows again, nothing happens really.
My code for the add filter drop down:
function products_form_node_admin_content_alter(&$form, &$form_state){
$results = db_query("SELECT r.nid, r.title FROM {node} AS n
LEFT JOIN {node_revision} AS r ON r.nid = n.nid
WHERE type = 'product'")->fetchAll();
$optionsF = Array ( '[any]' => 'any' );
foreach($results as $key => $result) {
$options[$result->title] = $result->title;
}
$options = $optionsF + $options;
$course_titles['title'] = Array
(
'#type' => 'select',
'#options' => $options,
'#title' => 'title',
'#default_value' => 'any'
);
$form['filter']['filters']['status']['filters'] = $form['filter']['filters']['status']['filters'] + $course_titles;
$uid_column = array('uniqueid' => array(
'data' => 'UniqueID',
'field' => 'n.nid'
));
$form['admin']['nodes']['#header'] = $form['admin']['nodes']['#header']+$uid_column;
foreach ($form['admin']['nodes']['#options'] as $key => $row) {
$node = node_load(array('nid' => check_plain($key)));
$form['admin']['nodes']['#options'][$key]['uniqueid'] = $node->field_unique_code_course['und'][0]['value'];
}
}
Does any body have any idea what is lacking in my code or method?
Cheers!!!

I would recommend using Admin Views, it's built for this purpose.
https://drupal.org/project/admin_views

Related

Drupal 7 Hook_forms not working

Can anyone tell me why this is not working?
The drupal_render(drupal_get_form) is dynamically created in a foreach loop and put into a table theme.
Everything loads except the form fields. I've tried debugging by adding echos and exits to each form function call, but the page continues to load. I am not sure if these functions are simply not being called or if there is some other issue.
foreach( $w as $k => $v ) {
$r[] = array(
'$'.number_format($v->amount, 2),
date('F d, Y', $v->created),
filter_xss($v->paypal_email),
drupal_render(drupal_get_form(('toefl_tutors_admin_withdrawl_request_form_'.$v->id), $v->id))
);
}
function toefl_tutors_admin_withdrawl_request_forms($form_id, $args) {
$forms = array();
if (!empty($args) && $form_id == 'toefl_tutors_admin_withdrawl_request_form_' . $args[0]) {
$forms[$form_id] = array(
'callback' => 'toefl_tutors_admin_withdrawl_request_form',
'callback arguments' => array($args[0]),
);
}
return $forms;
}
function toefl_tutors_admin_withdrawl_request_form($form, &$form_state, $id = 0) {
$form['twid'] = array(
'#type' => 'hidden',
'#value' => $id
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Send Money'),
'#attributes' => array('class' => array('btn', 'btn-success'))
);
return $form;
}
I've solved the problem.
I needed to rename the hook_forms function to toefl_tutors_forms() because My module name is actually toefl_tutors not toefl_tutors_admin_withdrawl_request
Apparently and correct me if I am wrong, in order to use hook_forms you must name it mymodulename_forms, not mymodulename_xx_forms.
What confused me was hook_form works perfectly when you name the form function mymodulename_xx_form().

Get selected value of a dropdown list

I try to get the selected value of my select in Drupal (7), but the value of the select is always empty in my hook_submit() :| !
Below my code :
<?php
function gestionvideos_players_form() {
//I get my list of players from my database
$aPlayers = EasyVod_db::get_players();
$options = array();
if( empty($aPlayers) ) {
$options[] = "no available player";
}else{
foreach( $aPlayers as $player ){
$options[$player->iPlayer] = ucfirst($player->sName);
}
}
$form['gestionvideos_player'] = array(
'#type' => 'fieldset',
'#title' => t('Integration par defaut des videos'),
'#description' => t('Selection du player par defaut : '),
);
$form['gestionvideos_player']['selectplayer'] = array(
'#type' => 'select',
'#options' => $options,
);
$form['gestionvideos_player']['submit'] = array(
'#type' => 'submit',
'#value' => t('Choisir ce player'),
);
return $form;
}
function gestionvideos_players_form_submit($form, &$form_state){
drupal_set_message("test ".$form_state['values']['selectplayer']);
//I set my player in my session variable
$oPlayer = EasyVod_db::get_player( intval($form_state['values']['selectplayer']) );
$_SESSION['player'] = $oPlayer ->player;
}
?>
I would really appreciate some help because I really don't understand what it doesn't work...
Have you tried putting
$form['#tree'] = true;
inside your form builder function then try dumping:
$form_state['values']['gestionvideos_player']['selectplayer']

Drupal 6 : Not populating select list from db_query()

I have made a custom form in a module where I have used a select list & I am trying to populate that with the name of OG name.
I wrote a function for db_query() & that is giving me exact out put but I am not able to populate that in from select.
Function for db_query():-
function taskform_project_select(){
$options=array();
$project_query = "SELECT node.title FROM {node}, {og} WHERE node.nid = og.nid";
$project_details = db_query($project_query);
while($project_title = db_fetch_object($project_details)){
$options = $project_title->title;
dpm($options);
}
return $options;
}
Code in Form:-
$options = taskform_project_select();
$form['edproject'] = array(
'#type' => 'select',
'#title' => t('Project'),
'#options' => $options,
'#description' => t('Choose a project'),
'#prefix' => '<td>',
'#suffix' => '</td>',
);
Thanks :)
Correct syntax is:
$options[] = $project_title->title;
..with square brackets.
$options[$project_title->title] = $project_title->title;
provides a meaningful key value to the result. You could also retrieve the nid and use that as the key.

Drupal 6: Checkboxes table not rendering properly

I'm working on a Drupal 6 module which I want to generate a table with checkboxes in each row from data I have saved in a database. The table is being generated fine, but the checkboxes are not rendering in the table but are instead having their node id's put below the table. See the screenshot below:
"21" is the node id of "Test Question 01", and "19" is the node id of "Test Question 02".
The code I'm using (yes, it is all in a theme function which isn't ideal. I'm planning on moving stuff around once the checkboxes problem is resolved):
function theme_qt_assignment_questions_table($form) {
// Get the questions from the database
$db_results = db_query('SELECT {qt_questions}.nid, title, lesson, unit FROM node INNER JOIN {qt_questions} on {node}.nid = {qt_questions}.nid WHERE lesson = %d AND unit = %d',
$form['#lesson'], $form['#unit']);
// Define the headers for the table
$headers = array(
theme('table_select_header_cell'),
array('data' => t('Title'), 'field' => 'title'/*, 'sort' => 'asc'*/),
array('data' => t('Lesson'), 'field' => 'lesson'),
array('data' => t('Unit'), 'field' => 'unit'),
);
while($row = db_fetch_object($db_results)) {
$checkboxes[$row->nid] = '';
$form['nid'][$row->nid] = array(
'#value' => $row->nid
);
$form['title'][$row->nid] = array(
'#value' => $row->title
);
$form['lesson'][$row->nid] = array(
'#value' => $row->lesson
);
$form['unit'][$row->nid] = array(
'#value' => $row->unit
);
}
$form['checkboxes'] = array(
'#type' => 'checkboxes',
'#options' => $checkboxes,
);
// Add the questions to the table
if(!empty($form['checkboxes']['#options'])) {
foreach(element_children($form['nid']) as $nid) {
$questions[] = array(
drupal_render($form['checkboxes'][$nid]),
drupal_render($form['title'][$nid]),
drupal_render($form['lesson'][$nid]),
drupal_render($form['unit'][$nid]),
);
}
} else {
// If no query results, show as such in the table
$questions[] = array(array('data' => '<div class="error">No questions available for selected lesson and unit.</div>', 'colspan' => 4));
}
// Render the table and return the result
$output = theme('table', $headers, $questions);
$output .= drupal_render($form);
return $output;
}
Turns out my attempt at simplification of the problem was, in fact, the problem. Namely, doing everything in hook_theme isn't correct. Rather, I defined a function that pulls the info from database and creates the checkboxes array and call it in hook_form as such:
$form['questions_wrapper']['questions'] = _qt_get_questions_table($node->lesson, $node->unit);
At the end of this function (_qt_get_questions_table()), I specify the theme function which put everything into the table as such:
$form['#theme'] = 'qt_assignment_questions_table';
I'm still very new to Drupal so this explanation may not be the best to someone having the same problem, but hopefully it will help.

cannot get checkboxes value using drupal form api

i have form in drupal which uploads images and has got few checkboxes in it.
Here is the form:
$form['checklist_fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Check List'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['checklist_fieldset']['heating'] = array(
'#type' => 'checkboxes',
'#title' => t('Heating options'),
'#options' => array(
'0' => t('Yes'),
'1' => t('No')
),
'#description' => t('Heating details.')
);
and here is my submit function where i am processing image upload and grabbing the checkboxes value as well. I am getting the success message and image is getting uploaded but not getting the value of check boxes.
function property_add_view_submit($form,&$form_state){
$validators = array();
if($file = file_save_upload('p_file1',$validators,file_direcotry_path)){
$heating = array_keys($form_state['values']['heating']);
drupal_set_message(t('Property Saved! '.$heating));
dpm( $form_state['values']['heating']);
}
When you use #options on a FAPI element the value passed to the $form_state is the array key, so you don't need to use array_keys().
I'm not sure why you're using checkboxes for a yes/no, usually one would use a simple checkbox element. However if that's really what you want to do:
Your #options can't contain on option with 0 as the array key, it will be automatically filtered out and you'll never know if that option has been checked.
You should use $heating_options_chosen = array_filter($form_state['values']['heating'] to get the selected checkbox options.
I honestly think your code should look like this though:
$form['checklist_fieldset']['heating'] = array(
'#type' => 'checkbox',
'#title' => t('Heating options'),
'#options' => array(
'1' => t('Yes'),
'0' => t('No')
),
'#description' => t('Heating details.')
);
$heating_checked = $form_state['values']['heating'] == 1;
If I have checkbox Friends and options are like
[ ] abc
[ ] def
[ ] ghi
[ ] jkl
And I want to know which options user have marked, then use below function.
if ($form_state->getValue('friends') != NULL) {
foreach ($form_state->getValue('friends') as $key => $value) {
if ($value != 0) {
$friends = $friends . ", " . $key;
$friends = substr_replace($friends, "", 0, 1);
}
}
}
If user has chosen abc and ghi then you will get 1,3 as result in $friends
If you wanted to know the value then use $friends = $friends.", ".$value;
it worked for me..hope it will help you as well :)

Resources