Passing input type file through ajax - php

So I am trying to pass a file through Ajax along with other data in the form. Every data except the file is getting passed. I am sending an email with all the data using php. I am new to Ajax and tried many ways. But still not sure where I am going wrong.
So here is my jQuery code
$(document).ready(function(){
$("#submitbtn").click(function(){
var uname = $("#uname").val();
var uemail= $("#uemail").val();
var subject= $("#subject").val();
var resume= $('input[type=file]').val();
var message= $("#message").val();
if(uname == '')
{
$("#errormsgs1").html("Please Enter Name");
$("#uname").css("border","1px solid #f00");
$("#uname").focus();
return false;
}
if(uemail == '')
{
$("#errormsgs2").html("Please Enter Email");
$("#uemail").css("border","1px solid #f00");
$("#uemail").focus();
return false;
}
if(subject == '')
{
$("#errormsgs3").html("Please Enter Subject");
$("#subject").css("border","1px solid #f00");
$("#subject").focus();
return false;
}
if(resume == '')
{
$("#errormsgs4").html("Please Enter Your Resume");
$("#resume").css("border","1px solid #f00");
$("#resume").focus();
return false;
}
if(message == '')
{
$("#errormsgs5").html("Please Enter Message");
$("#message").css("border","1px solid #f00");
$("#message").focus();
return false;
}
$("form#data").submit(function(){
var formData = new FormData(this);
$.ajax({
url: mycareer.php,
type: 'POST',
data: formData,
async: false,
success: function (data) {
alert(data)
},
cache: false,
contentType: false,
processData: false
});
return false;
});
Below is the mycareer.php file
<?php
$uname = $_POST['uname'];
print_r($uname);
$uemail = $_POST['uemail'];
print_r($uemail);
//$subject = $_POST['subject'];
$resume = $_FILES['resume'];
print_r($resume );
$message = $_POST['message'];
print_r($message );
if($uname !='' && $uemail !='')
{
$to = 'sayantan.m#gmail.in';
$subject = "My Career";
$message ='<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<title>Mycareer.in</title>
<style type="text/css">
div, p, a, li, td {
-webkit-text-size-adjust:none;
}
.ReadMsgBody {
width: 100%;
background-color: #d1d1d1;
}
.ExternalClass {
width: 100%;
background-color: #d1d1d1;
line-height:100%;
}
body {
width: 100%;
height: 100%;
background-color: #d1d1d1;
margin:0;
padding:0;
-webkit-font-smoothing: antialiased;
-webkit-text-size-adjust:100%;
}
html {
width: 100%;
}
img {
-ms-interpolation-mode:bicubic;
}
table[class=full] {
padding:0 !important;
border:none !important;
}
table td img[class=imgresponsive] {
width:100% !important;
height:auto !important;
display:block !important;
}
#media only screen and (max-width: 800px) {
body {
width:auto!important;
}
table[class=full] {
width:100%!important;
}
table[class=devicewidth] {
width:100% !important;
padding-left:20px !important;
padding-right: 20px!important;
}
table td img.responsiveimg {
width:100% !important;
height:auto !important;
display:block !important;
}
}
#media only screen and (max-width: 640px) {
table[class=devicewidth] {
width:100% !important;
}
table[class=inner] {
width:100%!important;
text-align: center!important;
clear: both;
}
table td a[class=top-button] {
width:160px !important;
font-size:14px !important;
line-height:37px !important;
}
table td[class=readmore-button] {
text-align:center !important;
}
table td[class=readmore-button] a {
float:none !important;
display:inline-block !important;
}
.hide {
display:none !important;
}
table td[class=smallfont] {
border:none !important;
font-size:26px !important;
}
table td[class=sidespace] {
width:10px !important;
}
}
#media only screen and (max-width: 520px) {
}
#media only screen and (max-width: 480px) {
table {
border-collapse: collapse;
}
table td[class=template-img] img {
width:100% !important;
display:block !important;
}
}
#media only screen and (max-width: 320px) {
}
</style>
</head>
<body style="background:#f2f2f2;">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="full">
<tr>
<td height="54"> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="full">
<tr>
<td align="center"><table width="600" border="0" cellspacing="0" cellpadding="0" align="center" class="devicewidth">
<tr>
<td><table width="100%" bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="0" align="center" class="full" style="border-radius:5px 5px 0 0; background-color:#ffffff;">
<tr>
<td height="29"> </td>
</tr>
<tr>
<td><table border="0" cellspacing="0" cellpadding="0" align="left" class="inner" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;">
<tr>
<td width="23" class="hide"> </td>
<td height="75" class="inner" valign="middle"><img class="logo" src="http://my.in/img/my-logo.png" width="180" height="61" alt="Logo" style="background: #000;padding: 10px;"></td>
</tr>
</table>
<table width="150" border="0" cellspacing="0" cellpadding="0" align="right" class="inner" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;">
<tr>
<td height="15"> </td>
</tr>
<tr>
<td align="center">View online</td>
<td class="hide" width="20"> </td>
</tr>
</table></td>
</tr>
<tr>
<td style="border-bottom:1px solid #dbdbdb;"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="full">
<tr>
<td align="center"><table width="600" border="0" cellspacing="0" cellpadding="0" align="center" class="devicewidth">
<tr>
<td><table width="100%" bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="0" align="center" class="full" style="background-color:#ffffff;">
<tr>
<td height="23"> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="23" class="sidespace"> </td>
<td><table width="76%" border="0" cellspacing="0" cellpadding="0" align="left" class="inner" id="banner" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;">
<!--<tr>
<td style="font:bold 20px Arial, Helvetica, sans-serif; border-right:1px solid #dbdbdb;color: #000;" class="smallfont">THE BEST NUTRITION PLANS ARE HERE</td>
</tr>-->
<tr>
<td height="20"> </td>
</tr>
</table>
<!--<table width="22%" border="0" cellspacing="0" cellpadding="0" align="right" class="inner" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;">
<tr>
<td align="center"><img src="http://www.quanutrition.com/images/facebook.png" width="32" height="atuo" alt="Social Media" /></td>
<td align="center"><img src="http://www.quanutrition.com/images/twitter.png" width="32" height="atuo" alt="Social Media" /></td>
<td align="center"><img src="http://www.quanutrition.com/images/google.png" width="32" height="atuo" alt="Social Media" /></td>
</tr>
<tr>
<td height="20"> </td>
<td height="20"> </td>
<td height="20"> </td>
</tr>
</table>--></td>
<td width="23" class="sidespace"> </td>
</tr>
</table>
<!--<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="3.33%" class="sidespace"> </td>
<td width="93.33%"><img class="imgresponsive" src="http://www.quanutrition.com/images/banner1.jpg" width="554" height="atuo" alt="Banner" /></td>
<td width="3.33%" class="sidespace"> </td>
</tr>
<tr>
<td height="20"> </td>
<td height="20"> </td>
<td height="20"> </td>
</tr>
</table>-->
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="23" class="sidespace"> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0" align="left" class="inner">
<tr>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;width: 20%;color: #000;" class="smallfont">Name </td>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont" width="23">'.$uname.'</td>
</tr>
<tr>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont">Email </td>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont" width="23">'.$uemail.'</td>
</tr>
<tr>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont">Mobile </td>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont" width="23">'.$resume.'</td>
</tr>
<tr>
<tr>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont">Message:</td>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont" width="23">'.$message.'</td>
</tr>
<tr>
<td height="20"> </td>
<td class="hide" height="20"> </td>
</tr>
</table>
</td>
<td width="23" class="sidespace"> </td>
</tr>
<tr>
<td height="16"> </td>
<td height="16"> </td>
<td height="16"> </td>
</tr>
</table></td>
</tr>
<tr>
<td style="border-bottom:1px solid #dbdbdb;"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="full">
<tr>
<td align="center"><table width="600" border="0" cellspacing="0" cellpadding="0" align="center" class="devicewidth">
<tr>
<td><table width="100%" bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="0" align="center" class="full" style="border-radius:0 0 7px 7px;">
<tr>
<td height="18"> </td>
</tr>
<tr>
<td><table class="inner" align="right" width="340" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; text-align:center;">
<tr>
<td width="21"> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="full">
<tr>
<td height="18"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
<table class="inner" align="left" width="230" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; text-align:center;">
<tr>
<td width="21"> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" style="font:11px Helvetica, Arial, sans-serif; color:#000000;">© 2017, All rights reserved </td>
</tr>
<tr>
<td height="18"> </td>
</tr>
</table></td>
<td width="21"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td height="20"> </td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: mail#my.in' . "\r\n";
$headers .= 'Reply-to: '.$uemail.'' . "\r\n";
//$headers .= 'Cc: rajendra.b#my.in' . "\r\n";
$sent = mail($to,$subject,$message,$headers);
echo "Thankyou for Contacting with us. We will get back you soon !!.";
}
else
{
echo "Please enter all the fields.";
}
?>
Below is the form
<form action="purpledotcareer.php" id="fileUploadForm" method="post" enctype="multipart/form-data" onsubmit="return checkvalidate()">
<div class="form-group">
<label for="email">Enter Your Name:</label>
<input type="text" class="form-control" id="uname" name="uname" onblur="if (this.value == '') {this.value = '';}" onfocus="this.value = '';" required="" type="text" value="" >
</div>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="uemail" name="uemail" onblur="if (this.value == '') {this.value = '';}" onfocus="this.value = '';" required="" type="text" value="" >
</div>
<div class="form-group">
<label for="email">Message:</label>
<textarea class="form-control" id="message" name="message" onblur="if (this.value == '') {this.value = '';}" onfocus="this.value = '';" required="" rows="3" ></textarea>
</div>
<div class="form-group">
<label for="email">Upload Resume:</label>
<input type="file" class="form-control" id="resume" name="resume" onblur="if (this.value == '') {this.value = '';}" onfocus="this.value = '';" required="" accept=".xlsx,.xls,.doc, .docx,.ppt, .pptx,.txt,.pdf" >
</div>
<button type="submit" id="btnSubmit" class="btn btn-default">Submit</button>
</form>
It will be really helpful if anybody can solve this. Thanks in advance

