File upload with text in Mysql
Hey there.
Im quite into forms right now and have watched the file upload videos.
But I was wondering, how would you handle some file upload with text, let say I have to
make a profile and have both text forms and file uploads.
I have made a table in mysql and are inserting the text forms, but what about the picture upload, should this be in a separate table or in the same table as in the text forms???
If you are putting it in a separate table, the two tables should connect somehow?
I have do display both text and picture in a view page.
I have done some coding and just followed your file upload with the managed files in the form, but how would you display it with text at the same time???
Im a little lost here
<?php
function formcallback_menu() {
$items['formcallback/form'] = array(
'title' => 'Form callback',
'description' => t('form upload with page callback'),
'page callback' => 'drupal_get_form',
'page arguments' => array('formcallback_form'),
'access callback' => TRUE,
);
$items['formcallback/view'] = array(
'title' => 'View page',
'description' => 'view your form submit page',
'access arguments' => array('access content'),
'page callback' => 'formcallback_form_view'
);
return $items;
}
function formcallback_form($form, &$form_state){
$form['name'] = array(
'#type' => 'textfield',
'#title' => 'name',
'#description' => t('place your name'),
'#prefix' => '
',
'#suffix' => '
',
);
$form['alder'] = array(
'#type' => 'textfield',
'#title' => 'alder',
'#description' => t('skriv din alder'),
);
$form['fag'] = array(
'#type' => 'textfield',
'#title' => 'Fagområde',
'#description' => t('Skriv dit fagområde'),
);
$form['wishjob'] = array(
'#type' => 'textfield',
'#title' => 'Ønskejob',
'#description' => t('Hvilken branche ønsker du at arbejde i'),
);
$form['text'] = array(
'#type' => 'textfield',
'#title' => 'Skriv dine erfaringer',
'#description' => t('Skriv en tekst om dine erfaringer og ønsker'),
);
$form['managed_file'] = array(
'#title' => t('managed file'),
'#type' => 'managed_file',
'#upload_validators' => array('file_validate_extensions' => array('jpeg jpg png gif pdf'), 'assets_validate_not_filename' => array('test.')),
'#upload_location' => 'public://assets/managed',
'#progress_indicator' => 'bar',
'#progress_message' => 'vent, filen loades...',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Send',
);
return $form;
}
function formcallback_form_submit($form, &$form_state) {
$link_profil = l('Din side','formcallback/view');
$entry = array(
'name' => $form_state['values']['name'],
'alder' => $form_state['values']['alder'],
'fag' => $form_state['values']['fag'],
'wishjob' => $form_state['values']['wishjob'],
'text' => $form_state['values']['text'],
);
$sql = "insert into {bruger_form} (name, alder, fag, wishjob, text) values ('$_POST[name]','$_POST[alder]','$_POST[fag]','$_POST[wishjob]','$_POST[text]')";
$db_result = db_query($sql, $entry);
if ($db_result) {
drupal_set_message(
"name ".$form_state['values']['name'].
"er blevet added, gå til profil siden"
);
} else {
drupal_set_message(
"An unexpected error has occurred.".
$form_state['values']['name']." has not been created");
}
}
function formcallback_form_view() {
// Begin building the query.
$query = db_select('bruger_form', 'th')
->orderBy('id', 'DESC')
->fields('th');
// Fetch the result set.
$result = $query->execute();
foreach ($result as $row) {
$rows[] = array(
'
' . $row->name, $row->alder, $row->fag, $row->wishjob, $row->text
);
}
// Headers for theme_table().
$header = array('name');
// Format output.
$output = theme('table', array('header' => $header, 'rows' => $rows));
}
return $output;
}