Hallo,
Ich habe ein Formular für meine Erweiterung entwickeln begonnen. Es funktioniert schon gut aber es fehlt noch einige Sachen. Ich möchte gern TYPOlight nutzen um das Formular zu erstellen und nicht alles von Hand schreiben.
Deswegen habe ich zwei Fragen:
- Ich kann die Formularfelder erzeugen aber wie machen das mit "Label" ?
- Die Validierung von Formularfeldern ist nicht aktiv. Wie aktivieren ?
Mein Kode:
Template:Code:class subscription extends rdv_calendar
{
/**
* Template
* @var string
*/
protected $strTemplate = 'fe_subscription';
/**
* Generate module
*/
protected function compile()
{
// Champs du formulaire d'enregistrement
$arrFields = array
(
'customer_title' => array
(
'name' => 'customer_title',
'label' => &$GLOBALS['TL_LANG']['tl_rdv_light']['customer_title'],
'inputType' => 'select',
'options' => array('Mrs', 'Mr'),
'eval' => array('includeBlankOption'=>true, 'maxlength'=>64, 'mandatory'=>true)
),
'customer_firstname' => array
(
'name' => 'customer_firstname',
'label' => &$GLOBALS['TL_LANG']['tl_rdv_light']['customer_firstname'],
'inputType' => 'text',
'eval' => array('rgxp'=>'alnum', 'maxlength'=>64, 'mandatory'=>true)
),
'customer_lastname' => array
(
'name' => 'customer_lastname',
'label' => &$GLOBALS['TL_LANG']['tl_rdv_light']['customer_lastname'],
'inputType' => 'text',
'eval' => array('rgxp'=>'alnum', 'maxlength'=>64, 'mandatory'=>true)
),
'customer_phone' => array
(
'name' => 'customer_phone',
'label' => &$GLOBALS['TL_LANG']['tl_rdv_light']['customer_phone'],
'inputType' => 'text',
'eval' => array('rgxp'=>'digit', 'maxlength'=>64, 'mandatory'=>true)
),
'customer_mail' => array
(
'name' => 'customer_mail',
'label' => &$GLOBALS['TL_LANG']['tl_rdv_light']['customer_mail'],
'inputType' => 'text',
'eval' => array('rgxp'=>'email', 'mandatory'=>true, 'maxlength'=>128, 'decodeEntities'=>true)
),
'customer_description' => array
(
'name' => 'customer_description',
'label' => &$GLOBALS['TL_LANG']['tl_rdv_light']['customer_description'],
'inputType' => 'textarea',
'eval' => array('rgxp'=>'alnum', 'rows'=>4, 'cols'=>40, 'allowHtml'=>true)
)
);
$arrWidgets = array();
// Initialize widgets
foreach ($arrFields as $arrField)
{
// FFL = Form Field
$strClass = $GLOBALS['TL_FFL'][$arrField['inputType']];
$arrField['eval']['required'] = $arrField['eval']['mandatory'];
$objWidget = new $strClass($this->prepareForWidget($arrField, $arrField['name'], $arrField['value']));
$arrWidgets[] = $objWidget;
}
$this->Template->fields = $arrWidgets;
$this->Template->submit = 'Envoyer'; //trouver comment passer une variable ['TL_LANG']
$this->Template->action = ampersand($this->Environment->request);
// Add RDV
if ($this->Input->post('FORM_SUBMIT') == 'tl_rdv')
{
$this->addRdv();
//Permet d'actualiser la page sans renvoyer les donn�es dans la BD
$this->reload();
}
}
protected function addRdv()
{
// Prepare record
$arrSet = array
(
// 0 = libre et 1 = r�serv�
'is_reserved' => 1,
'tstamp' => time(),
'customer_title' => $this->Input->post('customer_title'),
'customer_firstname' => $this->Input->post('customer_firstname'),
'customer_lastname' => $this->Input->post('customer_lastname'),
'customer_phone' => $this->Input->post('customer_phone'),
'customer_mail' => $this->Input->post('customer_mail'),
'customer_description' => $this->Input->post('customer_description'),
);
$insert = $this->Database->prepare("INSERT INTO tl_rdv_light %s")->set($arrSet)->execute();
}
}
?>
Vielen Dank im VorausCode:<div class="<?php echo $this->class; ?>"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>
<?php if ($this->headline): ?>
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
<?php endif; ?>
<!-- indexer::stop -->
<div class="form">
<form action="<?php echo $this->action; ?>" method="post">
<input type="hidden" name="FORM_SUBMIT" value="tl_rdv" /><?php echo $this->messages; ?>
<?php foreach ($this->fields as $objWidget): ?>
<div class="widget">
<?php echo $objWidget->generateWithError(); ?> <?php if ($objWidget->required): ?><span class="mandatory">*</span><?php endif; ?>
</div>
<?php endforeach; ?>
<input type="submit" class="submit" value="<?php echo $this->submit; ?>" />
</form>
</div>
<!-- indexer::continue -->
</div>