Related

php foreach loop repeat td's 2 times in a tr

I creating a PDF for print the address of users. I have the below HTML structure:
I have tried with the below code:
<?php $i=0; ?>
<tr valign="top">
foreach ($users as $user): ?>
<?php if ($i % 2 == 1) {?>
<tr valign="top">
<?php } ?>
But it's now work as expect.
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0">
<tr valign="top">
<td width="48%" align="left" valign="top" style="padding:10px 10px 15px; font-size:14px; color:#333; font-family:Verdana, Geneva, sans-serif; border:1px solid #ccc;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%" height="25" valign="bottom">Name</td>
<td width="78%" valign="bottom" style="border-bottom:1px dashed #ccc;"> </td>
</tr>
<tr>
<td height="40" valign="bottom"> </td>
<td valign="bottom" style="border-bottom:1px dashed #ccc;"> </td>
</tr>
<tr>
<td height="40" valign="bottom">Phone</td>
<td valign="bottom" style="border-bottom:1px dashed #ccc;"> </td>
</tr>
</table></td>
<td width="4%" align="left"> </td>
<td width="48%" align="left" style="padding:10px 10px 15px; font-size:14px; color:#333; font-family:Verdana, Geneva, sans-serif; border:1px solid #ccc;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%" height="25" valign="bottom">Name</td>
<td width="78%" valign="bottom" style="border-bottom:1px dashed #ccc;"> </td>
</tr>
<tr>
<td height="40" valign="bottom"> </td>
<td valign="bottom" style="border-bottom:1px dashed #ccc;"> </td>
</tr>
<tr>
<td height="40" valign="bottom">Phone</td>
<td valign="bottom" style="border-bottom:1px dashed #ccc;"> </td>
</tr>
</table></td>
</tr>
<tr valign="top">
<td height="15" align="left"></td>
<td height="15" align="left"></td>
<td height="15" align="left"></td>
</tr>
</table>
In the abolve table I want to repeat the TD in each TR 2 times and added the blank TR after every TR.
The above HTML out should be the below image:
Could any one can help me out this.
If I get properly what you're looking for : I want to repeat in one TR repeat two TD
Then this code:
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
echo"<table>";
for ($i = 1; $i <= 10; $i++) {
if(($i % 2) == 1) // odd -> start TR
{ echo "<tr><td class=\"dark\">$i</td>"; }
else // even -> close TR
{ echo "<td class=\"red\">$i</td></tr><tr><td colspan=\"2\">whatever here</tr>"; }
}
echo"</table>";
?>
will give you this output :
<table>
<tr><td class="dark">1</td><td class="red">2</td></tr><tr><td colspan="2">whatever here</tr>
<tr><td class="dark">3</td><td class="red">4</td></tr><tr><td colspan="2">whatever here</tr>
<tr><td class="dark">5</td><td class="red">6</td></tr><tr><td colspan="2">whatever here</tr>
<tr><td class="dark">7</td><td class="red">8</td></tr><tr><td colspan="2">whatever here</tr>
<tr><td class="dark">9</td><td class="red">10</td></tr><tr><td colspan="2">whatever here</tr>
</table>
EDIT after you comment : added one 'blank' TR
Try below solution you missed out to close
<?php
$i=0;
foreach ($users as $user){
if ($i % 2 == 0) {?>
<tr valign="top">
<?php } ?>
<td width="48%" align="left" style="padding:10px 10px 15px; font-size:14px; color:#333; font-family:Verdana, Geneva, sans-serif; border:1px solid #ccc;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%" height="25" valign="bottom">Name</td>
<td width="78%" valign="bottom" style="border-bottom:1px dashed #ccc;"> </td>
</tr>
<tr>
<td height="40" valign="bottom"> </td>
<td valign="bottom" style="border-bottom:1px dashed #ccc;"> </td>
</tr>
<tr>
<td height="40" valign="bottom">Phone</td>
<td valign="bottom" style="border-bottom:1px dashed #ccc;"> </td>
</tr>
</table></td>
<?php if ($i % 2 == 0) {?>
</tr>
<?php } }?>

