Metin içine checkbox veri koyarak

4 Cevap php

Birden fazla onay kutularını almak ve ilgili id ​​/ isim otomatik bir un-düzenlenebilir metin kutusu / metin alanına doldurmak için bir yolu var mı?

Önerilerden biri olarak başına ... Ben genişletilmesi ve açıklığa kavuşturulması duyuyorum.

I have several checkboxes that I want saved into the SAME db field...at the same time. So, since I'm a novice programmer where php/sql (and advanced languages) are concerned, I figured the easiest and quickest way is to have the check box ID's inserted into a single text box then take that dynamic info from the text box into the db field, since this information has to correspond w/ other textboxes on a single transaction. So:

Name: textbox
ID#: textbox
Other Info: textbox
Check1: X
Check2: X
Check3:

and the db would all have the lines there...help...I'm confused.

4 Cevap

Burada henüz yorum yapamam, ama senin yorumuna cevap olarak "bu şekilde denedim, ve onu ...", aaron, sen print_r komutu kötüye ediyoruz. print_r metin biçiminde dizi değişkenlerin veri / yapısını damping için, sen "" = değere bir html giriş formu bölümünde bu metni dökümü olamaz. Ne gerçekten bu yaparak gerçekleştirerek konum oluşturulan html bu gibi bakarak sona erecek:

<input name="Extrasfield" type="text" id="extras" value='Array
(
    0 => 'adam',
    1 => 'nick',
    2 => 'simon'
 )' disabled>

Eğer metin kutusu "adam, nick, simon" gibi bir şey içermesini istiyorsanız, böyle bir şey print_r değiştirmeniz gerekir:

 implode(', ', $Extras)

',' bit kullanmak istediğiniz ayırıcı olduğu.

Tabii. Sen jQuery.each onay kutularını döngü kullanın ve metin kutusu / alanına id / NME ekleyebilirsiniz.

Birden fazla onay kutusu öğeleri ile bir form varsa:

<input type="checkbox" name="people[]" value="adam" />
<input type="checkbox" name="people[]" value="nick" />
<input type="checkbox" name="people[]" value="simon" />

Ekleme [] adı php dizideki tüm değerleri koyar sonra. Daha sonra şöyle verilere erişebilir:

$people = $_POST['people'];
print_r($people); // prints array('adam','nick','simon');

Ilgili onay kutusunun işaretli olup olmadığını dizisi değerler sadece mevcut olacaktır.

Yukarıdaki sorunun cevabı da anlaşılacağı gibi, JQuery kullanın. İşte bazı kullanılabilir kod,

$("#id :checkbox").click(function() { 

    var values = [];

    $('#id :checked').each(function() {
        values.push($(this).val());
    });

    $("#id").val(values)
});

İyi şanslar!