Welcome Guest, Not a member yet? Register   Sign In
How to send the selected answer?
#1

[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;
#2

[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']);
}
#3

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

[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.




Theme © iAndrew 2016 - Forum software by © MyBB