File upload with text in Mysql

No replies
sodborg
Offline
Last seen: 4 years 1 week ago
Joined: 2011-04-25

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;
}

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.