i am creating a custom module **
form_example.module
**
<?php
function form_example_permission() {
return array(
'submit form_example' => array(
'title' => t('Submit form_example'),
'description' => t('Submit the form_example form'),
),
'access form_example submissions' => array(
'title' => t('Access form_example submissions'),
'description' => t('Access the form_example submissions'),
),
);
}
function form_example_menu() {
$items = array();
$items['form-example'] = array( //this creates a URL that will call this form at "examples/form-example"
'title' => 'Employess Entry Form', //page title
'description' => "A form to submit the employee's data.",
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('submit form_example'),
'page callback' => 'drupal_get_form', //this is the function that will be called when the page is accessed. for a form, use drupal_get_form
'page arguments' => array('form_example_form'),
);
$items['form-submissions'] = array(
'title' => t('List'),
'page callback' => 'form_example_submissions',
'access callback' => TRUE,
'access arguments' => array('access form_example submissions'),
'type' => MENU_CALLBACK,
);
return $items;
}
function form_example_form($form, &$form_state) {
$form['empcode'] = array(
'#weight' => '0',
'#required' => '1',
'#type' => 'textfield',
'#title' => t('Employee Code'),
);
$form['empname'] = array(
'#weight' => '1',
'#required' => '1',
'#type' => 'textfield',
'#title' => t('Employee Name'),
);
$form['empemail'] = array(
'#weight' => '2',
'#required' => '1',
'#type' => 'textfield',
'#title' => t('Employee Email'),
);
$form['empdesignation'] = array(
'#weight' => '3',
'#required' => '1',
'#type' => 'textfield',
'#title' => t('Employee Designation'),
);
$form['file'] = array(
'#weight' => '4',
'#type' => 'file',
'#size' => '30',
'#title' => t('Employee Photo'),
);
$form['submit'] = array(
'#weight' => '5',
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function form_example_form_validate($form, &$form_state) {
/*if (!($form_state['values']['price'] > 0)){
form_set_error('price', t('Price must be a positive number.'));
}*/
// print('<pre>'.print_r($form_state['values'],1).'</pre>');
//die();
$file = file_save_upload('file', array(
'file_validate_is_image' => array(),
'file_validate_extensions' => array('png gif jpg jpeg'),
));
if ($file) {
if ($file = file_move($file, 'public://')) {
$form_state['values']['file'] = $file;
}
else {
form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
}
}
else {
form_set_error('file', t('No file was uploaded.'));
}
}
function form_example_form_submit($form, &$form_state) {
$file=$form_state['values']['file'];
unset($form_state['values']['file']);
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
// drupal_set_message(t('The form has been submitted and the image has been saved, filename: @filename.', array('@filename' => $file->filename)));
$fe_id = db_insert('form_example')
->fields(array(
'empcode' => $form_state['values']['empcode'],
'empname' => $form_state['values']['empname'],
'empemail' => $form_state['values']['empemail'],
'empdesignation' => $form_state['values']['empdesignation'],
'empphoto' => $file->filename,
))
->execute();
drupal_set_message(t('Successfully added'));
}
function form_example_theme($existing, $type, $theme, $path) {
return array(
'form_example_function' => array(
'variables' => array('rows' => NULL),
),
'form_example_template' => array(
'variables' => array('rows' => NULL),
'template' => 'form_example_template',
),
);
}
/* view the form submissions*/
function form_example_submissions()
{
$results = db_query("Select * from {form_example}");
$rows = array();
foreach($results as $result)
{
$rows[] = array(
$result->fe_id,
$result->empcode,
$result->empname,
$result->empphoto,
$result->empemail,
$result->empdesignation,
);
}
return theme('form_example_function',array('rows' => $rows));
}
/*function theme_form_example_function($variables)
{
print_r($variables);
//$output ="<h2>".print_r$variables."</pre></h2>";
/* foreach ($variables as $result)
{
$output = "<h2><pre>".print_r($result)."</pre></h2>";
}
return $output;
$output = '';
foreach($variables['rows'] as $row) {
foreach($row as $values) {
print_r($values);
$output .= "Empcode: " . $values . "</br> ";
// $output .= "EmpName: " . $values[1] . " </br>";
//$output .= "Emphot: " . $values[2] . "\n";
}
}
return $output;
}*/
function theme_form_example_function($variables)
{
$output = '';
print_r($variables);
foreach($variables['rows'] as $row) {
// echo $path;
// $output .= "Empcode: " . (isset($row[1]) ? $row[1] : "--") . " ";
// $output .= "EmpName: " . (isset($row[2]) ? $row[2] : "--") . " ";
// $output .= "Emphot: " . (isset($row[3]) ? $row[3] : "--") . "<br>";
$img_url = 'public://'.(isset($row[3]) ? $row[3] : "--"); // the orig image uri
$style = 'medium'; // or any other custom image style you've created via /admin/config/media/image-styles
$output .= '<div class="views-row"><div class="do_featured">
<div style="position: relative;" class="do_image">
<div class="field field-name-field-thumb-image field-type-image field-label-hidden"><div class="field-items"><div class="field-item "><img src="'.image_style_url($style, $img_url).'" ></div></div></div></div>
<div class="do_title">
<span> <div class="field"><div class="field-items"><b>'.(isset($row[2]) ? $row[2] : "--") .'</b></div></div>
<div class="field"><div class="field-items">Emp Code: </div><div class="field-items">'.(isset($row[1]) ? $row[1] : "--") .'</div></div>
<div class="field"><div class="field-items">'.(isset($row[4]) ? $row[4] : "--") .'</div></div>
<div class="field"><div class="field-items">'.(isset($row[5]) ? $row[5] : "--") .'</div></div>
</span>
</div></div></div>';
}
return $output;
}
?>
I want to show only filters on form-submissions like below:
After filter the data screen will shown like below
i want to know how can i add these filter on page and search the result on database and shown on page