Formual in DB speichern
Eingetragen von Tiega (8)
am 19.01.2011 - 23:20 Uhr in
am 19.01.2011 - 23:20 Uhr in
Hey Leute,
Guckt euch mal bitte den Code an, ich mein ich hab den genau wie in der API beschrieben gemacht, aber der übergibt nur leere werte... bzw zeigt nur einen fehler.
function event_createform_submit($form, &$form_state) {
db_query("INSERT INTO competitions (name, description, start, end, gametype_id, fieldsize, ranking_id, challenges_allowed) VALUES ('%s', %s, '%s', '%s', '%s', '%s', '%s', '%s')", $form_state['event']['name'], $form_state['event']['description'], $form_state['event']['start'], $form_state['event']['end'], $form_state['event']['gametype'], $form_state['event']['fieldsize'], $form_state['event']['ranking'], $form_state['event']['challenges_allowed']);
drupal_set_message(t('Your form has been saved.'));
}
/**
* Die Callback-Funktion
*/
function EventCreator_seiteninhalt()
{
$output .= drupal_get_form('event_createform');
return $output;
}
function get_gametypes()
{
db_set_active('default');
$sql = "SELECT * FROM gametypes";
$result = db_query($sql);
$gametype_option_id = array();
while ($row = db_fetch_array($result))
{
$gametype_option_id[$row["id"]] = $row["id"];
}
return $gametype_option_id;
}
function get_ranking()
{
db_set_active('default');
$sql = "SELECT * FROM rankings";
$result = db_query($sql);
while ($row = db_fetch_array($result))
{
$ranking_option_id[$row["id"]] = $row["id"];
}
return $ranking_option_id;
}
function event_createform(){
$form['event']['name'] = array(
'#title' => t('Event name'),
'#type' => 'textfield',
'#description' => t('Please enter the event name'),
);
$form['event']['description'] = array(
'#title' => t('Description'),
'#type' => 'textfield',
'#description' => t('Please enter a description'),
);
$form['event']['gametype'] = array(
'#title' => t('Gametype_id'),
'#type' => 'select',
'#options' => get_gametypes(),
'#description' => t('Please choose the gametype_id'),
);
$form['event']['ranking'] = array(
'#title' => t('Ranking_id'),
'#type' => 'select',
'#options' => get_ranking(),
'#description' => t('Please choose the ranking_id'),
);
$form['event']['fieldsize'] = array(
'#title' => t('Fieldsize'),
'#type' => 'textfield',
'#description' => t('Please enter a fieldsize'),
);
$form['event']['challenges_allowed'] = array(
'#title' => t('Challenges_Allwoed'),
'#type' => 'select',
'#options' => array(
'1' => t('1'),
'0' => t('0'),
),
);
$form['event']['start'] = array(
'#title' => t('Start'),
'#type' => 'date',
);
$form['event']['end'] = array(
'#title' => t('End'),
'#type' => 'date',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
Viele Grüße und Danke
- Anmelden oder Registrieren um Kommentare zu schreiben
Hallo, deine Submit Funktion
am 20.01.2011 - 10:31 Uhr
Hallo,
deine Submit Funktion übernimmt nicht existente Daten. Schau dir mal mit var_dump($form_state) bzw wenn du das DEVEL Modul installiert hast mit dsm($form_state) den Inhalt an. Du wirst sehen dass die Werte in dem Objekt in etwa unter $form_state['values']['event']... stehen.