Form -> submit -> webroot anstatt Drupal
am 08.07.2011 - 06:38 Uhr in
Hallo zusammen,
ich versuche gerade ein Form zu erstellen.
Wenn ich nun die Submit Function einbaue und auf den Button clicke, wird das webroot aufgerufen.
(Drupal ist im Unterverzeichnis)
Falls es jemand kennt: es ist das Weather_info Beispiel aus Drupal 7 for windows developers
Grüße Knut
- Anmelden oder Registrieren um Kommentare zu schreiben

Wie sieht denn deine
am 08.07.2011 - 08:48 Uhr
Wie sieht denn deine derzeitige Funktion aus ?
Kannst du den Quellcode mal hier posten - das Beispiel sagt mir so jetzt nix !
SteffenR
nach dem Buch müsste er schon
am 08.07.2011 - 09:08 Uhr
nach dem Buch müsste er schon in diesem Stadium funktionieren (weitere Teile fehlen noch)
.module datei
<?php
// $Id$
function weather_info_block_info() {
$blocks['user_custom'] = array(
'info' => t('Weather block custom for each user'),
);
return $blocks;
}
function weather_info_block_view($delta='') {
$block['subject'] = t('Get Weather');
$temp = drupal_get_form('weather_location_form');
$block_content = drupal_render($temp);
$block['content'] = $block_content;return $block;
}
function weather_location_form($form_in, &$form_state) {
$form['wx_info_title'] = array (
'#value' => t('Location'),
);$form['wx_info']['weather_location'] = array (
'#type' => 'textfield',
'#size' => 20,
'#maxlengh' => 20,
);
$form['wx_info']['weather_location_submit'] = array (
'#type' => 'submit',
'#value' => t('Search'),
);
$form['#action'] = '/';
return $form;
}
include_once ('weather_info.inc');
function weather_location_form_validate($form, $form_state) {
$location = trim($form_state['values']['weather_location']);
$weather = weather_info_get_weather($location, 'en');
if (!$weather) {
form_set_error('weather_location', t('Location %location not found.',
array('%location' => $location)));
}
}
function weather_location_form_submit($form, $form_state) {
$location = trim($form_state['values']['weather_location']);
variable_set('current_location', $location);
}
.include datei
<?php
function weather_info_get_weather($location, $language) {
$requestAddress = sprintf('http://www.google.com/ig/api?weather=%s&hl=%s',
url($location), $language);
try {
$xml_str = utf8_encode(file_get_contents($requestAddress, 0));
$weather = new SimplexmlElement($xml_str);
if (isset($weather->weather->problem_cause)) {
throw new Exception (t("Can't load %loc", array('%loc' => $location)));
}
if(!$weather) {
throw new Exception ('weather failed');
}
} catch (Exception $err) {
watchdog ('weather_info', 'Cannot get weather for %location: %message',
array('%location' => $location, '%message' => $err->getMessage()),
WATCHDOG_ERROR);
return null;
}
return $weather;
}
function weather_info_temp($in_temp, $unit, $unit_system) {
return sprintf('%s°%s', $in_temp, $unit);
}
Ist am Code irgendetwas zu
am 14.07.2011 - 07:32 Uhr
Ist am Code irgendetwas zu sehen weshalb das passiert?
Grüße Knut
Du hast die form Action auf
am 14.07.2011 - 09:55 Uhr
Du hast die form Action auf den Root gesetzt - dies funktioniert so dann nicht, da dein Drupal in einem Unterverzeichnis liegt.
<?php
$form['#action'] = '/';
return $form;
?>
Du kannst dir den base_path deiner Drupal Installation über die Funktion http://api.drupal.org/api/drupal/includes--common.inc/function/base_path zurückgeben lassen. Wenn du diesen Pfad dann der Form-Action übergibst, müsste das Formular korrekt umgeleitet werden.
SteffenR
ich dachte das ist das Drupal
am 14.07.2011 - 11:05 Uhr
ich dachte das ist das Drupal Stammverzeichnis....
Danke Knut