WriteHTML is not working in mpdf, blank screen displays

I am trying to figure out the problem in this, but not able to. Query is proper, Result i am getting. If i echo $html i get result, but nothing for WriteHTML();
Here is my code
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include("connect.php");
$id = $_GET['id'];
include("mpdf/mpdf.php");
$mpdf=new mPDF('utf-8', 'A4');
$mpdf->debug = true;
$mpdf->useOnlyCoreFonts = true; // false is default
$mpdf->SetProtection(array());
$mpdf->SetTitle("My Company");
$mpdf->SetAuthor("MeAuthor");
$mpdf->SetWatermarkText("Demo");
$mpdf->showWatermarkText = false;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');
$s1 = "SELECT * FROM mytable WHERE cid=".$id."";
$sql = mysqli_query($con, $s1) or die (mysqli_error($con));
$row = mysqli_fetch_array($sql);
$html = '
<html>
<head>
<body>
<!--mpdf
<htmlpageheader name="myheader">
<table width="100%"><tr>
<td width="80%" style="text-align: center; font-size: 16pt;">Company Name<br>
<span style="font-size: 11pt;text-align: center;">Address 123, Lorel Ipsum, sdfsdf sdsdgsdg,</span><br>
<span style="font-size: 11pt;text-align:center;">sdfdsfdsf, sfsdf - 100066
</td>
</tr>
</table>
</htmlpageheader>
<sethtmlpageheader name="myheader" value="on" show-this-page="1" />
<sethtmlpagefooter name="myfooter" value="off" />
mpdf-->
<table width="100%">
<tr><td colspan="2" align="right" width="40%"> Vocher No : '.$id.' </td></tr>
<tr>
<td width="70%">Debit A/C. : '.$row['account_no'].' </td>
<td width="30%" style="text-align: right">Date: '.date("d-m-Y").'</td></tr>
</table>
<div style="border: 1px solid black">
<table border="0" style="white-space:nowrap; border-spacing:0;" height="100%" cellspacing="5"><thead>
<tr>
<th width="30%" style="border-right:1px solid #000;">Name</th>
<th width="20%" style="border-right:1px solid #000;">E-Mail</th>
<th width="20%" style="border-right:1px solid #000;">Mobile</th>
<th width="30%" style="border-right:1px solid #000;">Particulars</th>
<th width="15%" style="border-right:1px solid #000;">RS.</th>
<th width="5%" style="border-right:1px solid #000;">P.</th>
</tr>
</thead>
<tr>
<td style="border-right:1px solid #000;" width="30%" height="100px;" >'.$row['name'].'</td>
<td style="border-right:1px solid #000;" width="20%">'.$row['email'].'</td>
<td style="border-right:1px solid #000;" width="20%">'.$row['mobile'].'</td>
<td style="border-right:1px solid #000;" width="30%">'.$row['purpose'].'</td>
<td style="border-right:1px solid #000;" width="15%">'.$row['amount'].'</td>
<td style="border-right:1px solid #000;" width="5%">00</td>
</tr>
<tr><td colspan="4" style="font-weight:bold;">Total Rs.</td> '.$row['amount'].'<td></tr>
</table></div>
<br>
<table border="0"><tr><td style="width=50%;">Mode of Payment : '.$row['mode'].' </td><td width="50%">Date : '.date('Y-m-d').'</td></tr>
<tr><td colspan="2">Rupees : </td></tr>
</table>
<br><br><br>
<table width="100%" border="0">
<tr><td width="20%"> Hon. Secretary </td>
<td width="20%">Hon. Treasurer</td>
<td width="20%">Hon. Trustee</td>
<td width="20%">Receiver s Signature</td></tr>
</table>
</body>
</html>
';
//echo $html;
echo $mpdf->WriteHTML($html);
//$mpdf->Output('Receipt.pdf','D');
$mpdf->Output();
?>
Method WriteHTML() returns void! So you'll not get any echo.
Note that you have not send anything to browser (even http-header) before Output().

