이것은 WordPress의 플러그인입니다.데이터베이스에 다른 이름으로 입력 배열을 저장하십시오.
그래서 새 항목이 만들어 질 때 생성되는 숨겨진 입력 체크 상자가 있습니다. 이 항목은 슬라이딩 토글 (확인란)을 사용하여 켜거나 끌 수 있습니다. 배열이 게시되고처럼
즉 var_dump($_POST)
를 사용하는 경우에 일부 항목을 돌려 테스트 한 후 온/오프가 보인다 :
array (size=3)
'new_filter' => string '' (length=0)
'dp_show_filter_15' => string 'yes' (length=3)
'dp_show_filter_16' => string 'yes' (length=3)
하지만 항목이 돌아올 수없는 아무것도, yes로 설정되어있는 경우에만 사용할 수 있습니다.
덤프에 업데이트 된 배열이 표시 되더라도 Firebug에서는 값이 데이터베이스에 게시되지 않고 입력 값이 비어 있습니다.
여기 내 PHP 코드입니다 :
나는 그것이name="dp_show_filter"
대신
name="dp_show_filter_15"
을 예전처럼 입력 이름으로 ID를 추가하지만 원인이 모든 항목이 나는 자연스럽게 업데이트 할 때이 문제가 도입
/*------------------------------------------*/
/* Check if the filter is active or not */
/*------------------------------------------*/
$settings="select * from wp_dp_settings";
$filters=$wpdb->get_results($settings,ARRAY_A);
/*------------------------------------------*/
/* We'll use this to save active states */
/*------------------------------------------*/
if($_POST){
${active}=isset($_POST["dp_show_filter_[$i]"]);
var_dump($_POST);
$update="UPDATE wp_dp_settings SET active_filter = '".$active."' WHERE id";
//die($qry);
$ok=$wpdb->query($update);
if($ok==0)
{
echo mysql_error();
}
else
{
header("Location: admin.php?page=profolio_theme");
/** Just lettin you know that there was a successful save **/
echo "<div class='updated settings-error' id='setting-error-settings_updated'>
<p><strong>Active State Saved.</strong></p></div>";
}
}
?>
<td><label for="new_filter">Create a New Filter :<span class="tip">Must be one word</span></label></td>
<td><input type="text" name="new_filter" id="new_filter"/></td>
<td>
</tr>
<?php $object = new stdClass(); ?>
<?php foreach($filters as $key => $value) {
?>
<tr>
<td><label for="show_filter">Show <?php echo $object->$key = $value['filter']; ?> Filter</label></td>
<td><input type="checkbox" id="show_filter_<?php echo $object->$key = $value['id']; ?>" <?php //if ($row['active_filter'] === 'yes') { ?>checked="checked"<?php //} ?> name="dp_show_filter_<?php echo $object->$key = $value['id']; ?>" value="<?php echo $object->$key = $value['active_filter']; ?>"/><?php echo $object->$key = $value['active_filter']; ?></td>
<td><a class="button-primary" href="?page=profolio_theme&del=<?php echo $object->$key = $value['id'];?>">Delete</a></td>
</tr>
<?php
$i++;
}
?>
내 자바 스크립트에서 입력 이름을 참조하고 있었다.
당신은 도움이된다면 것을에서 좀 걸릴 수 있습니다 :
jQuery(document).ready(function(e) {
var $ = jQuery.noConflict();
$i = 0;
customCheckbox = $('.dp_wrap input[type="checkbox"]');
values = [];
return customCheckbox.each(function(i) {
// the dynamic id
var id = parseInt(this.id.replace("show_filter_", ""));
var showFilter = $("#show_filter_" + id);
// the element
var el = this;
// Hide checkbox
$(this).hide();
// Replace element
var rep = $('<a href="#"><span></span></a>').addClass('dp-checkbox').insertAfter(this);
// default state
if($(showFilter[i]).val() === 'yes'){
$(showFilter).prop('checked', true);
$(rep).removeClass('off').addClass('on');
} else {
$(showFilter).prop('checked', false);
$(rep).removeClass('on').addClass('off');
}
if($(this).is(':checked')) {
$(rep).addClass('on');
} else {
$(rep).addClass('off');
}
// Click event
$(rep).click(function(e) {
e.preventDefault();
if($(el).is(':checked')) {
values.push($(showFilter).val('no'), ++$i);
$(el).prop('checked', false);
$(rep).removeClass('on').addClass('off');
} else {
values.push($(showFilter).val('yes'), ++$i);
$(el).prop('checked', true);
$(rep).removeClass('off').addClass('on');
}
});
});
});
을 그래서 예/아니오,이 값이 데이터베이스에 게시해야합니다 체크 박스 값을, 온/오프 항목을 켜집니다. 참고 : 내가 스위치를 켜거나 끌 때 Firebug에서 개별적으로 yes/no로 변경되는 값을 알 수 있습니다. 따라서 자바 스크립트가 작동 중임을 알 수 있습니다.
모든 도움을 주시면 감사하겠습니다.
$ _POST의 값은, 어쩌면 당신은 아니오/예와 라디오 버튼이 필요하지 않은 선택을 해제 ckeckbox? –
예가 선택된 경우에도 값이 전혀 게시되지 않습니다. ID를 입력 이름에서 제거하면 DB에 저장되지만 선택한 항목 대신 모든 ID에 대해 ID가 설정됩니다. –