duanhuilao0787 2015-08-27 11:51 采纳率: 100%
浏览 93

如何使用php获取所选文本框值的值

I have list of properties and i get the list of users who matched to my selection criteria.

I need to send mail to the selected users.

I am check all option to check every user.

and i have text box for every user to change the rent value.

And i selected some user and click on send i need to send mail with value in the textbox.

I want to get the selected text box value in to form submit code.

enter image description here

in the above image there is a checkbox for every property and checkbob to check all. and i have text box for the price .

when i click on send by selecting some properties i want to send a mail the posted rent value

Here is the sample code.

    while($tenant = mysqli_fetch_array($result))
        {
        echo '
        <tr>

            <td>
                <a href="property.php?id='.$pro['id'].'"><img src="'.(($pro['image_1']) ? $pro['image_1'] : 'images/placeholder.png').'" alt="" width="100"></a>
            </td>

            <td><a href="#">'.$name['name'].$tenant['tenant_id'].' </a><br> '.$pro['name'].'</td>

            <td><b>'.$tenant['lease_exp'].'</b><br><i>'.$pro['ready'].'</i></td>

            <td>'.$pro['type'].'</td>

            <td><div class="price"><strong>$</strong><span>'.$tenant['rent_from'].'-'.$tenant['rent_to'].'</span></div><br><br><input type="text" name="new_rent'.$i.'" value='.$pro['rent'].' class="form-control" style="width:30%;" ></td>

            <td>
                <input type="checkbox" name="rent[]" id="rent'.$i.'" value="'.$tenant['tenant_id'].'"> Send

            </td>
        </tr>
        ';
    }

    <script>
    $(document).ready(function() {
    $('#all').change(function(){
    var ckb_status = $("#all").prop('checked');
    $('input[type="checkbox"]').prop("checked", ckb_status );
    });
    });
    </script>

    if(isset($_POST['submit'])) {
      if(!empty($_POST['rent'])) {
          print_r($_POST);
        foreach($_POST['rent'] as $check) {

            $tenant_profile = "SELECT * FROM tenant where id=".$check;
            $prof = mysqli_query($link, $tenant_profile);
            $profile = mysqli_fetch_array($prof);



            //echo $tenant_profile;
            //echo "</br>";
            //echo $pro['name'];

            echo $_POST['new_rent'];echo "</br>";

            $to      = $profile['email'];
            $subject = 'Price Change Alert';
            $header = "From: ".ADMIN_EMAIL."
"; 
            $header.= "MIME-Version: 1.0
"; 
            $header.= "Content-Type: text/plain; charset=utf-8
"; 
            $header.= "X-Priority: 1
"; 
            $message = '' ;
            $message .= "<div><p>Dear User there is a price drop for the property
            <a href='".$_SERVER['SERVER_NAME']."/property.php?id=".$pro['id']."'>".$pro['name']."</a></p>
            <p>Owner offering you ".$_POST['new_rent'].". </p>
            <p>please contact the owner for the complete details. </p>
            <p>Owner email id:#</div>";

            $mail1 = mail($to, $subject, $message, $header);

            if($mail1) { echo 'mail sent successfully'; }


        }// foreach
      } //empty checkbox check
    else  { echo "Plase Check Any Result"; }
    }//submit
  • 写回答

2条回答 默认 最新

  • duanrongshi1544 2015-08-27 12:02
    关注
    Count how many checkbox are getting checked. 
    
    $rent=$_POST['rent']; // Changes Done
    $SelectedCheckbox=sizeof($rent); // Changes Done
    for($i=0;$i<$SelectedCheckbox;$i++)
    -----------------------------------------------------------------------
    <?
    while($tenant = mysqli_fetch_array($result))
            {?>
            <tr>
                <td>
                    <a href="property.php?id='.$pro['id'].'">
                            <img src="images/placeholder.png" alt="" width="100">
                    </a>
                </td>
                <td><a href="#"><?echo $name['name'].$tenant['tenant_id'];?></a><br><?echo $pro['name'];?></td>
                <td><b><?echo $tenant['lease_exp']?></b><br><i><?echo $pro['ready'];?></i></td>
                <td><?echo $pro['type'];?></td>
                <td>
                    <div class="price"><strong>$</strong><span><?echo $tenant['rent_from'].'-'.$tenant['rent_to'];?></span></div><br><br>
                    <input type="text" name="new_rent[]" value="<?echo $pro['rent']?>" class="form-control" style="width:30%;" ></td> //Changes Done
                <td>
                    <input type="checkbox" name="rent[]" id="rent'.$i.'" value="<?echo $tenant['tenant_id'];?>"> Send
                </td>
            </tr>
            <?}>
    
        <script>
        $(document).ready(function() {
        $('#all').change(function(){
        var ckb_status = $("#all").prop('checked');
        $('input[type="checkbox"]').prop("checked", ckb_status );
        });
        });
        </script>
    
        if(isset($_POST['submit'])) 
        {
          if(!empty($_POST['rent'])) 
          {
            print_r($_POST);
            $rent=$_POST['rent']; // Changes Done
            $SelectedCheckbox=sizeof($rent); // Changes Done
            for($i=0;$i<$SelectedCheckbox;$i++) // Changes Done
            {
                $tenant_profile = "SELECT * FROM tenant where id=".$check;
                $prof = mysqli_query($link, $tenant_profile);
                $profile = mysqli_fetch_array($prof);
    
                echo $_POST['new_rent'];echo "</br>";
    
                $NewRent=$new_rent[$i]; //Changes Done
    
                $to      = $profile['email'];
                $subject = 'Price Change Alert';
                $header = "From: ".ADMIN_EMAIL."
    "; 
                $header.= "MIME-Version: 1.0
    "; 
                $header.= "Content-Type: text/plain; charset=utf-8
    "; 
                $header.= "X-Priority: 1
    "; 
                $message = '' ;
                $message .= "<div><p>Dear User there is a price drop for the property
                <a href='".$_SERVER['SERVER_NAME']."/property.php?id=".$pro['id']."'>".$pro['name']."</a></p>
                <p>Owner offering you ".$NewRent.". </p>
                <p>please contact the owner for the complete details. </p>
                <p>Owner email id:#</div>";
    
                $mail1 = mail($to, $subject, $message, $header);
    
                if($mail1) { echo 'mail sent successfully'; }
    
    
            }// for
          } //empty checkbox check
        else  { echo "Plase Check Any Result"; }
        }//submit
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常