dompdf render doesn't look like html

i use dompdf with codeigniter to convert my php (html) file into pdf.
My problem is the dompdf render doesn't appear like my php page :
Style for php file :
body {font-family:Arial, Helvetica, sans-serif;
font-size:15px;
color:#000;}
.xls {
border-top:1px solid #868686; }
.xls tr > td {
border-right:1px solid #868686; padding: 2px 3px 2px 5px;}
.t-pad tr > td {
border-right:1px solid #868686; padding: 2px 3px 2px 5px;}
.xls tr:first-child >td {
border-top:1px solid #868686;border-bottom:1px solid #000;}
.xls tr:last-child >td {
border-bottom:1px solid #868686;
text-align: center;
}
.xls {
border-right:1px solid #868686;
border-left:1px solid #868686;
}
.xls .m-td{
border-bottom: 0 none !important;
border-left: 1px solid #868686;
border-right: 1px solid #868686;
border-top: 0 none !important;}
.last-col{border-right:0 !important;
border-top: 0 none !important; }
.td-tab{ padding:10px 10px 10px 20px !important;}
.tab-center{ border-left: 1px solid #868686; }
.tab-center td{ padding: 0 0 0 5px; border-bottom: 1px solid #868686; }
.first-td {
border-top: 1px solid #868686 !important;
}
.border-r{border-right: 1px solid #868686 !important;}
.tab-cc{
border: 1px solid #868686;
}
.border-bt{border-bottom: 1px solid #868686 !important;}
.titre-tab {
background:#b2b1b1;
}
and it appear like :
http://info-du-jour.net/wp-content/uploads/2014/06/php.png
fil in controller to convert into pdf :
$data = $this->data_paie($ids);
$this->load->view('paie/fdp_etat', $data);
// Get output html
$html = $this->output->get_output();
// Load library
$this->load->library('dompdf_gen');
// Convert to PDF
$this->dompdf->load_html($html);
$this->dompdf->render();
$this->dompdf->stream("fiche_de_paie.pdf",array('Attachment'=>0));
and it look like
http://info-du-jour.net/wp-content/uploads/2014/06/dompdf.png
html rendering code :
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="50" valign="top">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="font-size:24px; font-weight:bold;">BULLETIN DE PAIE</td>
<td align="right">
<img src="/logo/logo_simple1.jpg"
width="136" height="31" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" width="101"><strong>Période :</strong></td>
<td width="197" colspan="3" align="center">
<div style="font-size:14px; font-weight:bold;">
01-06-2014 au 30-06-2014 </div>
</td>
</tr>
</table>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="48%" valign="top">
<table border="0" cellpadding="0" cellspacing="2" class="tab-cc t-pad" width="100%" style="height:150px;">
<tr>
<td width="137"><strong>Matricule</strong></td>
<td width="217">SAL003</td>
</tr>
<tr>
<td><b>Nom et Prénom</b></td>
<td>AYARI Marwa</td>
</tr>
<tr>
<td><strong>Fonction</strong></td>
<td>Développeur</td>
</tr>
<tr>
<td><strong>Sit. familiale</strong></td>
<td>Marié </td>
</tr>
<tr>
<td><strong>Nbre d'enfants</strong></td>
<td>3</td>
</tr>
</table></td>
<td width="4%"> </td>
<td width="48%" align="left" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="2" class="tab-cc" style="height:150px;">
<tr>
<td align="center"><b>EMPLOYEUR</b></td>
</tr>
<tr>
<td align="center"><strong>TOPO+</strong><br />
6 Rue des Cyclamens<br />
1004 EL MENZAH 5, ARIANA.<br />
CNSS Employeur : 45454 </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><table border="1" cellspacing="2" cellpadding="0" class="tab-cc xls" width="48%" >
<tr>
<td rowspan="2"><b>Droit congés payés</b></td>
<td align="center">Ancien solde</td>
<td align="center">(+) Droits</td>
<td align="center">(-) Pris</td>
<td align="center">Nouv. solde</td>
</tr>
<tr>
<td align="center">12</td>
<td align="center">1</td>
<td align="center">5</td>
<td align="center">2</td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<table width="100%" border="1" cellpadding="0" cellspacing="2" class="xls">
<tr class="titre-tab">
<td height="40"><strong>Désignation</strong></td>
<td><strong>Nombre</strong></td>
<td><strong>Base</strong></td>
<td><strong>Gains</strong></td>
<td><strong>Retenues</strong></td>
</tr>
<tr>
<td>Nombre de jours de présence</td>
<td align="right"> </td>
<td align="right"> </td>
<td align="right">26</td>
<td align="right"> </td>
</tr>
<tr>
<td>Salaire de base</td>
<td align="right"> </td>
<td align="right">1258,799</td>
<td align="right">1258,799</td>
<td align="right"> </td>
</tr>
<!-- autant de lignes que de primes dans la conv collective -->
<tr>
<td>Indemnité de transport</td>
<td align="right"> </td>
<td align="right">40,000</td>
<td align="right">40,000</td>
<td align="right"> </td>
</tr>
<tr>
<td>Prime de présence</td>
<td align="right"> </td>
<td align="right">2,080</td>
<td align="right">2,080</td>
<td align="right"> </td>
</tr>
<tr>
<td>Indemnité de déplacement</td>
<td align="right"> </td>
<td align="right">0,000</td>
<td align="right">0,000</td>
<td align="right"> </td>
</tr>
<tr>
<td> <b>Total Brut</b></td>
<td align="right"> </td>
<td align="right"> </td>
<td align="right">1300,879</td>
<td align="right"> </td>
</tr>
<tr>
<td>Retenu C.N.S.S</td>
<td align="right"> </td>
<td align="right">1300,879</td>
<td align="right"> </td>
<td align="right">119,421</td>
</tr>
<tr>
<td><b>SALAIRE IMPOSABLE</b></td>
<td align="right"> </td>
<td align="right"> </td>
<td align="right"> </td>
<td align="right">1181,458</td>
</tr>
<tr>
<td>IRPP</td>
<td align="right"> </td>
<td align="right"> </td>
<td align="right"> </td>
<td align="right">173,646</td>
</tr>
<tr>
<td> <b>Total Cotisations</b></td>
<td align="right"> </td>
<td align="right"> </td>
<td align="right"> </td>
<td align="right">293,067</td>
</tr>
<tr height="35">
<td> </td>
<td align="right"> </td>
<td align="right"> </td>
<td align="right"> </td>
<td align="right"> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td><table cellpadding="0" cellspacing="2" border="0" width="100%">
<tbody>
<tr height="21">
<td align="right"> </td>
<td></td>
<td></td>
<td></td>
</tr>
<tr height="21">
<td width="66%" align="right"><strong>Net à Payer</strong></td>
<td width="3%"></td>
<td width="2%"></td>
<td width="29%" colspan="2" align="right" class="tab-cc"><span style="font-weight:bold;padding-right: 4px;">1007,812</span> </td>
</tr>
<tr height="21">
<td align="right"> </td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
Instead of using $html = $this->output->get_output(); you can get the same HTML as it is rendering on browser . for that you need to make changes in script like :
$html = $this->load->view('paie/fdp_etat', $data , true); // so now your `$html` will be string which will return string from your view and both will be same.
For reference SEE HERE

Why is this script not working? (not getting error, simply posts script and looks like it works)

Below is a contact us script in php, when I click submit at www.mydomain.com.au/contact.html it looks as though it works because I end up at ww.mydomain.com.au/thanks.html.
However the specified email account is not receiving contact emails.
Here is the code for the contact us script found at includes/contact_mail.php
<?php
if(isset($_POST['enter']) && $_POST['enter']==1)
{
$_SESSION['email']=$_POST['email'];
$to="name#domains.com";
$subject='Contact Us Details';
$message="<style>
.textstyle{
font-family:Tahoma;
font-size:11px;
color:#156E00;
text-align:left;
margin-left:10px;
text-decoration:none;
}
</style>";
$message.="<table width=400 border=0>
<tr><td class=textstyle>First Name: </td> <td class=textstyle>".$_POST['fname']."</td></tr>
<tr><td class=textstyle>Last Name: </td> <td class=textstyle>".$_POST['lname']."</td></tr>
<tr><td class=textstyle>E-mail: </td> <td class=textstyle>".$_POST['email']."</td></tr>
<tr><td class=textstyle>Phone Number: </td> <td class=textstyle>".$_POST['tel']."</td></tr>
<tr><td class=textstyle>Comments: </td> <td class=textstyle>".$_POST['que']."</td></tr>
</table>";
$mail_from = "From:".$_POST['email'];
$mail_from .="\r\nContent-type: text/html";
#mail($to,$subject,$message,$mail_from);
header("location: ../thankyou.html");
exit();
}
?>
Here is the code at ww.mydomain.com.au/contact.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="GENERATOR" content="Macromedia Dreamweaver CS3" />
<meta name="author" content="Relyon security" />
<meta name="keywords" content="Camera Surveillance,Spy Cameras,Remote Viewing,Audio recording,Relyon security" />
<meta name="description" content="" />
<meta http-equiv="EXPIRES" content="-1" />
<title>Relyon Security: About Relyon Security</title>
<link rel="stylesheet" type="text/css" href="css/stylesheet.css" />
<script language="JavaScript" type="text/javascript">
function fullcheck()
{
var str=document.contact.email.value;
//alert(str);
if (document.contact.fname.value=="")
{
alert ("Blank space not allowed. Please type your First Name.");
document.contact.fname.select();
return false;
}
if (document.contact.lname.value=="")
{
alert ("Blank space not allowed. Please type your Last Name.");
document.contact.lname.select();
return false;
}
if ((document.contact.email.value).indexOf(" ")>=0)
{
alert ("Blank space not allowed inside email!");
document.contact.email.select();
return false;
}
if (document.contact.email.value.indexOf("#",1) == -1)
{
alert("Invalid E-Mail address");
document.contact.email.focus();
document.contact.email.select();
return(false);
}
if (document.contact.email.value.indexOf("#") == 0)
{
alert("Invalid E-Mail address");
document.contact.email.focus();
document.contact.email.select();
return(false);
}
if (document.contact.email.value.indexOf(".",5) == -1)
{
alert("Invalid E-Mail address");
document.contact.email.focus();
document.contact.email.select();
return(false);
}
if (document.contact.email.value.indexOf(".") == 0)
{
alert("Invalid E-Mail address");
document.contact.email.focus();
document.contact.email.select();
return(false);
}
if ((document.contact.email.value.lastIndexOf(".")) -(document.contact.email.value.indexOf("#"))<4 )
{
alert("Invalid E-Mail address");
document.contact.email.focus();
document.contact.email.select();
return(false);
}
if (document.contact.tel.value=="")
{
alert ("Blank space not allowed. Please type your Telephone Number.");
document.contact.tel.select();
return false;
}
if (document.contact.que.value=="")
{
alert ("Blank space not allowed. Please enter your question or comment.");
document.contact.que.select();
return false;
}
}
//-->
</script>
</head>
<body>
<table width="1000" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" align="left" width="110" height="186"><img src="images/spacer.gif" alt="" width="1" height="1" /></td>
<td width="780" rowspan="2" align="center" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
<tr>
<td height="161" valign="top"><img src="images/spacer.gif" alt="" /></td>
</tr>
<tr>
<td valign="top" align="left" class="btn">
<table width="780" border="0" cellspacing="0" cellpadding="0" align="left">
<tr>
<td width="10" valign="top"><img src="images/btn-left.jpg" alt="" width="10" height="49" /></td>
<td align="center" valign="middle">
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="154" align="center" valign="top">Home Page</td>
<td width="180" align="center" valign="top">Our Services</td>
<td width="244" align="center" valign="top">About relyon security</td>
<td width="182" align="center" valign="top"><span class="navg_contact_activated">Contact Us</span></td>
</tr>
</table>
</td>
<td width="10" valign="top" align="right"><img src="images/btn-right.jpg" alt="" width="10" height="49" /></td>
</tr>
<tr>
<td colspan="3" height="1" bgcolor="#FFFFFF"><img src="images/spacer.gif" alt="" width="1" height="1" /></td>
</tr>
<tr>
<td width="10"><img src="images/left-bot.jpg" alt="" width="10" height="42" /></td>
<td class="shadow"><img src="images/spacer.gif" alt="" width="1" height="1" /></td>
<td><img src="images/rgh-bot.jpg" alt="" width="10" height="42" /></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td valign="top" align="left" width="110"><img src="images/spacer.gif" alt="" /></td>
</tr>
<tr>
<td valign="top" align="left" width="110" bgcolor="#FFFFFF" height="66"><img src="images/spacer.gif" alt="" /></td>
<td valign="top" align="left" width="110" bgcolor="#FFFFFF"><img src="images/spacer.gif" alt="" /></td>
</tr>
</table>
<table width="1000" border="0" cellspacing="0" cellpadding="0" align="center" class="white">
<tr>
<td valign="top" align="left"><table width="780" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" class="inner_text"><span class="head-blue">Contact Us</span><br /><br />
Email address: relyonsecurity#live.com.au
<br />
Phone: 0422 663 489<br />
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="1000" border="0" cellspacing="0" cellpadding="0" align="center" class="blue">
<tr>
<td valign="top" align="left"><table width="780" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top">
<form name="contact" method="post" action="includes/contact_mail.php" onsubmit="return fullcheck()">
<table width="90%" border="0" cellpadding="0" cellspacing="3" >
<tr>
<td width="7%"> </td>
<td height="30" colspan="2" align="left" valign="middle"><span class="mandatory">*</span>Required fields</td>
</tr>
<tr>
<td> </td>
<td width="22%" class="form_text"><span class="mandatory">*</span>First Name :</td>
<td width="71%"><input name="fname" type="text" id="fname" size="35" class="inputbox"></td>
</tr>
<tr>
<td> </td>
<td width="22%" class="form_text"><span class="mandatory">*</span>Last Name :</td>
<td width="71%"><input name="lname" type="text" id="lname" size="35" class="inputbox"></td>
</tr>
<tr>
<td> </td>
<td class="form_text"><span class="mandatory">*</span>Email Address :</td>
<td><input name="email" type="text" class="inputbox" id="email" size="35"></td>
</tr>
<tr>
<td width="7%"> </td>
<td class="form_text"><span class="mandatory">*</span>Telephone Number:</td>
<td><input name="tel" type="text" class="inputbox" id="tel" size="35"></td>
</tr>
<tr>
<td> </td>
<td class="form_text"><span class="mandatory">*</span>Please enter your question or comment :</td>
<td><textarea name="que" cols="33" rows="8" id="que" class="inputbox"></textarea></td>
</tr>
<tr>
<td colspan="3" height="5" valign="top"><input name="enter" type="hidden" value="1" /></td>
</tr>
<tr>
<td> </td>
<td class="form_text"> </td>
<td><input type="submit" name="Submit" value="Submit" class="inputbox">
<input type="reset" name="Submit2" value="Reset" class="inputbox"></td>
</tr>
<tr>
<td colspan="3" height="30" valign="top"></td>
</tr>
</table>
</form>
<table width="780" border="0" cellspacing="0" cellpadding="0" align="center" class="footer" height="41">
<tr>
<td valign="top" width="12" height="8"><img src="images/foo-l-top.gif" alt="" width="12" height="8" /></td>
<td><img src="images/spacer.gif" alt="" /></td>
<td align="right" valign="top" width="9" height="8"><img src="images/foo-r-top.gif" alt="" width="9" height="8" /></td>
</tr>
<tr>
<td><img src="images/spacer.gif" alt="" /></td>
<td align="center" valign="middle">©2009 Relyon Security.com All Rights Reserved</td>
<td><img src="images/spacer.gif" alt="" /></td>
</tr>
<tr>
<td valign="bottom" height="8"><img src="images/foo-l-bot.gif" alt="" width="12" height="8" /></td>
<td><img src="images/spacer.gif" alt="" /></td>
<td valign="bottom"><img src="images/foo-r-bot.gif" alt="" width="9" height="8" /></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Second attempt at script?
<?php
error_reporting(E_ALL)
if(isset($_POST['enter']) && $_POST['enter']==1)
{
$_SESSION['email']=$_POST['email'];
$to="name#domains.com";
$subject='Contact Us Details';
$message="<style>
.textstyle{
font-family:Tahoma;
font-size:11px;
color:#156E00;
text-align:left;
margin-left:10px;
text-decoration:none;
}
</style>";
$message.="<table width=400 border=0>
<tr><td class=textstyle>First Name: </td> <td class=textstyle>".$_POST['fname']."</td></tr>
<tr><td class=textstyle>Last Name: </td> <td class=textstyle>".$_POST['lname']."</td></tr>
<tr><td class=textstyle>E-mail: </td> <td class=textstyle>".$_POST['email']."</td></tr>
<tr><td class=textstyle>Phone Number: </td> <td class=textstyle>".$_POST['tel']."</td></tr>
<tr><td class=textstyle>Comments: </td> <td class=textstyle>".$_POST['que']."</td></tr>
</table>";
$mail_from = "From:".$_POST['email'];
$mail_from .="\r\nContent-type: text/html";
mail($to,$subject,$message,$mail_from);
// header("location: ../thankyou.html");
exit();
}
?>
put error_reporting(E_ALL) at the top of the script, remove # from mail() call and comment string with header() and THEN look for errors

Jquery change text ajax request problem

I have an html file as coded below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
.style1 {
background-color: #c3d9ff;
font-family:arial,sans-serif;
}
.style2 {
text-align: center;
font-weight: bold;
}
.style3 {
background-color: #FFFFFF;
font-family:arial,sans-serif;
text-align: center;
font-weight: bold;
}
.style4 {
background-color: #FFFFFF;
font-family:arial,sans-serif;
text-align: left;
}
body {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:15px;
background-color: ;
}
.action_button {
font-weight:bold;
float:right;
}
</style>
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script type="text/javascript">$(function() {
$('.action_button').click(function() {
var $button = $(this);
$.ajax({
type: 'POST',
url: 'action.php',
data: 'id='+ $(this).attr('id'),
cache: false,
success: function(result) {
var $row = $button.closest('tr');
var $col = $row.find('.clickme2');
$row.fadeOut('fast', function() {
if (result == 'ACTIVATED') {
$button.text('Activate');
$col.text('Active');
} else if (result == 'INACTIVATED') {
$button.text('Inactivate');
$col.text('Inactive');
}
}).fadeIn();
}
});
return false;
});
});
</script>
</head>
<body>
<table style="width: 90%" align="center" class="style1">
<tr>
<td colspan="7" class="style2">MANAGER</td>
</tr>
<tr>
<td class="style3" style="width: 139px">Col1</td>
<td class="style3" style="width: 139px">Col2</td>
<td class="style3" style="width: 139px">Col3</td>
<td class="style3" style="width: 139px">Col4</td>
<td class="style3" style="width: 139px">Col5</td>
<td class="style3" style="width: 200px">Col6</td>
<td class="style3" style="">Action</td>
</tr>
</table>
<td id="main" class="main">
<td class="update">
<table style="width: 90%" align="center" class="style1">
<tr>
<td class="style4" style="width: 139px">DataA1</td>
<td class="style4" style="width: 139px">DataA2</td>
<td class="style4" style="width: 139px">DataA3</td>
<td class="style4" style="width: 139px">DataA4</td>
<td class="style4 clickme2" style="width: 139px">Inactive</td>
<td class="style4" style="width: 200px">DataA6</td>
<td>
<button href="#" id="DataA1" class="action_button" style="width:80px;height:">
Activate</button>
</td>
</tr>
<tr>
<td class="style4" style="width: 139px">DataB1</td>
<td class="style4" style="width: 139px">DataB2</td>
<td class="style4" style="width: 139px">DataB3</td>
<td class="style4" style="width: 139px">DataB4</td>
<td class="style4 clickme2" style="width: 139px">Inactive</td>
<td class="style4" style="width: 200px">DataB6</td>
<td>
<button href="#" id="DataB1" class="action_button" style="width:80px;height:">
Activate</button>
</td>
</tr>
<tr>
<td class="style4" style="width: 139px">DataC1</td>
<td class="style4" style="width: 139px">DataC2</td>
<td class="style4" style="width: 139px">DataC3</td>
<td class="style4" style="width: 139px">DataC4</td>
<td class="style4 clickme2" style="width: 139px">Active</td>
<td class="style4" style="width: 200px">DataC6</td>
<td>
<button href="#" id="DataC1" class="action_button" style="width:80px;height:">
Inactivate</button>
</td>
</tr>
<tr>
<td class="style4" style="width: 139px">DataD1</td>
<td class="style4" style="width: 139px">DataD2</td>
<td class="style4" style="width: 139px">DataD3</td>
<td class="style4" style="width: 139px">DataD4</td>
<td class="style4 clickme2" style="width: 139px">Active</td>
<td class="style4" style="width: 200px">DataD6</td>
<td>
<button href="#" id="DataD1" class="action_button" style="width:80px;height:">
Inactivate</button>
</td>
</tr>
<tr>
<td class="style4" style="width: 139px">DataE1</td>
<td class="style4" style="width: 139px">DataE2</td>
<td class="style4" style="width: 139px">DataE3</td>
<td class="style4" style="width: 139px">DataE4</td>
<td class="style4 clickme2" style="width: 139px">Inactive</td>
<td class="style4" style="width: 200px">DataE6</td>
<td>
<button href="#" id="DataE1" class="action_button" style="width:80px;height:">
Activate</button>
</td>
</tr>
</table>
</td>
</td>
</body>
</html>
The fage contain a table with 5 rows with a button at the end of the row. On click, the button submits data to a php file and then changes text and blurs according to the response from php file. The blur function and change text function in col5 is working well. But the change text function in button got really buggy. The button text should change accordingly. the text of button "Activate" should change to "Inactivate" and the text of button "Inactivate" should change to "Activate" on click / successful submission.. This is not working..
Below is the php file code
<?php
$id = $_POST[id];
if($id=="DataA1"){
echo "ACTIVATED";
}
if($id=="DataB1"){
echo "ACTIVATED";
}
if($id=="DataE1"){
echo "ACTIVATED";
}
if($id=="DataC1"){
echo "INACTIVATED";
}
if($id=="DataD1"){
echo "INACTIVATED";
}
?>
Thanks in advance.. :)
blasteralfred
I think your logic is wrong. When the button initially says "Activate", you are returning "ACTIVATED" so your button should then read "Inactivate." You are, however, setting the text to "Activate" again. Look at the button with id "DataA1" for an example.
Change $_POST[id] to $_POST["id"].
I found the solution..
Thank you #Heikki, #Cristy..... :)
I corrected the script as below
$(function() {
$('.action_button').click(function() {
var $button = $(this);
$.ajax({
type: 'POST',
url: 'action.php',
data: 'id='+ $(this).attr('id'),
cache: false,
success: function(result) {
var $row = $button.closest('tr');
var $col = $row.find('.clickme2');
$row.fadeOut('fast', function() {
if (result == 'ACTIVATED') {
$button.text('Inactivate');
$col.text('Active');
} else if (result == 'INACTIVATED') {
$button.text('Activate');
$col.text('Inactive');
}
}).fadeIn();
}
});
return false;
});
});
Thanks again ... :)
I know you've already solved the problem, but here's my answear anyway:
Replace
data: 'id='+ $(this).attr('id'),
with
data: 'val='+ $button.html(),
And, the php file with this:
<?php
$val = $_POST['val'];
if(strstr($val,"Activate"))
echo "ACTIVATED";
else
echo "INACTIVATED";
?>

Categories