通过邮件发送表格中的复选框数据

时间:2014-05-22 05:48:49

标签: php html invalid-argument

我正在尝试通过表结构中的邮件发送选定的复选框数据,但收到以下错误:

implode(): Invalid arguments passed

static function mcontent($chkbox){
    $sql = "SELECT station,reach,language,rate FROM `radio_city` where chkid in (".implode(',', $chkbox).")";
    return DB::select($sql);
}

请帮忙。 谢谢 乔蒂

View1:通过邮件发送数据时使用

<input type="hidden" name="checkbox" id="checkbox" >
              <input type="hidden" name="hiddamount" id="hiddamount">
              <input type="email" name="email" id="email">&nbsp;&nbsp;
              <input type="submit" id="submit" class="button" style="box-shadow: 5px 5px 3px #888888;" value="Email Plan" onsubmit="return validateForm();checkbox();"/>

function checkbox(){
  if (document.myForm.checkbox.checked){
    document.getElementById("error").innerHTML = "";
    return true;
  }
  else {
    document.getElementById("error").innerHTML = "Select your Plans";
  }
}

View2:选择复选框

时使用
<td onchange="Process(this.options[this.selectedIndex].value)" class="chart_row" align="center" >
    <input type="checkbox" name="checkbox[<?php echo $i; ?>]" id="checkbox" value="<?php echo $chkid; ?>" data-price="<?php echo $total; ?>" onChange="updateTotal(this);">
</td>
<td id="station" class="chart_row" align="center"><?= $result->station ?></td>
<td id="reach" class="chart_row" align="center"><?= $result->reach ?></td>
<td id="language" class="chart_row" align="center"><?= $result->language ?></td>
<td id="rate" class="chart_row" align="center">Rs <?= $result->rate ?>/-</td>
<td id="duration" class="chart_row" align="center"><?= $duration ?></td>
<td id="frequency" class="chart_row" align="center"><?= $frequency ?></td>
<td id="hours" class="chart_row" align="center"><?= $hours ?></td>
<?php $totals += ($result->rate) * $duration * $frequency * $hours * $days/10; ?></div>
</tr>

控制器:

function mail() {
    $input = Input::get();
    if (isset($_GET['checkbox'])){
        $city = $_GET['city'];
        $duration = $_GET['duration'];
        $frequency = $_GET['frequency'];
        $hours = $_GET['hours'];
        $days = $_GET['days'];
        $total = $_GET['hiddamount'];
        $chkbox = $_GET['checkbox'];
        $mailrslt = Radio::mcontent($chkbox); 
        $cityname = Radio::getall($input);
        foreach($cityname as $cities){
            //modify table ans add css here if you want.
            $html_table ="<table><caption>City: ".$cities->city."</caption><thead style='color:A0A0A0'><th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Station</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Reach</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Language</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Rate</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Jingle Lenght</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Frequency</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Hours/Day</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Days/Week</th></thead><tbody style='color: #000000;'>";}
                //whole query result is here
                                foreach($mailrslt as $key=>$row) {
                                $html_table .= "<tr>";
                //Iterate your data for table data.
                                foreach($row as $key2=>$row2){                    
                                $html_table .= "<td width='200' align='center' class='tabledata'>" . $row2 . "</td>";
                                        }
                //Database data ends here
                                $html_table .= "<td width='200' align='center' class='tabledata'>" . $duration . "</td>";
                                $html_table .= "<td width='200' align='center' class='tabledata'>" . $frequency . "</td>";
                                $html_table .= "<td width='200' align='center' class='tabledata'>" . $hours . "</td>";
                                $html_table .= "<td width='200' align='center' class='tabledata'>" . $days . "</td>";
                                        } //table rows ends here for displaying data
                                $html_table .= "</tr></tbody></table>";
                //contact details and total calculation done here
                                $html_table .= "<p>The total negotiable cost for your activity is <b>Rs ".$total."/-</b></p><div float='right'></p><u><b>For Best Rates</b></u></br> Call: Samir-+919686595443</br>Email: samir@themediaant.com</p></div>";
                                $to = $input['email'];//user email id from form.
            $from = 'help@themediaant.com';//from email ID
            $subject = 'Self Help Radio Planner';//subject
            $totals = 0;

            $message = $html_table;//assigning html_table variable to message.
            $contact_enquiry = new ContactEnquiry;
            $contact_enquiry->email = $from;
            $contact_enquiry->message = $message;
            $contact_enquiry->save();
//final mail function goes here
            $mail = Mail::send('emails.media_option_assistance', ['msg' => $message], function ($msg) use ($from, $to, $subject) {
                $msg->from($from, 'The Media Ant');
                $msg->to($to)->subject($subject);//->cc('servicing@themediaant.com');
            });
        //after successful mail redirect user to same page.
            return Redirect::to('/radio-plan/radioplan')->with('message','<b>Congratulations! You have succesfully sent the email');
    }       

}

型号:

static function mcontent($chkbox){
    $sql = "SELECT station,reach,language,rate FROM `radio_city` where chkid in (".implode(',', $chkbox).")";
    return DB::select($sql);
}

1 个答案:

答案 0 :(得分:0)

你的问题在这里

$chkbox = $_GET['checkbox'];
$mailrslt = Radio::mcontent($chkbox); 

implode需要第二个参数(或第一个参数,如果只提供一个参数)为array。您向mcontent提供了从输入中获得的string。因此,当您在implode内触及mcontent时,您正试图将string转换为string

因此,您必须创建一个array,其中包含一个或多个要传递给您的函数的变量,或者从函数中删除implode

我会尝试提供更多帮助,但老实说,我不会从你的代码中理解太多,这将是一个猜谜游戏。