开发者

Poll form (view) creates security errors in CakePHP

I am writing a simple poll for Cakephp. I have created tables polls and poll_votes. Poll contains 7 columns: id,question,numberofanswers,answer1,answer2,answer3,answer4. PollVote contains 4: id,poll_id,ip,v开发者_JAVA技巧ote. If this works, I might be adding a new table called PollAnswers as a way to get rid of the answer-limit.

Unfortunately the view I made causes security errors. I would prefer to use the form-helper as a whole, but I have not figured out how since I need radio-buttons with multiple options that have id's 1 to 4, but show answer1 to answer4.

[daweb@directadmin01 public_html]$ cat models/poll.php
<?php
class Poll extends AppModel {
        var $name = 'Poll';
        var $displayField = 'question';

        var $hasMany = array(
                'PollVote' => array(
                        'className' => 'PollVote',
                        'foreignKey' => 'poll_id',
                        'dependent' => false
                )
        );
}
?>
[daweb@directadmin01 public_html]$ cat models/poll_vote.php
<?php
class PollVote extends AppModel {
        var $name = 'PollVote';

        var $belongsTo = array(
                'Poll' => array(
                        'className' => 'Poll',
                        'foreignKey' => 'poll_id'
                )
        );
}
?>
[daweb@directadmin01 public_html]$ cat views/polls/view.ctp
<h2><?=$polls[0]['Poll']['question']?></h2>
<?php
echo $this->Form->create('Poll');
?>
<br /><p>
<select name="PollName" id="PollFieldId">
<option value="0"><?=$polls[0]['Poll']['answer1']?></option>
<option value="1"><?=$polls[0]['Poll']['answer2']?></option>
<option value="2"><?=$polls[0]['Poll']['answer3']?></option>
<option value="3"><?=$polls[0]['Poll']['answer4']?></option>
</select>
<?php
echo $this->Form->input('id', array('type' => 'hidden'));
echo $this->Form->end('Submit');
?>
</p>
[daweb@directadmin01 public_html]$

I am honestly not sure I am creating the Poll application with the right design, so general advice is welcome. Unfortunately I was unable to find examples of polls written in Cakephp to help me.


your design is fine, as long as you only need 4 questions for each poll. Change numberofanswers to pollVote_count and use counterCache Take a look at Database design for a survey, although that might be overkill for your purpose.

for the radio input, that should be in the pollVotes controller/add action, not in the polls/view:

echo $this->Form->create('PollVote');
echo $this->Form->input('poll_id');
echo $this->Form->input('vote',array('type' => 'radio','options' => $polls[0]['Poll']));
echo $this->Form->end('Submit');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