1

I have got an array with strings and I want to create a form with checkboxes, where each string has it´s own checkbox. The function $Service->read_command_cfg(); returns the correct array.

My PHP Code is as follows:

<form action="host_add.php" method = "post" >
<?PHP
include_once('service.php');
echo'Services:';
if (!empty($_POST['host_select']))
{
  $Service = new Service;
  $array_command_name_new = $Service->read_command_cfg();
}

foreach($array_command_name_new as $key=>$value)
{
  echo'<p><input type="checkbox" name="'.$value.'" value="'.$value.'/>' .$value. '</p>';    
}
?>
</form>

I got the following HTML-Output:

<form action="host_add.php" method = "post" >
Services:<p><input type="checkbox" name="command_name   notify-host" value="command_name notify-host/>command_name  notify-host</p><p><input type="checkbox" name="command_name notify-service" value="command_name notify-service/>command_name    notify-service</p>
</form>

On the Website I got only one checkbutton without text.

3
  • Everything looks fine. Your html shows two checkboxes. I don't think I understand the problem. Commented Jul 22, 2014 at 9:06
  • 4
    You're missing a quote from value="' . $value . '" Commented Jul 22, 2014 at 9:06
  • Nevermind, I think @billyonecan just nailed it. Commented Jul 22, 2014 at 9:07

1 Answer 1

1

There is syntax error -

foreach($array_command_name_new as $key=>$value)
{
    echo "<p><input type='checkbox' name='$value' value='$value' />$value</p>";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.