Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/69980-solved-issue-passing-form-data/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.