Skip to content

Commit

Permalink
Dev: some cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Feb 17, 2017
1 parent 24e5bbc commit d312f2a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 82 deletions.
48 changes: 8 additions & 40 deletions application/helpers/frontend_helper.php
Expand Up @@ -1495,51 +1495,19 @@ function renderRenderWayForm($renderWay, array $redata, array $scenarios, $sTemp

case "main": //Token required, maybe Captcha required

// Using the normal Yii rendering way is a good idea: but, or we do it everywhere or we do it nowhere.
// Mixing different render logic is a bad idea, it makes it harder to understand.
// But: once everything is twiged, we could use this method everywhere

// QUESTION: maybe it's needed by Captcha system?
App()->getController()->layout = "survey";
App()->getController()->aReplacementData = $aEnterTokenData;
App()->getController()->bStartSurvey = true;

$aForm = array();
// Datas for the form
$aForm = array();
$aForm['sType'] = ($scenarios['tokenRequired'])?'token':'captcha';
$aForm['token'] = array_key_exists('token', $aEnterTokenData)?$aEnterTokenData['token']:null;
$aForm['aEnterErrors'] = $aEnterTokenData['aEnterErrors'];
$aForm['bCaptchaEnabled'] = $aEnterTokenData['bCaptchaEnabled'];

if ($aEnterTokenData['bCaptchaEnabled']){
$aForm['bCaptchaEnabled'] = $aEnterTokenData['bCaptchaEnabled'];
}





$thissurvey["aForm"] = $aForm;
// render token form
/*
$aReplacements['FORMID'] = ($scenarios['tokenRequired'])?'token':'captcha';
$aReplacements['FORMHEADING'] = App()->getController()->renderPartial("/survey/frontpage/{$aReplacements['FORMID']}Form/heading",$aEnterTokenData,true);
$aReplacements['FORMMESSAGE'] = App()->getController()->renderPartial("/survey/frontpage/{$aReplacements['FORMID']}Form/message",$aEnterTokenData,true);
$aReplacements['FORMERROR'] = App()->getController()->renderPartial("/survey/frontpage/{$aReplacements['FORMID']}Form/error",$aEnterTokenData,true);
$aReplacements['FORM'] = CHtml::beginForm(array("/survey/index","sid"=>$surveyid), 'post',array('id'=>'form-'.$aReplacements['FORMID'],'class'=>'ls-form'));
$aReplacements['FORM'] .= App()->getController()->renderPartial("/survey/frontpage/{$aReplacements['FORMID']}Form/form",$aEnterTokenData,true);
$aReplacements['FORM'] .= CHtml::endForm();
*/
/* @ todo : some hidden field must be moved here : in controller */

// $content = templatereplace(file_get_contents($sTemplateViewPath."form.pstpl"),$aReplacements,$aData);

/* App()->getController()->render("/survey/system/display",array(
'content'=>$content,
));
*/

$redata = compact(array_keys(get_defined_vars()));
echo templatereplace(file_get_contents($sTemplateViewPath."user_forms_layout.twig"), array(), $redata);
// Rendering user_forms_layout.twig
$thissurvey["aForm"] = $aForm;
$redata = compact(array_keys(get_defined_vars()));
echo templatereplace(file_get_contents($sTemplateViewPath."user_forms_layout.twig"), array(), $redata);

// With a good logic in survey runtime, we could avoid those exits
Yii::app()->end();
break;

Expand Down
72 changes: 30 additions & 42 deletions templates/default/views/user_forms_layout.twig
@@ -1,4 +1,9 @@

{#
TODO: alignement, some unclosed div (for token + captcha)
#}

<!DOCTYPE html>
<html lang="{{ aSurveyInfo.languagecode }}" dir="{{ aSurveyInfo.dir }}" class="no-js {{ aSurveyInfo.languagecode }} dir-{{ aSurveyInfo.dir }} ">

Expand All @@ -16,12 +21,11 @@

<!-- Main Row -->
<div id="main-row">
{{ include('./subviews/flash_message.twig') }}

<!-- Main Col -->
<div class="col-centered" id="main-col">

<div class='{FORMID}-page'>
<div class='{{aSurveyInfo.aForm.sType}}-page'>
<div class="h3">
{# OLD FORMHEADING #}
{% if aSurveyInfo.aForm.sType == 'token' %}
Expand All @@ -35,36 +39,31 @@

<div class="well">

{# TOKEN #}
{% if aSurveyInfo.aForm.sType == 'token' %}
{# OLD FORMMESSAGE #}
<p class='text-info'>
{# TODO: convert !isset to null #}
{% if aSurveyInfo.aForm.token == null %}
{{ "If you have been issued a token, please enter it in the box below and click continue." | t }}
{% else %}
{{ "Please confirm the token by answering the security question below and click continue." | t }}
{% endif %}
</p>
{% endif %}

{# OLD FORMERROR #}
{% if not empty(aSurveyInfo.aForm.aEnterErrors) %}
{# TODO: check how is defined $class #}
<ul class='alert alert-danger list-unstyled' role='alert'>
{% for key, error in aSurveyInfo.aForm.aEnterErrors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}

<div class="form-{{ aSurveyInfo.aForm.sType }}">
{# old FORM
TODO: check if surveyUrl is ok
CHtml::beginForm(array("/survey/index","sid"=>$surveyid), 'post',array('id'=>'form-'.$aReplacements['FORMID'],'class'=>'ls-form'));
#}
{# TOKEN #}
{% if aSurveyInfo.aForm.sType == 'token' %}
{# OLD FORMMESSAGE #}
<p class='text-info'>
{# TODO: convert !isset to null #}
{% if aSurveyInfo.aForm.token == null %}
{{ "If you have been issued a token, please enter it in the box below and click continue." | t }}
{% else %}
{{ "Please confirm the token by answering the security question below and click continue." | t }}
{% endif %}
</p>
{% endif %}

{# OLD FORMERROR #}
{% if not empty(aSurveyInfo.aForm.aEnterErrors) %}
{# TODO: check how is defined $class #}
<ul class='alert alert-danger list-unstyled' role='alert'>
{% for key, error in aSurveyInfo.aForm.aEnterErrors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}

<div class="form-{{ aSurveyInfo.aForm.sType }}">
{# old FORM#}

{#
array of attributes of the form tag.
Expand All @@ -87,9 +86,6 @@
(htmlOptions)
)
}}



{# TOKEN FORM #}


Expand Down Expand Up @@ -185,14 +181,6 @@
<div class='ls-input-group'>
<div class='ls-input-group-extra captcha-widget' >
{{ renderCaptcha() }}

{#
<?php $this->widget('CCaptcha',array(
'buttonOptions'=>array('class'=> 'btn btn-xs btn-info'),
'buttonType' => 'button',
'buttonLabel' => gt('Reload image','unescaped')
)); ?>
#}
</div>
<input class='form-control' type='text' size='15' maxlength='15' id='loadsecurity' name='loadsecurity' value='' alt='' required>
</div>
Expand Down

0 comments on commit d312f2a

Please sign in to comment.