sasori
(Nemo Md5)
November 30, 2010, 3:40pm
1
Hi, I need some tips/suggestions from all of you.
currently I have a secret question input field to fill-in by a user who wish to register.
then I was asked to put a pre-made questionaires , i was thinking of creating a drop down
this is what i currently have
<div class = "row">
<?php echo CHtml::activeLabelEx($form,'SecretQuestion'); ?>
<?php echo CHtml::activeTextArea($form,SecretQuestion', array('rows' => 2,'cols' =>15)); ?>
</div>
because of the requested additional stuff, I created a function at the members model (yii, i learned it from the book )
public function getSecretQuestions()
{
return array(
0 => 'What is your favourite Colour?',
1 => 'What is your mothers Maiden Name?',
2 => 'What is your Pets Name?',
3 => 'What was your first telephone number?',
4 => 'What was your favourite teachers name?',
5 => 'What is the title of your favourite film?',
6 => 'What is the name of your favourite book?',
);
}
but how’s/what’s the best way to approach this thing ?,
what if the user doesn’t want a pre-made question ?
i have seen this kind of stuff in some websites when I use to register
is there a yii function/component that can help me with this ?
sasori
(Nemo Md5)
December 1, 2010, 5:06am
2
here’s what i have right now at the view file
<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>
<script>
$(document).ready(function(){
$('#textSecret').css('display','none');
$('#ownSecret').click(function(){
$('#dropSecret').hide();
$('#textSecret').show();
});
});
</script>
<div id="dropSecret" class="row">
<?php echo CHtml::activeLabelEx($form,'WSMembershipSecretQuestion'); ?>
<?php echo CHtml::activeDropDownList($form,'WSMembershipSecretQuestion',$form->getSecretQuestions()); ?>
</div>
<?php echo CHtml::link('write my own secret question','#',array('id'=>'ownSecret')); ?>
<div id="textSecret" class = "row">
<?php echo CHtml::activeLabelEx($form,'WSMembershipSecretQuestion'); ?>
<?php echo CHtml::activeTextArea($form,'WSMembershipSecretQuestion', array('rows' => 2,'cols' =>15)); ?>
</div>
my question is, how can i make it sure which of the form field will get save in the db once i submitted the form ?. Even if I hid one of them using the jquery, isn’t it still part of the $_POST ? , e.g the array in the drop down list of question …
sasori
(Nemo Md5)
December 1, 2010, 5:25am
3
this is the problem I am having now
it doesn’t recognize the question in my drop down menu?
any ideas how to fix this?,
phreak
(Phreak)
December 1, 2010, 7:35am
4
try to add it to the ‘safe’ variables in your model’s rules.
sasori
(Nemo Md5)
December 1, 2010, 7:38am
5
I tried that, but it didn’t helped, I var_dumped the things that are being grabbed by
$_POST[] array,
i got this
'WSMembershipSecretQuestion' => string '' (length=0)
it grabs the text area and not the dropdown array list , that’s why
the error is occuring, any other idea ?
zaccaria
(Matteo Falsitta)
December 1, 2010, 7:53am
6
You have to save the text area in a different field, like "alternative_secret_question".
You can add a new alternative:
public function getSecretQuestions()
{
return array(
0 => 'What is your favourite Colour?',
1 => 'What is your mothers Maiden Name?',
2 => 'What is your Pets Name?',
3 => 'What was your first telephone number?',
4 => 'What was your favourite teachers name?',
5 => 'What is the title of your favourite film?',
6 => 'What is the name of your favourite book?',
7 => 'Write my own secret question',
);
}
And with jquery you can show the field only if is selected the 7th options.
sasori
(Nemo Md5)
December 1, 2010, 8:05am
7
zaccaria:
You have to save the text area in a different field, like "alternative_secret_question".
You can add a new alternative:
public function getSecretQuestions()
{
return array(
0 => 'What is your favourite Colour?',
1 => 'What is your mothers Maiden Name?',
2 => 'What is your Pets Name?',
3 => 'What was your first telephone number?',
4 => 'What was your favourite teachers name?',
5 => 'What is the title of your favourite film?',
6 => 'What is the name of your favourite book?',
7 => 'Write my own secret question',
);
}
And with jquery you can show the field only if is selected the 7th options.
I got a few questions with regards to your suggestion
I have this WSMembershipSecretQuestion table column set as ‘not null’,
that supposed to save the written secret question, if I’ll add
a new table column named e.g alternative_secret_question,
how will I implement that?, if only one of them should be saved and one is hidden ?
apparently, my form grabs the hidden textarea’s values and not the dropdown selection
sasori
(Nemo Md5)
December 1, 2010, 8:14am
8
problem solved, i changed my jquery to this
<script>
$(document).ready(function(){
$('#textSecret').hide();
$('#ownSecret').click(function(){
$('#dropSecret').remove();
$('#textSecret').show();
$ ('#ownSecret').hide();
});
});
</script>
iivano71
(Igor Zg1987)
December 1, 2010, 8:18am
9
sasori:
<div id="dropSecret" class="row">
<?php echo CHtml::activeLabelEx($form,'WSMembershipSecretQuestion'); ?>
<?php echo CHtml::DropDownList($form,'WSMembershipSecretQuestion',$form->getSecretQuestions()); ?>
</div>
problem is beacuse you have to setup first atribute
this is the solution , tested and works:
CHtml::dropDownList(‘WSMembershipSecretQuestion’,0,$form->getSecretQuestions);
zaccaria
(Matteo Falsitta)
December 1, 2010, 8:39am
10
The trick is to add a new field in database, WSMembershipMySecretQuestion.
In case of MySecretQuestion, in database there will be saved
WSMembershipSecretQuestion= 7
WSMembershipMySecretQuestion= ‘what is…’
If you remove the dropdown, a user cannot change his choice, and that is not the expected behavior.
The solution is simply to add a new field in database.
sasori
(Nemo Md5)
December 1, 2010, 8:46am
11
zaccaria:
The trick is to add a new field in database, WSMembershipMySecretQuestion.
In case of MySecretQuestion, in database there will be saved
WSMembershipSecretQuestion= 7
WSMembershipMySecretQuestion= ‘what is…’
If you remove the dropdown, a user cannot change his choice, and that is not the expected behavior.
The solution is simply to add a new field in database.
ok I’ll try this one too., but can you give a jquery snippet for it, like how to select from the array in the drop down ? all i can do for now is some basic select and some magic hide and show
sasori
(Nemo Md5)
December 1, 2010, 10:39am
12
problem is beacuse you have to setup first atribute
this is the solution , tested and works:
CHtml::dropDownList(‘WSMembershipSecretQuestion’,0,$form->getSecretQuestions);
am using an activeDropDownList
<?php echo CHtml::activeDropDownList($form,'WSMembershipSecretQuestion',$form->getSecretQuestions()); ?>
it won’t work if am gonna remove the “$form” , or it will cause an error if I’ll add zero at the left side of $form->getSecretQuestions()
sasori
(Nemo Md5)
December 2, 2010, 2:11am
13
this is the final version i have
$(document).ready(function(){
$('#textSecret').hide();
$('#showDrop').hide();
$('#drop').change(function(){
if($(this).val() == 7){
$('#textSecret').show();
$('#showDrop').show();
}
else{
$('#textSecret').hide();
}
});
});
I added the extra column in my db table to place the value of the text area
once the 7th key value pair is selected from the dropdown.
works like a charm , thanks for the suggestions