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();
}
}
?>
Template:
Lesezeichen