Jump to content
Server Maintenance This Week. ×

PHP checkboxes & web question


This topic is 2349 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have created an event registration site using FM server advanced 9 and the php site assistant. I am now styling the registration page and have probably a silly question.

How do I get the 'Yes' from my checkboxes to not appear on the web? I am having registrants use checkboxes to list their employment interests and experience.

Thanks.

Link to comment
Share on other sites

  • 6 months later...

I'm having the same problem except my checkboxes have a "1" after each one of them (my value list consists of only the "1" value).

I suspect it has everything to do with this function, found in fmview.php:

function getInputChoices($type, $valuelist, $fieldvalue, $fieldName) {

	$selected = "";

	$fieldValueArray = explode(" ", str_replace("n"," ", $fieldvalue));

	

	foreach ($valuelist as $eachvalue) {

		if (in_array(trim($eachvalue), $fieldValueArray)){

			$selected = " checked";

		}else{

			$selected = "";

		}

		if ($type == "checkbox"){

			echo "$eachvalue";

		}else{

			echo "$eachvalue";

		}

	}

}

Link to comment
Share on other sites

Well, I guess the easiest way to do it would be to modify the function (which is seriously messed up by the way)...


function getInputChoices($type, $valuelist, $fieldvalue, $fieldName, $echoValue=true) {

	$selected = "";

	$valuedisplay="";

	$fieldValueArray = explode(" ", str_replace("n"," ", $fieldvalue));

	

	foreach ($valuelist as $eachvalue) {

		if (in_array(trim($eachvalue), $fieldValueArray)) $selected = " checked";

		else $selected = "";



		if( $echoValue ) $valuedisplay = $eachValue;

		if ($type == "checkbox"){

			echo "$valuedisplay";

		}else{

			echo "$valuedisplay";

		}

	}

}

Then, wherever you see a call to getInputChoices function after the last parameter that's in there by default, add: ,false e.g.

getInputChoices("checkbox", "somelist", "somevalue", "someFieldName", false);

Link to comment
Share on other sites

Ahh, thanks for the tip Genx, but I tried that function and got a error saying "Undefined variable: eachValue". I think I fixed that by just including the line

$eachValue = "";

directly after the other variables being set as blank, and it almost works, except that now my checkbox looks like a regular text field (pre-populated with a "1").

So, I think I figured out a better way to get rid of the value lists… this method would just require you to designate this:

getInputChoices("checkbox_no_label", "somelist", "somevalue", "someFieldName");

instead of this:

getInputChoices("checkbox", "somelist", "somevalue", "someFieldName");

As you can see from the code below (compared to my original post above), I had to change the echoed html code to actually spell out 'checkbox' instead of simply calling '$type'.

function getInputChoices($type, $valuelist, $fieldvalue, $fieldName) {

	$selected = "";

	$fieldValueArray = explode(" ", str_replace("n"," ", $fieldvalue));

	

	foreach ($valuelist as $eachvalue) {

		if (in_array(trim($eachvalue), $fieldValueArray)){

			$selected = " checked";

		}else{

			$selected = "";

		}

		if ($type == "checkbox_no_label"){

			echo "";

		}else if ($type == "checkbox"){

			echo "$eachvalue";

		}else{

			echo "$eachvalue";

		}

	}

}

Link to comment
Share on other sites

Sorry typo:


function getInputChoices($type, $valuelist, $fieldvalue, $fieldName, $echoValue=true) {

	$selected = "";

	$valuedisplay="";

	$fieldValueArray = explode(" ", str_replace("n"," ", $fieldvalue));

	

	foreach ($valuelist as $eachvalue) {

		if (in_array(trim($eachvalue), $fieldValueArray)) $selected = " checked";

		else $selected = "";



		if( $echoValue ) $valuedisplay = $eachvalue;

		if ($type == "checkbox"){

			echo "$valuedisplay";

		}else{

			echo "$valuedisplay";

		}

	}

}





Link to comment
Share on other sites

  • 8 years later...

If you are using booleans, e.g. Yes/No,  since 

1. Code is processed sequentially

2. Only the last 'checked' answer is used. 

Therefore put the 'non' answer first but hide it and leave it always checked. The positive answer comes second. 

<?php $fieldName = 'Privacy_Agreement';?>
<?php $fieldValue = $record->getField($fieldName, 0) ; ?>
<input type='hidden' name='<?php echo (getFieldFormName($fieldName, 0, $record, true, 'EDITTEXT', 'number')) ;?>' value='No' checked>
<input type='checkbox' name='<?php echo (getFieldFormName($fieldName, 0, $record, true, 'EDITTEXT', 'number')-1) ;?>' value='Yes'  <?php if ($fieldValue == 'Yes'){ echo 'checked'; } ?>>

 You can insert whatever text before or after.  This works for me- I was searching for how to make a single checkbox work.

Link to comment
Share on other sites

This topic is 2349 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.