ist es möglich bei der ADDON Erstellung Pflichtfelder zu definieren?
Folgender Hintergrund:
Ich bastel mir einen Eventkalender. Als Grundlage habe ich das Beispiel-Addon "Adressen" verwendet.
Es soll ein Start- und ein Enddatum angegeben werden.
Die Eingabe des Startdatums soll Pflicht sein.
Das Enddatum soll optional sein, es soll sich jedoch das Startdatum eintragen, wenn das Feld leer ist.
Wie gehe ich an die Sache heran?
Ich habe mir schon mal 'rex_form::validate()' angeschaut, finde aber keinen Weg, die Klasse zu nutzen.
Hier mein Skript
Code: Alles auswählen
<?php
$id = rex_request('id', 'int');
// Eintragsliste
if ($func == '') {
$list = new rex_list('SELECT id, start_date, start_time, event_name,event_desc,event_location, status FROM '.$REX['TABLE_PREFIX'].'900_events', 200);
$imgHeader = '<a href="'. $list->getUrl(array('func' => 'add')) .'"><img src="media/metainfo_plus.gif" alt="add" title="add" /></a>';
// Sortierbare Spaltenkoepfe
$list->setColumnSortable('start_date');
$list->setColumnSortable('event_name');
$list->addColumn(
$imgHeader,
'<img src="media/metainfo.gif" alt="field" title="field" />',
0,
array(
'<th class="rex-icon">###VALUE###</th>',
'<td class="rex-icon">###VALUE###</td>'
)
);
$list->setColumnParams (
$imgHeader,
array('func' => 'edit', 'id' => '###id###')
);
// Beschriftungen für Spaltenköpfe
$list->setColumnLabel('start_date', 'Startdatum');
$list->setColumnLabel('start_time', 'Uhrzeit');
$list->setColumnLabel('event_name', 'Name');
$list->setColumnLabel('event_pic', 'Bild');
$list->setColumnLabel('event_desc', 'Beschreibung');
$list->setColumnLabel('event_location', 'Location');
$list->setColumnLabel('status', 'On/Offline');
$list->setColumnLayout (
'id',
array(
'<th class="rex-icon">###VALUE###</th>',
'<td class="rex-icon">###VALUE###</td>'
)
);
$list->setColumnParams('name', array('func' => 'edit', 'id' => '###id###'));
$list->show();
}
// Formular
elseif ($func == 'edit' || $func == 'add') {
$form = new rex_form($REX['TABLE_PREFIX'].'900_events',"Events","id=".$id,"post",false);
// Formularfelder anlegen
$field = &$form->addTextField('start_date');
$field->setAttribute('class','date-pick');
$field->setAttribute('id','start-date');
$field->setLabel("Startdatum");
$field = &$form->addTextField('start_time');
$field->setLabel("Uhrzeit");
$field->setAttribute('size','5');
$field = &$form->addTextField('end_date');
$field->setAttribute('class','date-pick');
$field->setAttribute('id','end-date');
$field->setLabel("Enddatum");
$field = &$form->addTextField('event_name');
$field->setLabel("Name der Veranstaltung");
$field = &$form->addMediaField('event_pic');
$field->setLabel("Grafik/Bild zur Veranstaltung");
$field = &$form->addTextAreaField('event_desc');
$field->setLabel("Beschreibung");
$field = &$form->addSelectField('status');
$field->setLabel("Status");
$select = &$field->getSelect();
$select->setSize(1);
$select->addOption('Online',1);
$select->addOption('Offline',0);
$select->setAttribute('style','width: 100px');
// Standardwert: 1
if ($field->getValue()== "") {
$field->setValue(1);
}
// Selectfeld für Veranstaltungsorte
// Werte werden aus der Locations-Tabelle geholt
$field = &$form->addSelectField('event_location');
$field->setLabel("Location");
$select =& $field->getSelect();
$select->setSize(1);
$query = 'SELECT name as label, id FROM '.$REX['TABLE_PREFIX'].'900_locations';
$select->addSqlOptions($query);
if($func == 'edit') {
$form->addParam('id', $id);
}
$form->show();
}
?>