CodeIgniter Forums
How to send the selected answer? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to send the selected answer? (/showthread.php?tid=22118)



How to send the selected answer? - El Forum - 08-30-2009

[eluser]benfike[/eluser]
Hi!

I now work on a POLL system, and have an Question. How can I post the selected answer?
And then I Post that, add +1 vote for that answer.

Code:
<form action="[b]?????[/b]" method="post">
    
    <h2>&lt;?php echo htmlspecialchars($poll['name']) ?&gt;</h2>
    
    <ul>
        &lt;?php foreach($answers as $answer):?&gt;
            <li>
                &lt;input id="answer_&lt;?php echo $answer['id'] ?&gt;" name="poll_answer_id" type="radio" value="&lt;?php echo $answer['id'] ?&gt;" /&gt;
                <label for="answer_&lt;?php echo $answer['id'] ?&gt;">
                    <strong>&lt;?php echo ($answer['answer']) ?&gt;</strong>
                    (&lt;?php echo $answer['votes'] ?&gt;)
                </label>
            </li>
            &lt;?php
            endforeach;
            ?&gt;



How to send the selected answer? - El Forum - 08-30-2009

[eluser]Nick Husher[/eluser]
I think you need a submit button Wink

Code:
// poll_view.php
&lt;form action="&lt;?=site_url('/poll/pollhandler') ?&gt;"&gt;
    &lt;?php foreach($answers as $answer) ?&gt;
        // options for each answer
    &lt;?php endforeach; ?&gt;
    &lt;input type="submit" /&gt;
&lt;/form&gt;

// controllers/poll.php
function pollhandler() {
    $answer_id = $_POST['poll_answer_id'];
    
    // process poll answer, add to database
    
    // send them back where they came from
    redirect($_SERVER['HTTP_REFERER']);
}



How to send the selected answer? - El Forum - 08-30-2009

[eluser]benfike[/eluser]
I have an submit button, only not link it.
But this fine. Its working, thanks.


How to send the selected answer? - El Forum - 08-30-2009

[eluser]benfike[/eluser]
My table for answers:
votes_answers
id - answer id
pid -poll id
answer - answer name
votes - votes number

Other Question, how can sum the votes number?
So I need to SUM the votes value.