[Gelöst] Formular erscheint nicht
am 27.11.2011 - 02:44 Uhr in
Will mit meinem Mini-Modul die Anzeige eines weiteren Formulars erreichen. Hierzu habe ich mir andere Module angesehen, die per FAPI ein Formular mitbringen. Erhalte jedoch im Frontend keinerlei Ausgabe. Fällt jemandem zu Folgendem etwas ein?
<?php
function uc_auction_instant_buy_form(&$form_state, $node, $teaser) {
$form = array(
'#node' => $node,
'#teaser' => $teaser,
'#theme' => 'uc_auction_instant_buy',
'foobar' => array(
'#title' => t('High bid'),
'#type' => 'item',
'#value' => 1,
'#weight' => 2,
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 1,
'#description' => 'foobar',
'#weight' => 8,
);
return $form;
}
function uc_auction_instant_buy_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op === 'view' && isset($node->uc_auction)) {
$node->content['uc_auction_instant_buy'] = array(
'#value' => drupal_get_form('uc_auction_instant_buy_form', $node, $a3),
'#weight' => 0,
);
}
}
/**
* Implementation of hook_theme().
*/
function uc_auction_instant_buy_theme($existing, $type, $theme, $path) {
return array(
'uc_auction_instant_buy' => array(
'arguments' => array('form' => NULL),
),
);
}
/**
* Implementation of hook_form_alter().
*/
function uc_auction_instant_buy_form_alter(&$form, $form_state, $form_id) {
if (user_access('create auctions') && $form_id == 'product_node_form') {
$instant_buy_price = array(
'instant_buy_price' => array(
// This weird #type thing is explained below.
'#type' => 'textfield',
'#title' => t('Instant buy price'),
'#description' => t('Type in the price, for which the customer should by the product directly.'),
'#field_suffix' => '€',
'#size' => 12,
'#weight' => 5,
),
);
array_push($form['base']['auction'], $instant_buy_price);
$form['#submit'][] = 'uc_auction_instant_buy_submit';
$form['#validate'][] = 'uc_auction_instant_buy_validate';
}
}
function uc_auction_instant_buy_submit(&$form, &$form_state) {
$record = array(
'nid' => $form_state['values']['nid'],
'amount' => str_replace(',', '.', $form_state['values']['instant_buy_price']),
);
drupal_write_record('uc_auction_instant_buy', $record, 'nid');
}
/**
* Validate new auction creation.
*/
function uc_auction_instant_buy_validate($form, &$form_state) {
if (!is_numeric(str_replace(',', '.', $form_state['values']['instant_buy_price']))) {
form_set_error('instant_buy_price', t('Please check the instant buy price.'));
}
}
?>- Anmelden oder Registrieren um Kommentare zu schreiben

Soll das ein Node-Formular
am 27.11.2011 - 10:54 Uhr
Soll das ein Node-Formular werden? Du verwendest nämlich hook_form, welchen man für Node-Formulare (also eigene Inhaltstypen) nimmt.
Ein Modul setzt bereits ein
am 27.11.2011 - 20:13 Uhr
Ein Modul setzt bereits ein Formular in den Inhaltstypen rein, wo ich ein weiteres Formular einsetzen möchte. Insofern ist es dann wohl ein Node-Formular. Dann mache ich mit dem erwähnten Hook doch alles richtig, oder? Wenn dem so ist: wieso erscheint mein Formular nicht?
Zitat:Dann mache ich mit dem
am 27.11.2011 - 22:25 Uhr
Dann mache ich mit dem erwähnten Hook doch alles richtig, oder?
Nein, mit hook_form erstellst du einen eigenen, neuen Inhaltstyp, damit kannst du eigentlich keine vorhandenen Node-Formulare ändern.
Außerdem versuchst du an einer anderen Stelle in deinem Code, (hook_nodeapi) das Formular mit in der Node-Ansicht auszugeben. Was willst du nun erreichen? Soll das Formular mit beim normalen Node-Formular des bestehenden Inhaltstyps auftauchen? Dann nimm hook_form_alter oder so. Oder soll das Formular unter der Node-Ansicht verwendet werden? Dann verwende ganz normal die Form-API, aber nicht hook_form.
Edit: Nochmal zum verständnis: Ein "Node-Formular" ist kein Formular, welches in einem Node auftaucht - das wäre nämlich ein stinknormales Formular - sondern das ist das Formular bzw. die Eingabemaske, mit der ein Node erstellt wird. Wenn du also einen neuen Node erzeugst oder einen bestehenden Node bearbeitest und das Formular mit Titel-Feld, Inhalt-Feld usw. siehst - DAS ist ein Node-Formular.
Danke für die Posts. Lag an
am 28.11.2011 - 12:16 Uhr
Danke für die Posts. Lag an meiner Template-File *facepalm*.