Jump to content

Very Strange - Multiple Checkboxes


Looktrne
Go to solution Solved by Looktrne,

Recommended Posts

I am transfering a site from PHP 5.2 to PHP 5.4

 

now the checkboxes are not being passed to PHP

 

the html looks like this

<form action="index.php?page=matchfinder&action=enable" method=post>
<tr>
<td width=50%><input value=1 type=checkbox name=search_marital_status[1] checked> Single - Never Married</td>
<td width=50%><input value=1 type=checkbox name=search_marital_status[2]> Married</td>
<td width=50%><input value=1 type=checkbox name=search_marital_status[3] checked> Divorced</td>
</tr>
<input type="submit" value="Update Settings">
</form>

on the PHP page that it posts to I don't receive the $search_marital_status data.

if I change "search_marital_status[1]" to "search_marital_status1" it can read the variable

my question is why would this work normally on 5.2 but not 5.4?

any suggestions it saves values into a database field names "marital_status" and would look like this if all 3 were checked "|1|3|"

Why would this be broken in 5.4? any thoughts? it doesn't like the checkbox variables using [1]  [2]  on the end

thanks for any insite

Paul

Link to comment
Share on other sites

I believe it may be using register globals but have seen it work on sites with it disabled also

 

I pretty much need a variable to equal

$search_marital_status = "|1|3|5|";   if I selected all 3 boxes

is there a simple way to re-write the buttons to accomplish this?

 

thanks

Paul

Link to comment
Share on other sites

That is possible if your check boxes values are set, using

<td width=50%><input value=1 type=checkbox name=search_marital_status[1] checked> Single - Never Married</td>
<td width=50%><input value=3 type=checkbox name=search_marital_status[2]> Married</td>
<td width=50%><input value=5 type=checkbox name=search_marital_status[3] checked> Divorced</td>

I assume

1 is Single

3 is Married

5 is Divorced

 

To get the selected values separated by a pipe, you'd do

$search_martial_status = implode('|', $_POST['search_martial_status']);
Edited by Ch0cu3r
Link to comment
Share on other sites

First, I would recommend changing the values for your checkboxes.

<td width=50%><input value=1 type=checkbox name=search_marital_status[] checked> Single - Never Married</td>
<td width=50%><input value=3 type=checkbox name=search_marital_status[]> Married</td>
<td width=50%><input value=5 type=checkbox name=search_marital_status[] checked> Divorced</td>
When the form is submitted, you can loop through the $_POST['search_marital_status'] variable to get the values.
Link to comment
Share on other sites

Seems Register Globals OFF is ok

 

but Safe_mode should be disabled according to the script

 

I know Safe_mode is no longer existing.... any thoughts on how this may effect my Form?

 

The form most likely isn't the problem. The problem more likely resides in the script which processes the form submission. If you're looking for answers, you'll need to post that code.

Link to comment
Share on other sites

The form most likely isn't the problem. The problem more likely resides in the script which processes the form submission. If you're looking for answers, you'll need to post that code.

 

Here is the page that receives it... all it does is write the marital_status variable into the database.

 

When I use a variable without [] or [1] in the button it passes the data with [] or [1] I get nothing... 

 

I just need a simple way to rewrite the button code so I can then write to database as |1|2|3 as explained above.

 

thanks for any thoughts

 

