For Drupal 7:
function youth_fest_form($form, &$form_state) {
$form['can_id'] = array(
'#type'=>'hidden',
'#value' => isset($value['can_id']) ? $value['can_id'] : '' ,
);
$form['firstname'] = array(
'#type' => 'textfield',
'#title' => 'Full Name',
'#size' => 30,
'#maxlength' => 50,
'#weight'=>1,
//'#default_value'=>t('First Name'),
'#required' => TRUE,
'#attributes' => array(
'placeholder' => t('First Name'),
),
'#prefix' => '<div id="wrapper"><div id="leftcolumn">',
'#suffix' => '</div>',
);
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('SUBMIT'),
'#weight'=>13,
);
return $form;
}
function youth_fest_form_submit($form, &$form_state) {
$data = db_insert('youth')
->fields(array(
'first_name' => $form_state['values']['firstname'],
))
->execute();
if(isset($data)){
drupal_set_message('Values inserted successfully!');
}
}
submitted result in a table:
function youth_admin_content_page(){
$header = array('First Name', 'Last Name');
# set the database table
$query = db_select('youth', 'p')->extend('PagerDefault');
# get the desired fields from the database
$query->leftJoin('file_managed', 'fm', 'fm.fid = p.file');
$query->fields('fm',array('filename','uri'));
$query->fields('p', array('candidate_id', 'first_name'))
->limit(3);
# execute the query
$results = $query->execute();
# build the table fields
$rows = array();
foreach ($results as $row) {
$rows[] = array("<a href=\"/projects/edit/" . $row->candidate_id . "\">" . $row->first_name . '</a>',
$row->last_name,
'<img src="'.$optimageurl.'" width="100" height="100">',
);
}
$output = theme('table', array('header' => $header,'rows' => $rows ));
$export = 'Export';
# add the pager
$output .= theme('pager');
return $output;
}