K
K
Kirill Gorelov2015-09-28 14:05:02
PHP
Kirill Gorelov, 2015-09-28 14:05:02

Can't edit checkbox positions?

Hello.
There is a code:

include $_SERVER['DOCUMENT_ROOT']."/theme/assets/data/setting/setting.php";

function showRow($title = "", $description = "", $field = "", $class = "") {
  echo "<tr>
       <td class=\"col-xs-10 col-sm-6 col-md-7 {$class}\">{$title}<span >{$description}</span></td>
       <td class=\"col-xs-2 col-md-5 settingstd {$class}\">{$field}</td>
       </tr>";
}
  
function makeDropDown($options, $name, $selected) {
  $output = "<select class=\"uniform\" style=\"min-width:100px;\" name=\"$name\">\r\n";
  foreach ( $options as $value => $description ) {
    $output .= "<option value=\"$value\"";
    if( $selected == $value ) {
      $output .= " selected ";
    }
    $output .= ">$description</option>\n";
  }
  $output .= "</select>";
  return $output;
}

function makeCheckBox($name, $selected) {
  $selected = $selected ? "checked" : "";
  
  return "<input class=\"iButton-icons-tab\" type=\"checkbox\" name=\"$name\" value=\"\" {$selected}>";
}
function makeRadiokBox($name, $selected) {
  $selected = $selected ? "checked" : "";
  
  return "<input class=\"iButton-icons-tab\" type=\"radio\" name=\"$name\" value=\"1\" {$selected}>";
}

echo <<<HTML
          
            <div class="portlet-body form">
              <form action="setting.php?$=r1" method="post"class="form-horizontal" id="submit_form">
              
                <div class="form-wizard">
                  <div class="form-body">

                    <div class="tab-content">
                      <div class="tab-pane active" id="tab1">

                        <h3 class="block">Пароль и его востановление</h3>
                        <div class="form-group">
                          <label class="control-label col-md-3">Метрика от яндекса</label>
                          <div class="col-md-4">
HTML;
 showRow( $lang['yan'], $lang['yand'], "<textarea name=\"save_con[yan]\" size=20>{$setting['yan']}</textarea>", "white-line" );
 
 echo <<<HTML
                            
                            <span class="help-block">Метрика от яндекса</span>
                          </div>
                        </div>
                        <div class="form-group">
                          <label class="control-label col-md-3">Язык</label>
                          <div class="col-md-4">
HTML;
  showRow( $lang['vconf_flvpos'], $lang['vconf_flvposd'], makeDropDown( array ("left" => l, "center" => c, "right" => r ), "save_con[flv_watermark_pos]", "{$setting['flv_watermark_pos']}" ) );
  showRow( $lang['vconf_play'], $lang['vconf_playd'], makeCheckBox( "save_con[play]", "{$setting['play']}" ) );

showRow( $lang['title'], $lang['title'], "<input type=text class=\"form-control\" name=\"save_con[title]\" value=\"{$setting['title']}\" size=20>", "white-line" );
showRow( $lang['sconf_mailru'], $lang['sconf_mailru'], makeCheckBox( "save_con[mailru]", "{$setting['mailru']}" ) );
 // makeCheckBox( "save_con[play]", "{$setting['play']}"

  echo <<<HTML
                            <span class="help-block">Описание для поисковых систем</span>
                          </div>
                        </div>

                      </div>
                    </div>
                  </div>
                      </div>
                    </div>
                  



</table>


<div class="form-actions">


                          <input type="submit" class="btn default" name="save" value="Submit">
                          

</form>
</div>
HTML;
if ($_POST['save']){

$save_con = $_POST['save_con'];
  
  $find = array();
  $replace = array();
  
  $find[] = "'\r'";
  $replace[] = "";
  $find[] = "'\n'";
  $replace[] = "";
  
  $save_con = $save_con + $setting;
  
  $handler = fopen($_SERVER['DOCUMENT_ROOT']."/theme/assets/data/setting/setting.php", "w" );
  
  fwrite( $handler, "<?PHP \n\n//Videoplayers Configurations\n\n\$setting = array (\n\n" );
  foreach ( $save_con as $name => $value ) {
    
    $value = trim(strip_tags(stripslashes( $value )));
    $value = htmlspecialchars( $value, ENT_QUOTES, $setting['charset']);
    $value = preg_replace( $find, $replace, $value );
      
    $name = trim(strip_tags(stripslashes( $name )));
    $name = htmlspecialchars( $name, ENT_QUOTES, $setting['charset'] );
    $name = preg_replace( $find, $replace, $name );
    
    $value = str_replace( "$", "&#036;", $value );
    $value = str_replace( "{", "&#123;", $value );
    $value = str_replace( "}", "&#125;", $value );
    if( $name != "flv_watermark_al") $value = str_replace( ".", "", $value );
    $value = str_replace( '/', "", $value );
    $value = str_replace( chr(92), "", $value );
    $value = str_replace( chr(0), "", $value );
    $value = str_replace( '(', "", $value );
    $value = str_replace( ')', "", $value );
    $value = str_ireplace( "base64_decode", "base64_dec&#111;de", $value );
    
    $name = str_replace( "$", "&#036;", $name );
    $name = str_replace( "{", "&#123;", $name );
    $name = str_replace( "}", "&#125;", $name );
    $name = str_replace( ".", "", $name );
    $name = str_replace( '/', "", $name );
    $name = str_replace( chr(92), "", $name );
    $name = str_replace( chr(0), "", $name );
    $name = str_replace( '(', "", $name );
    $name = str_replace( ')', "", $name );
    $name = str_ireplace( "base64_decode", "base64_dec&#111;de", $name );
    
    fwrite( $handler, "'{$name}' => '{$value}',\n\n" );
  
  }
  fwrite( $handler, ");\n\n?>" );
  fclose( $handler );
  echo '<script type="text/javascript">'; 
echo 'window.location.href="'.$url.'";'; 
echo '</script>'; 

}
   ?>

It writes some data to a php file as an array. In this form
<?PHP 
$setting = array (
'yan' => '',
'play' => '1',
'mailru' => '1',
);
?>

So.
Problem. This code. He writes checkbox. Position one or zero.
showRow( $lang['vconf_play'], $lang['vconf_playd'], makeCheckBox( "save_con[play]", "{$setting['play']}" ) );
Position one(1) he writes. If the checkbox is unchecked, the zero(0) position is not recorded.
I can't figure out what the problem is. Seems like it's supposed to!
Please tell me why?
Or if there is another way to write it, it will also be useful!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Teterin, 2015-11-22
@errogaht

if the checkbox is not set, then it is not transmitted at all, as if it does not exist. I think so.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question