<?

    if($action == disable)
    {
        q("UPDATE dt_members SET matchfinder='0' WHERE id='$fMember[id]'");
        $fMember[ matchfinder ] = 0;
    }

    if($action == enable)
    {
        $error = "";

        if((int)$age_from <= 0 || (int)$age_to <= 0 || $age_from > $age_to || $age_to > 90)
        {
            $error = "Invalid age from and age to entered! Please try again.";
       	}

        if($error == "")
        {
            q("UPDATE dt_members SET looking_for='$looking_for' WHERE id='$fMember[id]'");
            q("UPDATE dt_members SET matchfinder='1' WHERE id='$fMember[id]'");

            $fMember[ matchfinder ] = 1;
            $fMember[ looking_for ] = $looking_for;

            $f_mf = f(q("SELECT * FROM dt_matchfinder WHERE member_id='$fMember[id]'"));
            
            $fields = array(
	                "search_marital_status",
	                "search_body_type",
	                "search_hair_color",
	                "search_eye_color",
						 "search_race",
	                "search_religion",
	                "search_education",
	                "search_occupation",
	                "search_food"
                );

            foreach($fields as $field_name)
			{
				if(isset($$field_name))
				{
					$temp = "|";
					foreach($$field_name as $field_key=>$field_value)
					{
					    if($field_value) $temp .= $field_key."|";
					}
					$$field_name = $temp;
				}
			}

            if($f_mf == "")
            {
                q("INSERT INTO dt_matchfinder(member_id, age_from, age_to,country,race,marital_status,education,hair_color,eye_color,food,occupation,state,city) VALUES('$fMember[id]', '$age_from','$age_to','$search_country','$search_race','$search_marital_status','$search_education','$search_hair_color','$search_eye_color','$search_food','$search_occupation','$state','$city')");
            }
            else
            {
                q("UPDATE dt_matchfinder SET age_from='$age_from' WHERE id='$f_mf[id]'");
                q("UPDATE dt_matchfinder SET age_to='$age_to' WHERE id='$f_mf[id]'");

				// new code for webDate v1.3.5
            	
				q("UPDATE dt_matchfinder SET country='$search_country' WHERE id='$f_mf[id]'");
				q("UPDATE dt_matchfinder SET state='$state' WHERE id='$f_mf[id]'");
				q("UPDATE dt_matchfinder SET city='$city' WHERE id='$f_mf[id]'");
				
				q("UPDATE dt_matchfinder SET marital_status='$search_marital_status' WHERE id='$f_mf[id]'");
				q("UPDATE dt_matchfinder SET body_type='$search_body_type' WHERE id='$f_mf[id]'");
				q("UPDATE dt_matchfinder SET hair_color='$search_hair_color' WHERE id='$f_mf[id]'");
				q("UPDATE dt_matchfinder SET eye_color='$search_eye_color' WHERE id='$f_mf[id]'");
				q("UPDATE dt_matchfinder SET race='$search_race' WHERE id='$f_mf[id]'");
				q("UPDATE dt_matchfinder SET religion='$search_religion' WHERE id='$f_mf[id]'");
				q("UPDATE dt_matchfinder SET education='$search_education' WHERE id='$f_mf[id]'");
				q("UPDATE dt_matchfinder SET occupation='$search_occupation' WHERE id='$f_mf[id]'");
				q("UPDATE dt_matchfinder SET food='$search_food' WHERE id='$f_mf[id]'");
				
				
				
			}
        }
    }

    $f_mf = f(q("SELECT * FROM dt_matchfinder WHERE member_id='$fMember[id]'"));

    if($f_mf != "" && $fMember[ matchfinder ] == 1)
    {
        $enabled = 1;
    }
    
    if($enabled)
    { 
    	$matchfinder_status = "enabled";
    	$matchfinder_submit = "Update Settings";	
		$matchfinder_disable = '<input type="button" value="'."Disable Matchfinder".'" OnClick="window.location.href='."'index.php?page=matchfinder&action=disable'".'">';
    }
    else {
    	$matchfinder_status = "disabled";
    	$matchfinder_submit = "Enable Matchfinder";
    }
    
	if ($error) {
   		$matchfinder_error = '<tr>';
    	$matchfinder_error .= '<td class="trtc" height="25" colspan="2">  ';
    	$matchfinder_error .= '<font color=C00000>'.$error.'</font>';
    	$matchfinder_error .= '</td>';
    	$matchfinder_error .= '</tr>';
   	}
   	
   	$looking_for = $fMember[ looking_for ];
   	$matchfinder_looking_for = sysGetValSelect(looking_for, dt_genders);
 
   	$age_from=$f_mf[ age_from ];
	$matchfinder_age_from = sysGetNumberSelect(age_from, 18, 55, 0);

	$age_to=$f_mf[ age_to ];
	if($age_to=="")$age_to=35;
	$matchfinder_age_to = sysGetNumberSelect(age_to, 18, 80, 0); 
	
	$search_country=$f_mf[ country ];
	$matchfinder_search_country = sysGetSelect(search_country, dt_countries,0,$search_country); 

	$matchfinder_search_state = "";
	if(!$no_state) {
		$state = $f_mf[ state ];
		if($state_dropdown)
		{ 
			$matchfinder_search_state_select = sysGetValSelect(state, dt_states,0,$state);
		}
		else 
		{
			$matchfinder_search_state_select = '<input type=text name=state value="'.$state.'">';
		}
		$matchfinder_search_state = parseVariables("templates/matchfinder_state.html",0);
	}
	
	$matchfinder_search_city = $f_mf[ city ];
	
	$temp = explode("|", $f_mf[marital_status]);
	$search_marital_status = "";
	foreach($temp as $i) $search_marital_status[$i] = 1;
	$matchfinder_marital_status = sysGetCheckboxesMatchfinder("search_marital_status", "dt_marital_status",0);
	
	$temp = explode("|", $f_mf[body_type]);
	$search_body_type = "";
	foreach($temp as $i) $search_body_type[$i] = 1;
	$matchfinder_body_types = sysGetCheckboxesMatchfinder("search_body_type", "dt_body_types",0);
	
	$temp = explode("|", $f_mf[hair_color]);
	$search_hair_color = "";
	foreach($temp as $i) $search_hair_color[$i] = 1;
	$matchfinder_hair_colors = sysGetCheckboxesMatchfinder("search_hair_color", "dt_hair_colors",0);
	
	$search_eye_color = "";
	$temp = explode("|", $f_mf[eye_color]);
	foreach($temp as $i) $search_eye_color[$i] = 1;
	$matchfinder_eye_colors = sysGetCheckboxesMatchfinder("search_eye_color", "dt_eye_colors",0);
	
	$search_race = "";
	$temp = explode("|", $f_mf[race]);
	foreach($temp as $i) $search_race[$i] = 1;
	$matchfinder_race = sysGetCheckboxesMatchfinder("search_race", "dt_races",0);
	
	$search_religion = "";
	$temp = explode("|", $f_mf[religion]);
	foreach($temp as $i) $search_religion[$i] = 1;
	$matchfinder_religion = sysGetCheckboxesMatchfinder("search_religion", "dt_religions",0);
				  
	$search_education = "";			
	$temp = explode("|", $f_mf[education]);
	foreach($temp as $i) $search_education[$i] = 1;
	$matchfinder_education = sysGetCheckboxesMatchfinder("search_education", "dt_educations",0);
	 
	$search_occupation = "";
	$temp = explode("|", $f_mf[occupation]);
	foreach($temp as $i) $search_occupation[$i] = 1;
	$matchfinder_occupation = sysGetCheckboxesMatchfinder("search_occupation", "dt_occupations",0);
	
	$search_food = "";
	$temp = explode("|", $f_mf[food]);
	foreach($temp as $i) $search_food[$i] = 1;
	$matchfinder_food = sysGetCheckboxesMatchfinder("search_food", "dt_food",0);

    parseVariables("templates/matchfinder.html");
