gigantorTRON Posted September 19, 2007 Share Posted September 19, 2007 Hey guys and gals... I have a project that consists of a large quiz that displays multiple questions per page from a database and then saves those answers to another database table. The issue I'm having is with a form that consists of radio buttons and check boxes. The form is only submitting the last checked value for the check boxes rather than all checked values. I'm sure this is an easy fix but my mind is about to explode from a full day's work and a lot of time trying to figure this out, so I was wondering if someone could give me a hand. Here is the code from my form... function get_form_type($qid) { $query = "SELECT choice, type, text FROM answer WHERE question_id =" . $qid; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $choice = $row['choice']; $type = $row['type']; $text = $row['text']; $output .= $this->form_output($qid, $type, $choice, $text); } return $output; } function form_output($qid, $type, $choice, $text) { switch($type) { //radio button case "R": $output = "<p><input type='radio' name='" . $qid . "' value='" . $choice . "'> " . $text . "</p>"; break; case "C": $output .= "<p><input type='checkbox' name='" . $qid . "' value='" . $choice . "'> " . $text . "</p>"; break; } return $output; } And the main page of the form... <?php print "<form name='form1' method='POST' action='test_submit_old.php?question=" . $question . "'>";?> <?php $form = $caller->get_form_type(15); print $form;?> <input type="submit" name="" value="Submit"> </p> </form> And here's the script that's called by the form... foreach ($_POST as $name=>$value) { print $value; } So when I call the form handler script I only get the value of my radio button and the value of my last checked check box. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/69980-solved-issue-passing-form-data/ Share on other sites More sharing options...
gigantorTRON Posted September 20, 2007 Author Share Posted September 20, 2007 Any help?? Quote Link to comment https://forums.phpfreaks.com/topic/69980-solved-issue-passing-form-data/#findComment-351616 Share on other sites More sharing options...
BlueSkyIS Posted September 20, 2007 Share Posted September 20, 2007 the name of your checkbox needs to have brackets: name='".$qid."[]' Quote Link to comment https://forums.phpfreaks.com/topic/69980-solved-issue-passing-form-data/#findComment-351638 Share on other sites More sharing options...
gigantorTRON Posted September 20, 2007 Author Share Posted September 20, 2007 Ah yes... thanks !!! Quote Link to comment https://forums.phpfreaks.com/topic/69980-solved-issue-passing-form-data/#findComment-351709 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.