Ich versuche in einer Form die Fehlerbehandlung von Woltlab nachzubauen. Orientiert habe ich mich an an der RegisterForm.class.php und dem entsprechendem Template. Obwohl ich das ziemlich genau nachgebaut - um nicht zu sagen dreist kopiert - habe, hatte ich gehofft, dass ich neben der allgemeinen Fehlermeldung "Du hast da was vergessen..." auch die im template eingepflegte Meldung zu dem jeweiligem Feld angezeigt bekomme.
Ich habe mal den Quellcode beigefügt.
PHP: PetbattleAccountForm.class.php
<?php
namespace wcf\form;
use wcf\data\user\User;
use wcf\system\WCF;
use wcf\util\JSON;
use wcf\action\BnetRefershAction;
use wcf\data\wow\character\WoWCharacter;
use wcf\data\wow\character\WoWCharacterList;
use wcf\data\wow\battlepet\WoWBattlePet;
use wcf\data\wow\battlepet\WoWBattlePetList;
use wcf\system\exception\UserInputException;
use wcf\system\cache\builder\WoWUserPetbattlelistCacheBuilder;
use wcf\action\BnetAuthAction;
use wcf\data\tournament\attendance\TournamentAttendance;
use wcf\data\tournament\attendance\TournamentAttendanceEditor;
use wcf\data\tournament\attendance\TournamentAttandanceAction;
/**
* Create or edit a tornamanet attandance
*
* @author Veneanar
* @copyright 2016 Sylvanas Garde
* @package eu.petbattle.tournament
* @subpackage tournament.managment
* @category Torunamten Tools
*/
class PetbattleAccountForm extends AbstractForm {
/**
* @see \wcf\page\AbstractPage::$activeMenuItem
*/
public $activeMenuItem = 'wcf.page.bnetTool.MyAccount';
/**
* @see \wcf\page\AbstractPage::$templateName
*/
public $templateName = 'petbattleAccountForm';
/**
* @see \wcf\page\AbstractPage::$enableTracking
*/
public $enableTracking = true;
/**
* @see \wcf\page\AbstractPage::$loginRequired
*/
public $loginRequired = true;
/**
* @see \wcf\page\AbstractPage::$neededPermissions
*/
public $neededPermissions = array('user.bnetTool.canRegisterTournamaent', );
/**
* $petIDs
* List of selected pets
* @var array
*/
public $petIDs = null;
/**
* $petIDs
* selected character
* @var int
*/
public $charID = 0;
/**
* @see Form::submit()
*/
public function submit() {
if (isset($_POST['refreshData']) && $_POST['refreshData']) {
WoWUserPetbattlelistCacheBuilder::GetInstance()->reset();
$action = new BnetRefershAction();
$action->execute();
exit;
}
parent::submit();
}
/**
* @see Form::readFormParameters()
*/
public function readFormParameters() {
parent::readFormParameters();
if ((isset($_POST['petIDs'])) && (!empty($_POST['petIDs']))) {
$this->petIDs = JSON::decode($_POST['petIDs'], true);
} else {
$this->petIDs = array();
}
$this->charID = intval($_POST['charID'] ?: 0);
}
/**
* @see \wcf\form\IForm::validate()
*/
public function validate() {
if (!empty($this->petIDs)) {
if (count($this->petIDs) < 6) {
throw new UserInputException("petselector", "low");
}
if (count($this->petIDs) > 12) {
throw new UserInputException("petselector", "high");
}
} else {
throw new UserInputException("petselector", "no");
}
if ($this->charID < 1) {
throw new UserInputException("charselector");
}
parent::validate();
}
/**
* @see Form::save()
*/
public function save() {
$tournamentAttendence = TournamentAttendance::getByUser(WCF::getUser()->getUserID());
if ($tournamentAttendence->attandanceID > 0) {
$objectAction = new TournamentAttandanceAction(array(), 'create', array(
'data' => array(
'userID' => WCF::getUser()->getUserID(),
'charID' => $this->charID,
'petIDs' => serialize($this->petIDs),
'date' => TIME_NOW,
'state' => 1,
)
));
$objectAction->executeAction();
} else {
$userEditor = new TournamentAttendanceEditor($tournamentAttendence);
$objectAction = new TournamentAttandanceAction(array(), 'update', array(
'data' => array(
'charID' => $this->charID,
'TournamentAttendanceEditor' => $userEditor,
)
));
$objectAction->executeAction();
}
parent::save();
}
/**
* @see Page::assignVariables()
*/
public function assignVariables() {
parent::assignVariables();
$tournamentAttendence = TournamentAttendance::getByUser(WCF::getUser()->getUserID());
$woWCharList = new WoWCharacterList();
// ENTFERNT wegen cloudflare
$woWCharList->readObjects();
$charList= $woWCharList->getObjects();
if ($tournamentAttendence->attandanceID > 0) {
WCF::getTPL()->assign(array(
'cnttype' => 'changeChar',
'petList' => $tournamentAttendence->pets,
'selectedChar' => $tournamentAttendence->char,
'avaibleChars' => $charList,
));
} else {
$petlist = WoWUserPetbattlelistCacheBuilder::getInstance()->getData(array('userID' => WCF::getUser()->getUserID()));
if ($petlist) {
WCF::getTPL()->assign(array(
'cnttype' => 'performRegister',
'petList' => $petlist,
'avaibleChars' => $charList,
));
} else {
WCF::getTPL()->assign(array(
'cnttype' => 'bnetError',
));
}
}
}
}
Display More
Code
{include file='documentHeader'}
<head>
<title>{lang}wcf.page.bnet.tornamentregister.title{/lang}</title>
{include file='headInclude'}
<script data-relocate="true" type="text/javascript" src="{@$__wcf->getPath()}js/jquery.searchabledropdown-1.0.8.min.js?v={@$__wcfVersion}"></script>
<style type="text/css">
#CompletePetList, #SelectedPets {
border: 1px solid #000;
width: 300px;
min-height: 500px;
max-height: 500px;
list-style-type: none;
margin: 0;
padding: 5px 0 0 0;
margin-right: 10px;
overflow-y:auto;
overflow-x:hidden;
}
#CompletePetList li, #SelectedPets li {
margin: 0 5px 5px 5px;
padding: 5px;
font-size: 1.2em;
width: 280px;
}
.petbox {
border: 1px solid #DDD;
background-color: rgba(0,0,0,0.3);
box-shadow: 1px 2px 4px rgba(0,0,0, .2);
}
</style>
</head>
<body id="tpl{$templateName|ucfirst}">
{include file='header'}
<header class="boxHeadline">
<h1>{lang}wcf.page.bnet.tornamentregister.title{/lang}</h1>
</header>
{if $success|isset}
<p class="success">{lang}wcf.global.success.{$action}{/lang}</p>
{/if}
{include file='userNotice'}
<div class="container containerPadding">
{include file='formError'}
{if $avaibleChars|count}
<form id="tornament" name="tornament" method="post" action="" enctype="multipart/form-data">
<fieldset>
<legend>{lang}wcf.page.bnet.tornamentregister.charinfo{/lang}</legend>
<dl>
<dt>
<label>{lang}wcf.page.bnet.tornamentregister.refershdata{/lang}</label>
</dt>
<dd>
<input class)"small" type="submit" value="Aktualisieren" name="refreshData" id="refreshData" accesskey="s" />
<small>{lang}wcf.page.bnet.tornamentregister.refershdata.description{/lang}</small>
{@SECURITY_TOKEN_INPUT_TAG}
</dd>
<dt>
<label for="charID">{lang}wcf.page.bnet.tornamentregister.charname{/lang}</label>
</dt>
<dd>
<select id="charID" name="charID" class="medium">
{foreach from=$avaibleChars item=char}
<option value="{$char->charID}">{@$char->charname} - {@$char->realmname} ({@$char->level})</option>
{/foreach}
</select>
{if $errorType.charselector|isset}
<small class="innerError">
{lang}wcf.page.bnet.tornamentregister.error_nochar{/lang}
</small>
{/if}
</dd>
</dl>
</fieldset>
<fieldset>
<legend>{lang}wcf.page.bnet.tornamentregister.tornamentpets{/lang}</legend>
<dl>
<dt>
<label for="petselection">{lang}wcf.page.bnet.tornamentregister.selectpets{/lang}</label>
</dt>
<dd>
{if $errorType.petselector|isset}
<small class="innerError">
{if $errorType.petselector == 'low'}{lang}wcf.page.bnet.tornamentregister.error_lowpet{/lang}{/if}
{if $errorType.petselector == 'high'}{lang}wcf.page.bnet.tornamentregister.error_highpet{/lang}{/if}
{if $errorType.petselector == 'no'}{lang}wcf.page.bnet.tornamentregister.error_nope{/lang}{/if}
</small>
{/if}
{lang}wcf.page.bnet.tornamentregister.selectpets.description{/lang}
<div id="petselection">
<div style="float:left">
<header class="containerHeadline">
<h3>{lang}wcf.page.bnet.tornamentregister.avaublepets{/lang}</h3>
</header>
<div style="height:30px">
{lang}wcf.page.bnet.tornamentregister.searchfilter{/lang}
<input placeholder="{lang}wcf.page.bnet.tornamentregister.searchhint{/lang}" name="filterbox" id="filterbox" type="text" style="margin-bottom:5px"/>
</div>
<ul id="CompletePetList" class="connectedSortable">
{foreach from=$petList item=pet}
<li class="ui-state-default" data-petname="{@$pet->name_de_DE}" data-petid="{@$pet->petID}">
<div class="petbox">
<img src="{@$pet->icon}" width="32" height="32" style="float:left; margin-right:10px;"/>
<p style="margin: 0; line-height: 36px;">{@$pet->name_de_DE}</p>
</div>
</li>
{/foreach}
</ul>
</div>
<div style="float:left">
<header class="containerHeadline">
<h3>{lang}wcf.page.bnet.tornamentregister.selectedpets{/lang}</h3>
</header>
<div id="SelectCount" style="height:30px">0 / 12</div>
<ul id="SelectedPets" class="connectedSortable">
</ul>
</div>
</div>
<div style="clear:both"></div>
</dd>
</dl>
</fieldset>
<div class="formSubmit">
<input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s" />
<input type="hidden" name="petIDs" id="petIDs">
{@SECURITY_TOKEN_INPUT_TAG}
</div>
</form>
{else}
<form id="tornament" name="tornament" method="post" action="" enctype="multipart/form-data">
<div class="error">
<p>{lang}wcf.page.bnet.tornamentregister.charerror{/lang}</p>
<div class="formSubmit">
<input class)"small" type="submit" value="{lang}wcf.page.bnet.tornamentregister.charerror.button{/lang}" name="refreshData" id="refreshData" accesskey="s" />
{@SECURITY_TOKEN_INPUT_TAG}
</div>
<p><small>{lang}wcf.page.bnet.tornamentregister.charerror.detail{/lang}</small></p>
</div>
</form>
{/if}
</div>
</div>
{literal}
<script data-relocate="true">
//<![CDATA[
function PetUpdate() {
var selpets = $( "#SelectedPets li" ).length;
if (selpets >= 6 && selpets <= 12) {
$("#action").show();
$( "#action" ).prop( "disabled", false );
$("#SelectCount").css('color', 'green');
} else {
$("#action").hide();
$( "#action" ).prop( "disabled", true );
$("#SelectCount").css('color', 'red');
}
var petarray = new Array();
$('#SelectedPets>li').each(function(){
petarray.push({name:$(this).data("petname"), id: $(this).data("petid")});
});
$("#petIDs").val(JSON.stringify(petarray));
$("#SelectCount").text(selpets+" / 12");
}
function isValidBattleTag(tag) {
var pattern = new RegExp(/^\D.{2,11}#\d{4}$/);
return pattern.test(tag);
}
$(function() {
$( "#CompletePetList, #SelectedPets" ).sortable({
connectWith: ".connectedSortable"
}).disableSelection().on("click", ".petbox", function() {
// First figure out which list the clicked element is NOT in...
var otherUL = $("#CompletePetList, #SelectedPets").not($(this).closest("ul"));
var li = $(this).closest("li");
// Move the li to the other list. prependTo() can also be used instead of appendTo().
li.detach().appendTo(otherUL);
PetUpdate();
// Finally, switch the class on the li, and change the arrow's direction.
});
$( "#SelectedPets" ).on( "sortupdate", function( event, ui ) {
PetUpdate();
});
$('#filterbox').on('input',function(e){
var valThis = $(this).val().toLowerCase();
$('#CompletePetList>li').each(function(){
var text = $(this).data("petname").toLowerCase();
// console.log("Suche nach:"+ valThis + " in " + text);
(text.indexOf(valThis) == 0) ? $(this).show() : $(this).hide();
});
});
});
//]]>
</script>
{/literal}
{include file='footer'}
</body>
</html>
Display More
@Alexander Ebert @Marcel Werk
Leider blockiert cloudflare das erstellen des Posts sobald man SQL Syntax verwendet. Nachdem ich die entsprechende Zeilen entfernt habe, ging es. Ist das so gewollt?