[gelöst]Dynamische Form
Eingetragen von dontgotanick (156)
am 23.07.2010 - 12:41 Uhr in
am 23.07.2010 - 12:41 Uhr in
Hi,
ich versuche ein Auswahl menu zu erstellen.
Bei dem ich erst das Jahr auswähle und dann einen Titel einer Node aus diesem Bereich.
Leider funktioniert das nicht so ganz habe mich daran versucht bin aber geshceitert......
Kann mir jemand sagen was ich falshc mache?
Hier mal der Code
<?php
<?php
// $Id$
/**
* Valid permissions for this module
* @return array An array of valid permissions for the signup_export module
*/
function cwg_signup_export_perm() {
return array('access signup_export');
} // function cwg_registration_perm()
function cwg_signup_export_menu() {
$items = array();
$items['admin/settings/cwg_signup_export'] = array(
'title' => 'CWG-Export-Signups',
'description' => 'Exports Signups for certain events.',
'page callback' => 'drupal_get_form',
'page arguments' => array('cwg_signup_export_admin'),
'access callback' => 'user_access',
'access arguments' => array('access signup_export'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Define the settings form.
*/
function cwg_signup_export_admin($param1, $form_values = NULL) {
if (!isset($form_values)) {
$step = 1;
}
else {
$step = $form_values['step'] + 1;
}
$form['step'] = array(
'#type' => 'hidden',
'#value' => $step,
);
switch ($step) {
case 1:
$form['event_signup_list']['year'] = array(
'#type' => 'select',
'#title' => t('Select the year of the event.'),
'#options' => get_years(),
);
break;
case 2:
$form['event_signup_list']['year'] = array(
'#type' => 'select',
'#title' => t('Select the year of the event.'),
'#options' => options($form_values['year']),
);
break;
}
// This part is important!
$form['#multistep'] = TRUE;
$form['#redirect'] = FALSE;
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'save',
);
return $form;
}
function options($value){
$sql = "SELECT title,changed FROM {node} WHERE nid <>'0' and type='event'";
$options = array();
$count = 0;
$result = db_query($sql);
while($row = db_fetch_object($result)){
$year = date(Y, $row->changed);
if($value = $year)
$options[$count++] = $row->title;
}
return $options;
}
function get_years(){
$years = array();
$count = 0;
$insert = true;
$sql = "SELECT changed FROM {node} WHERE nid<>0 AND type='event'";
$result = db_query($sql);
while($row = db_result($result)){
$year = date(Y,$row);
foreach ($years as &$value) {
if($value == $year)
$insert = false;
else
$insert = true;
}
if($insert)
$years[$count++] = $year;
}
return $years;
}
function cwg_signup_export_admin_submit($form, &$form_state){
$final_step = 3;
if ($form_values['step'] == $final_step) {
// Process the form here!
get_years();
}
/** $nid;
if($_POST['Filter'] === 'all'){
$t=options();
$sql = "SELECT nid FROM {node} WHERE title LIKE '%s'";
$nid = db_result(db_query($sql, $t[$_POST['All']]));
}
else{
$sql = "SELECT nid FROM {signup} WHERE nid !='0' and status='1'";
$nid = db_result(db_query($sql));
}
$sql = "SELECT form_data,uid FROM {signup_log} WHERE nid = '%d'";
$db_result = db_query($sql, $nid);
$out = "Username;Name;Surname;Company;Email;";
$n = "\n";
$first = true;
while($row = db_fetch_object($db_result)){
$uid = $row->uid;
$sql = "SELECT value FROM {profile_values} where uid='%d' and fid='1'";
$surname = db_result(db_query($sql,$uid));
$sql = "SELECT value FROM {profile_values} where uid='%d' and fid='2'";
$name = db_result(db_query($sql,$uid));
$sql = "SELECT value FROM {profile_values} where uid='%d' and fid='11'";
$company = db_result(db_query($sql,$uid));
$sql = "SELECT name FROM {users} where uid='%d'";
$username = db_result(db_query($sql,$uid));
$sql = "SELECT mail FROM {users} where uid='%d'";
$mail = db_result(db_query($sql,$uid));
$form_data = unserialize($row->form_data);
foreach ($form_data as $key => $value) {
if ($first) {
$out .= $key . ";";
}
if (is_array($value)) {
$isFirst = true;
foreach ($value as $arrayKey => $arrayValue) {
if ($arrayValue !== 0) {
if($isFirst) {
$isFirst = false;
$arrayValues .= check_plain($arrayKey);
}
else {
$arrayValues .= ", " . check_plain($arrayKey);
}
}
}
$rowValue .= check_plain($arrayValues) . ";";
$arrayValues = "";
} else {
$rowValue .= check_plain($value) . ";";
}
}
if ($first) {
$out .= "\n";
$first = false;
}
$out .= $username . ";" . $name . ";" . $surname . ";" . $company . ";" . $mail . ";" . $rowValue . $n;
$rowValue = "";
}
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Length: " . strlen($out));
header("Content-type: text/x-csv");
header("Content-Disposition: attachment; filename=export.csv");
echo $out;
**/
}
?>
danke
lg dave
- Anmelden oder Registrieren um Kommentare zu schreiben
Schau Dir mal das folgende
am 23.07.2010 - 12:51 Uhr
Schau Dir mal das folgende Tutorial an um Multistep Formulare zu bauen: http://www.andrewyager.com/content/view/51/27/
sense-design | online solutions | Do not hack core!
Drupalcenter Verhaltensregeln | Threads bitte auf [gelöst] stellen.
super
am 23.07.2010 - 14:35 Uhr
danke hat geklappt