Questtype ?Textinput?: add support for field sizes (Issue #252) and general improvements

This commit is contained in:
coderkun 2014-05-19 11:36:36 +02:00
commit b7a7299b45
4 changed files with 88 additions and 58 deletions

View file

@ -1,11 +1,25 @@
<form method="post" class="textinput">
<p>
<?php foreach($texts as $i => &$text) : ?>
<?php if($i > 0) : ?>
<input type="text" name="answers[<?=$i-1?>]" value="<?=$regexs[$i-1]['answer']?>" />
<?php endif ?>
<?=$t->t($text)?>
<?php endforeach ?>
<?php
$text = $t->t($task['text']);
// Insert input fields
foreach(array_reverse($fields) as &$field)
{
// Get positions
$posStart = mb_strrpos($text, '[textinput]', 0, 'UTF-8');
$posEnd = $posStart + mb_strlen('[textinput]', 'UTF-8');
// Create input field
$class = ($field['size'] != 'default') ? $field['size'] : null;
$value = (array_key_exists('answer', $field)) ? $field['answer'] : null;
$inputField = '<input type="text" name="answers[]" value="'.$value.'" class="'.$class.'" />';
// Insert input field
$text = mb_substr($text, 0, $posStart, 'UTF-8') . $inputField . mb_substr($text, $posEnd, mb_strlen($text)-$posEnd, 'UTF-8');
}
?>
<?=$text?>
</p>
<input type="submit" name="submit" value="<?=_('solve')?>" />
</form>

View file

@ -1,7 +1,21 @@
<?php foreach($texts as $i => &$text) : ?>
<?php if($i > 0) : ?>
<span style="background-color:grey"><?=$regexs[$i-1]['answer']?></span>
<?php if($regexs[$i-1]['right']) : ?>✓<?php else: ?>✕<?php endif ?>
<?php endif ?>
<?=$t->t($text)?>
<?php endforeach ?>
<p>
<?php
$text = $t->t($task['text']);
// Insert Character answers
foreach(array_reverse($fields) as &$field)
{
// Get positions
$posStart = mb_strrpos($text, '[textinput]', 0, 'UTF-8');
$posEnd = $posStart + mb_strlen('[textinput]', 'UTF-8');
// Create field for Character answer
$answerField = '<span style="background-color:grey">'.$field['answer'].'</span>';
$answerField .= ($field['right']) ? '✓' : '✕';
// Insert input field
$text = mb_substr($text, 0, $posStart, 'UTF-8') . $answerField . mb_substr($text, $posEnd, mb_strlen($text)-$posEnd, 'UTF-8');
}
?>
<?=$text?>
</p>