![]()
|
|
Template source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<div class="formElement{if $errorField == 'startAmount'} formError{/if}"> <div class="formFieldLabel"> <label for="startAmount">{lang}wbb.threadAdd.startAmount{/lang}</label> </div> <div class="formField"> <input type="text" class="inputText" name="startAmount" id="startAmount" value="{$startAmount}" tabindex="{counter name='tabindex'}" /> {if $errorField == 'startAmount'} <p class="innerError"> {if $errorType == 'empty'}{lang}wcf.global.error.empty{/lang}{/if} </p> {/if} </div> </div> |
|
|
PHP Source code |
1 2 3 4 5 |
case 'validate':
if(empty($this->startAmount)) {
throw new UserInputException('startAmount');
}
break;
|
|
|
PHP Source code |
1 |
public $errorField = '';
|
|
|
PHP Source code |
1 2 3 4 5 6 7 8 9 10 11 |
case 'validate':
try {
if (empty($this->startAmount)) {
throw new UserInputException('startAmount');
}
}
catch (UserInputException $e) {
$eventObj->errorField = $e->getField();
$eventObj->errorType = $e->getType();
}
break;
|
|
|
PHP Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
case 'submit':
try {
$this->validateStartAmount();
}
catch (UserInputException $e) {
$this->errorField = $e->getField();
$this->errorType = $e->getType();
}
break;
case 'validate':
$this->validateStartAmount();
break;
}
}
protected function validateStartAmount() {
if(empty($this->startAmount)) {
throw new UserInputException('startAmount');
}
}
|
This post has been edited 1 times, last edit by "Sebastian S." (Jul 31st 2012, 4:21pm)
|
|
PHP Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/**
* @see Form::submit()
*/
public function submit() {
// call submit event
EventHandler::fireAction($this, 'submit'); // das ist der falsche Platz dazu
$this->readFormParameters();
try {
$this->validate(); // hier musst du dein Eventlistener hereinhängen, beim Event validate
// no errors
$this->save();
}
catch (UserInputException $e) {
$this->errorField = $e->getField();
$this->errorType = $e->getType();
}
}
|
|
|
PHP Source code |
1 2 3 |
case 'submit':
parent::submit();
break;
|
|
|
PHP Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
<?php
//wcf imports
require_once(WCF_DIR.'lib/system/event/EventListener.class.php');
//wbb imports
require_once(WBB_DIR.'lib/form/ThreadAddForm.class.php');
class AdditionalMarketplaceFormFieldsListener extends ThreadAddForm implements EventListener {
//define variables
public $startAmount;
public $buyImmediately;
//public $errorField = '';
//public $errorType = '';
public function execute($eventObj, $className, $eventName) {
//execute commands depending on eventName
switch($eventName) {
case 'assignVariables':
parent::assignVariables();
WCF::getTPL()->assign(array(
'startAmount' => $this->startAmount,
'buyImmediately' => $this->buyImmediately,
//'errorField' => $this->errorField,
//'errorType' => $this->errorType
));
WCF::getTPL()->append('additionalInformationFields', WCF::getTPL()->fetch('additionalMarketplaceFormFields'));
break;
case 'submit':
break;
case 'readFormParameters':
if(isset($_POST['startAmount'])) $this->startAmount = intval($_POST['startAmount']);
if(isset($_POST['buyImmediately'])) $this->buyImmediately = intval($_POST['buyImmediately']);
break;
case 'validate':
break;
case 'save':
break;
}
}
}
?>
|
This post has been edited 3 times, last edit by "Sebastian S." (Aug 4th 2012, 1:26am)
|
|
XML |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?xml version="1.0" encoding="UTF-8"?> <data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/eventListener.xsd"> <import> <eventlistener> <eventclassname>ThreadAddForm</eventclassname> <eventname>readFormParameters</eventname> <environment>user</environment> <listenerclassname>lib/system/event/listener/AdditionalMarketplaceFormFieldsListener</listenerclassname> </eventlistener> <eventlistener> <eventclassname>ThreadAddForm</eventclassname> <eventname>validate</eventname> <environment>user</environment> <listenerclassname>lib/system/event/listener/AdditionalMarketplaceFormFieldsListener</listenerclassname> </eventlistener> <eventlistener> <eventclassname>ThreadAddForm</eventclassname> <eventname>save</eventname> <environment>user</environment> <listenerclassname>lib/system/event/listener/AdditionalMarketplaceFormFieldsListener</listenerclassname> </eventlistener> <eventlistener> <eventclassname>ThreadAddForm</eventclassname> <eventname>assignVariables</eventname> <environment>user</environment> <listenerclassname>lib/system/event/listener/AdditionalMarketplaceFormFieldsListener</listenerclassname> </eventlistener> </import> </data> |
|
|
PHP Source code |
1 |
if(isset($_POST['buyImmediately'])) $this->buyImmediately = intval($_POST['buyImmediately']);
|
|
|
PHP Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<?php
//wcf imports
require_once(WCF_DIR.'lib/system/event/EventListener.class.php');
class AdditionalMarketplaceFormFieldsListener implements EventListener {
//define variables
public $startAmount;
public $buyImmediately;
public function execute($eventObj, $className, $eventName) {
//execute commands depending on eventName
switch($eventName) {
case 'show':
WCF::getTPL()->append('additionalInformationFields', WCF::getTPL()->fetch('additionalMarketplaceFormFields'));
break;
case 'assignVariables':
WCF::getTPL()->assign(array(
'startAmount' => $this->startAmount,
'buyImmediately' => $this->buyImmediately,
));
break;
case 'readFormParameters':
if(isset($_POST['startAmount'])) $this->startAmount = intval($_POST['startAmount']);
if(isset($_POST['buyImmediately'])) $this->buyImmediately = intval($_POST['buyImmediately']);
break;
case 'validate':
$this->validateStartAmount();
$this->validateBuyImmediately();
break;
case 'save':
break;
}
}
protected function validateStartAmount() {
if(empty($this->startAmount)) {
throw new UserInputException('startAmount');
}
}
protected function validateBuyImmediately() {
if(!empty($this->buyImmediately)) {
if($this->buyImmediately <= $this->startAmount) {
throw new UserInputException('buyImmediately','tooSmall');
}
if(!preg_match('/^[0-9]+/',$this->buyImmediately)) {
throw new UserInputExcpetion('buyImmediately', 'illegalCharacters');
}
}
}
}
?>
|
This post has been edited 3 times, last edit by "Sebastian S." (Aug 4th 2012, 4:46pm)
Forum Software: Burning Board® 3.1.7, developed by WoltLab® GmbH