Jump to content

Form processing - checkboxes & radio buttons


joemamahunt

Recommended Posts

A little bit stuck and confused..

 

Form:

...

<label><input type="radio" id="radio1" name=”radio1” value=”1” /> 1</label>

<label><input type="radio" id="radio1" name=”radio1” value=”2” /> 2</label>

<label><input type="radio" id="radio1" name=”radio1” value=”3” /> 3</label>

<label><input type="radio" id="radio1" name=”radio1” value=”4” /> 4</label>

...

<label><input type="checkbox" id="lang_studied[]" name="lang_studied[]" value="english" /> English</label>

<label><input type="checkbox" id="lang_studied[]" name="lang_studied[]" value="russian" /> Russian</label>

<label><input type="checkbox" id="lang_studied[]" name="lang_studied[]" value="ukrainian" /> Ukrainian</label>

<label><input type="checkbox" id="lang_studied[]" name="lang_studied[]" value="romanian" /> Romanian</label>

<label><input type="checkbox" id="lang_studied[]" name="lang_studied[]" value="spanish" /> Spanish</label>

<label><input type="checkbox" id="lang_studied[]" name="lang_studied[]" value="other" /> Other</label>

...

Simplified process form:

<?php

// Pick up the form data and assign it to variables

 

$radio1 = $_POST['radio1'];

$lang_studied = $_POST['lang_studied'];

 

 

$message = "$radio1 $lang_studied";

 

// Send the mail using PHPs mail() function

mail($message);

 

// Redirect

header("Location: submitted.php");

 

?>

 

 

???

Link to comment
Share on other sites

<input type="hidden" name="Item[]" value="<?=$r['Item'];?>">
<?php
        if($_REQUEST['Submit'] == "Submit")
        {
            include("../connDB.php");
            $Items = $_REQUEST['Item'];
            for ($x = 0 ; $x < $i   ; $x++)
    { 

	$sql_add = "INSERT INTO studans (SubItems)VALUES("'" . $_REQUEST['Item'][$x] . "')";
             $q_add 	= mysql_query($sql_add);
        }
?>

please modify this.... :)

Link to comment
Share on other sites

^ thanks - fixed it.

 

<input type="hidden" name="Item[]" value="<?=$r['Item'];?>">
<?php
        if($_REQUEST['Submit'] == "Submit")
        {
            include("../connDB.php");
            $Items = $_REQUEST['Item'];
            for ($x = 0 ; $x < $i   ; $x++)
    { 

	$sql_add = "INSERT INTO studans (SubItems)VALUES("'" . $_REQUEST['Item'][$x] . "')";
             $q_add 	= mysql_query($sql_add);
        }
?>

please modify this.... :)

Whatever this is supposed to do, I'm not using a MySQL database, I'm just emailing the form.

 

 

I got this working:

$languages = implode(', ', $_POST['lang_studied']);

But in my email it just shows "Array".

 

 

And the radio choice is still not showing.

Link to comment
Share on other sites

joemamahunt

I'm going to give you the best advice possible for fixing a broken program:  Get more information.

1) Read carefully any error messages

2) If there are no error messages, add code to print error messages (such as echo()'ing mysql_error())

3) VERIFY your data.  Make sure the variables contain what you expect them to contain.  This prevents you from using arrays as strings, strings as numbers, etc.

 

As a continuation of #3, the best way to verify your data is to send it as output.  Here is a simple little function, that you can expand upon if you wish, to echo your data so that it's easy to read:

function debug_echo($val){
  $val = print_r($val, true);
  echo "<pre style='text-align: left;'>{$val}</pre>";
}

 

Add that to your script and at the very top do:

debug_echo($_POST);

 

What prints when you submit your form?

Link to comment
Share on other sites

This gets printed:

Array

(

)

 

 

I've checked the code too many times and it should be working fine to my understanding. Basically all I'm using is what I have quoted in my first post. I have a bunch of simple variables that just get posted, but they are not listed as they are unimportant and work as they should. (I've checked them all)

 

All in all, I'm just trying to email myself the form inputs and selections on submit, and the inputs get sent fine, but the radio and checkboxes do not.

Radio selection is not showing up anything, while currently the checkbox selections are just showing the word "Array".

Link to comment
Share on other sites

Got the checkboxes to work. Human error on my side. (forgot to switch the variable name) :-[

 

Got the radio buttons to work by deleting and re entering the quotation keys. I didn't change anything, just deleted and re typed in the following key for the name & values: "

Weird.

 

 

Thanks for all the help guys. :)

Link to comment
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.