0

I have the follow code, with checkboxes. Tried to do an array. I send these checkboxes to my mail-process file. How I do, that I only get these values, from these checkboxes, they are checked?

<div class="cpt-item four columns">
<div class="thumb-wrapper">
<img src="/assets/images/custom/bigb002.jpg" alt="The Big Buddha Temple">
</div>
<div class="cpt-detail">
<h2 class="cpt-title">The Big Buddha Temple</h2>
add this item<input type="checkbox" name="tmitem[0]" value="The Big Buddha Temple"></input>
</div>
</div>
<div class="cpt-item four columns">
<div class="thumb-wrapper">
<img src="/assets/images/custom/watplailaem002.jpg" alt="Wat Plai Leam">
</div>
<div class="cpt-detail">
<h2 class="cpt-title">Wat Plai Leam</h2>
add this item<input type="checkbox" name="tmitem[1]" value="Wat Plai Leam"></input>
</div>
</div>
<div class="cpt-item four columns">
<div class="thumb-wrapper">
<img src="/assets/images/custom/redwat001.jpg" alt="Red Temple Lamai">
</div>
<div class="cpt-detail">
<h2 class="cpt-title">Red Temple Lamai</h2>
add this item<input type="checkbox" name="tmitem[2]" value="Red Temple Lamai"></input>
</div>
</div>
<div class="cpt-item four columns">
<div class="thumb-wrapper">
<img src="/assets/images/custom/laemsor001.jpg" alt="Leam Sor Pagoda">
</div>
<div class="cpt-detail">
<h2 class="cpt-title">Leam Sor Pagoda</h2>
add this item<input type="checkbox" name="tmitem[3]" value="Leam Sor Pagoda"></input>
</div>
</div>
<div class="cpt-item four columns">
<div class="thumb-wrapper">
<img src="/assets/images/custom/mumonk001.jpg" alt="Mummified Monk">
</div>
<div class="cpt-detail">
<h2 class="cpt-title">Mummified Monk</h2>
add this item<input type="checkbox" name="tmitem[4]" value="Mummified Monk"></input>
</div>
</div>
<div class="cpt-item four columns">
<div class="thumb-wrapper">
<img src="/assets/images/custom/buddhapath001.jpg" alt="Buddha Footprint">
</div>
<div class="cpt-detail">
<h2 class="cpt-title">Buddha Footprint</h2>
add this item<input type="checkbox" name="tmitem[5]" value="Buddha Footprint"></input>
</div>
</div>

Edited by pritaeas: Moved to PHP

2
Contributors
5
Replies
17
Views
2 Years
Discussion Span
Last Post by Simon_4
0
if(!empty($_POST['tmitem'])){
    foreach($_POST['tmitem'] as $selected)
    {
        echo $selected."</br>";
    }
}
0

Hi

Yes, I had the same before too. But the problem, the real problem I have, it shows me ALL values from the checkboxes. And not only these - are checked.

2
//check below code, it is tested
<form action="#" method="post">
    <div class="cpt-item four columns">
    <div class="thumb-wrapper">
    <img src="/assets/images/custom/bigb002.jpg" alt="The Big Buddha Temple">
    </div>
    <div class="cpt-detail">
    <h2 class="cpt-title">The Big Buddha Temple</h2>
    add this item<input type="checkbox" name="tmitem[0]" value="The Big Buddha Temple"></input>
    </div>
    </div>
    <div class="cpt-item four columns">
    <div class="thumb-wrapper">
    <img src="/assets/images/custom/watplailaem002.jpg" alt="Wat Plai Leam">
    </div>
    <div class="cpt-detail">
    <h2 class="cpt-title">Wat Plai Leam</h2>
    add this item<input type="checkbox" name="tmitem[1]" value="Wat Plai Leam"></input>
    </div>
    </div>
    <div class="cpt-item four columns">
    <div class="thumb-wrapper">
    <img src="/assets/images/custom/redwat001.jpg" alt="Red Temple Lamai">
    </div>
    <div class="cpt-detail">
    <h2 class="cpt-title">Red Temple Lamai</h2>
    add this item<input type="checkbox" name="tmitem[2]" value="Red Temple Lamai"></input>
    </div>
    </div>
    <div class="cpt-item four columns">
    <div class="thumb-wrapper">
    <img src="/assets/images/custom/laemsor001.jpg" alt="Leam Sor Pagoda">
    </div>
    <div class="cpt-detail">
    <h2 class="cpt-title">Leam Sor Pagoda</h2>
    add this item<input type="checkbox" name="tmitem[3]" value="Leam Sor Pagoda"></input>
    </div>
    </div>
    <div class="cpt-item four columns">
    <div class="thumb-wrapper">
    <img src="/assets/images/custom/mumonk001.jpg" alt="Mummified Monk">
    </div>
    <div class="cpt-detail">
    <h2 class="cpt-title">Mummified Monk</h2>
    add this item<input type="checkbox" name="tmitem[4]" value="Mummified Monk"></input>
    </div>
    </div>
    <div class="cpt-item four columns">
    <div class="thumb-wrapper">
    <img src="/assets/images/custom/buddhapath001.jpg" alt="Buddha Footprint">
    </div>
    <div class="cpt-detail">
    <h2 class="cpt-title">Buddha Footprint</h2>
    add this item<input type="checkbox" name="tmitem[5]" value="Buddha Footprint"></input>
    </div>
    </div>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
if(isset($_POST['submit'])){//to run PHP script on submit
if(!empty($_POST['tmitem'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['tmitem'] as $selected){
echo $selected."</br>";
}
}
}
?>
0

So - I think - but I still do not know where the problem is, it is about all javascripts I use for the formhandling.
If I do it in a "normal way", without javascript, it works without any problem.

Somehow it 'blocked' the checkboxes as "checked".

And i prefer to use the "old" way - as i also can use phpmailer instead of mail (standart php).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.