Questtype ?Textinput?: improve injection of input-fields

This commit is contained in:
oliver 2015-05-12 16:45:15 +02:00
commit 4cb337f0aa

View file

@ -1,14 +1,14 @@
<form method="post" class="textinput"> <form method="post" class="textinput">
<p> <?php $text = $t->t($task['text']); ?>
<?php $posStart = 0; ?> <?php $posStart = 0; ?>
<?php foreach($fields as &$field) : ?> <?php foreach($fields as &$field) : ?>
<?php $posEnd = mb_strpos($task['text'], '[textinput]', $posStart, 'UTF-8'); ?> <?php $posEnd = mb_strpos($text, '[textinput]', $posStart, 'UTF-8'); ?>
<?=$t->t(mb_substr($task['text'], $posStart, $posEnd-$posStart, 'UTF-8'))?> <?=mb_substr($text, $posStart, $posEnd-$posStart, 'UTF-8')?>
<input type="text" name="answers[]" value="<?=(array_key_exists('answer', $field)) ? $field['answer'] : ''?>" <?php if($field['size'] != 'default') : ?>class="<?=$field['size']?>"<?php endif ?> /> <input type="text" name="answers[]" value="<?=(array_key_exists('answer', $field)) ? $field['answer'] : ''?>" <?php if($field['size'] != 'default') : ?>class="<?=$field['size']?>"<?php endif ?> />
<?php $posStart = $posEnd + mb_strlen('[textinput]', 'UTF-8'); ?> <?php $posStart = $posEnd + mb_strlen('[textinput]', 'UTF-8'); ?>
<?php endforeach ?> <?php endforeach ?>
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?> <?=mb_substr($text, $posStart, mb_strlen($text, 'UTF-8')-$posStart, 'UTF-8')?>
</p>
<?php if(!is_null($nCorrectAnswers)) : ?> <?php if(!is_null($nCorrectAnswers)) : ?>
<p><?=sprintf(_('You filled %d of %d fields correctly'), $nCorrectAnswers, count($fields))?>.</p> <p><?=sprintf(_('You filled %d of %d fields correctly'), $nCorrectAnswers, count($fields))?>.</p>
<?php endif ?> <?php endif ?>