?>

Paul

 

Link to comment
Share on other sites

 

That is possible if your check boxes values are set, using

<td width=50%><input value=1 type=checkbox name=search_marital_status[1] checked> Single - Never Married</td>
<td width=50%><input value=3 type=checkbox name=search_marital_status[2]> Married</td>
<td width=50%><input value=5 type=checkbox name=search_marital_status[3] checked> Divorced</td>

I assume

1 is Single

3 is Married

5 is Divorced

 

To get the selected values separated by a pipe, you'd do

$search_martial_status = implode('|', $_POST['search_martial_status']);

I tried this

 

<td width=50%><input value=1 type=checkbox name=search_marital_status[1] checked> Single - Never Married</td>
<td width=50%><input value=3 type=checkbox name=search_marital_status[2]> Married</td>
<td width=50%><input value=5 type=checkbox name=search_marital_status[3] checked> Divorced</td>
$search_martial_status = implode('|', $_POST['search_martial_status']);

echo "Marital Status Is:".$search_martial_status."<br>"

I get nothing out?

 

if I change search_marital_status[1] to search_marital_status then I would get data but it seems it won't eccept array?

 

this is just weird it works on some servers and not others.

 

is there a simple way to re-write? the code is old I just want to re-write this part

 

Paul

Link to comment
Share on other sites

You need to declare from both post and get data in your case, you have been relying on register_globals = ON !

 

In your form, you have

<form action="test.php?page=matchfinder&action=enable" method=post>

In order to get "page" and "action" status :

$page = $_GET['page'];
$action = $_GET['action'];
// now you can use them ....

Then handle posted values from form

foreach($_POST['search_marital_status'] as $key => $val){
  $status[] = $key; // you need key from your form names -> name[val] thing
}

$search_martial_status = implode('|',$status);
Link to comment
Share on other sites

  • Solution

I found a function that was killing the check boxes

 

this function was being called and killing checkboxes from working

 

//$type_rs_to_register = array( "GET", "POST", "COOKIE", "FILES", "SESSION", "SERVER" );
if ( !get_magic_quotes_gpc( ) )
{
    foreach ( $type_rs_to_register as $type_r )
    {
        if ( !( 0 < @count( ${ "_".$type_r } ) ) )
        {
            continue;
        }
        while ( list( $key, $value ) = each( ${ "_".$type_r } ) )
        {
            ${ "_".$type_r }[$key] = addslashes( $value );
        }
    }
}
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.