How to write on the server data edited by the client - javascript

I want a Select Box where I can Filter the Data from the Database (with Ajax - no site reload). For example: Order the data by ID or Order the data by name
Thats working fine and now when I get that data I want also that I can edit the data with Inputs and save it (also trough ajax) but I dont know how. I know how to save data with ajax but not when the data is a response from another ajax.
Code: (Its not well formatted here, that's why pastebin: http://pastebin.com/7mgi6VMc)
Index:
<div class="wrapper">
<p id="result">Erfolgreich gespeichert!</p>
<br>
<div class="filter">
<form>
Anzeige:
<select class="selectFilter" onchange="filterFunction(this.value)">
<option value="id_back">ID - Aufwärts</option>
<option value="id_up">ID - Abwärts</option>
</select>
</form>
</div>
<br>
<br>
<div id="resultCatalogue">
<b>Bitte wähle die gewünschte Anzeige ...</b>
</div>
</div>
getData.php:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css? family=Open+Sans" />
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$("#save").on("submit", function(event) {
event.preventDefault();
$.ajax({
type: "POST",
url: "./save.php",
data: $(this).serialize(),
success: function(data) {
if($('#result').css('display') == 'none') {
document.getElementById('result').style.display = 'block'
} else {
document.getElementById('result').style.display = 'none'
setTimeout(function() {
document.getElementById('result').style.display = 'block'
}, 100);
}
},
});
});
</script>
</head>
<body>
<?php
$type = intval($_GET['type']);
if($type == "id_up")
{
echo '
<table class="tableCatalogue">
<tr>
<th class="th" width="5%">ID</th>
<th class="th" width="5%">Unter-ID</th>
<th class="th" width="15%">Titel</th>
<th class="th" width="5%">Iceron</th>
<th class="th" width="10%">Sichtbar</th>
<th class="th" width="10%">Aktiv</th>
<th class="th" width="5%">Min. Rank</th>
<th class="th" width="5%">VIP</th>
<th class="th" width="5%">Reihen Nummer</th>
<th class="th" width="10%">Layout</th>
</tr>
<form method="post" id="save">
';
$index = 0;
$getCataloguePages = mysql_query("SELECT * FROM catalog_pages");
while($row = mysql_fetch_array($getCataloguePages))
{
$id = $row['id'];
$parent_id = $row['parent_id'];
$caption = $row['caption'];
$icon_image = $row['icon_image'];
$visible = $row['visible'];
$enabled = $row['enabled'];
$min_rank = $row['min_rank'];
$min_vip = $row['min_vip'];
$order_num = $row['order_num'];
$page_layout = $row['page_layout'];
$i++;
if(IsEven($i)){
$even = "Even";
} else {
$even = "Odd";
}
echo '
<tr>
<td class="td'.$even.'" width="5%"><input placeholder="ID" class="inputTable" name="id[]" value="'.$id.'"></td>
<td class="td<?php echo $even; ?>" width="5%"><input placeholder="Unter-ID" class="inputTable" name="parent_id[]" value="'.$parent_id.'"></td>
<td class="td<?php echo $even; ?>" width="15%"><input placeholder="Titel" class="inputTable" name="caption[]" value="'.$caption.'"></td>
<td class="td<?php echo $even; ?>" width="5%"><input placeholder="Icon" class="inputTable" name="icon_image[]" value="'.$icon_image.'"></td>
<td class="td<?php echo $even; ?>" width="5%"><select placeholder="Sichtbar" class="selectTable" name="visible[]"><option value="1">Sichtbar</option><option value="0">Nicht sichtbar</option></select></td>
<td class="td<?php echo $even; ?>" width="5%"><select placeholder="Aktiviert" class="selectTable" name="enabled[]"><option value="1">Aktiv</option><option value="0">Nicht aktiv</option></select></td>
<td class="td<?php echo $even; ?>" width="5%"><select placeholder="Mindest Rank" class="selectTable" name="min_rank[]"><option>1</option></select></td>
<td class="td<?php echo $even; ?>" width="5%"><select placeholder="VIP" class="selectTable" name="min_vip[]"><option value="1">Nur VIP</option><option value="0">Alle</option></select></td>
<td class="td<?php echo $even; ?>" width="5%"><input placeholder="Reihen Nummer" class="inputTable" name="order_num[]" value="'.$order_num.'"></td>
<td class="td<?php echo $even; ?>" width="10%"><input placeholder="Layout" class="inputTable" name="page_layout[]" value="'.$page_layout.'"></td>
</tr>
';
$index++;
}
echo '
<input class="save" type="submit" name="save" value="Speichern">
<br><br>
</form>
</table>
';
?>
<script>
$("#save").on("submit", function(event) {
event.preventDefault();
$.ajax({
type: "POST",
url: "./save.php",
data: $(this).serialize(),
success: function(data) {
if($('#result').css('display') == 'none') {
document.getElementById('result').style.display = 'block'
} else {
document.getElementById('result').style.display = 'none'
setTimeout(function() {
document.getElementById('result').style.display = 'block'
}, 100);
}
},
});
});
</script><?php
}
?>
save.php:
$size = count($_POST['id']);
$i = 0;
while ($i < $size)
{
$id = $_POST['id'][$i];
$query = "UPDATE catalog_pages SET id = '".$id."' LIMIT 1";
mysql_query($query) or die ("Error in query: $query");
++$i;
}
Like I said, everything is included. Database Connection, all fine.
It is also showing me the Response with the Select but then I want to Update that data - also with ajax.
Where do I have do place the Ajax Code? How can I do that?

Related

Toggle button print double value

I have had toggle button name is Enable, Disable in my table and in which if
I change the value of a button Enable to Disable then it prints Disable value two times.
My code:
<table id="prodcutTable" class="table table-bordered table-striped" style="width: 100%;" >
<thead>
<tr style="font-size: 12px; line-height: 0px; ">
<th>SR No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email ID</th>
<th>Phone Number</th>
<th>Status</th>
<th></th>
</tr>
<?php $counter=1?>
<?php foreach($result as $result):?>
<tr>
<input type="hidden" name="txt_user_id" value="<?php echo $result['id']?>">
<td><?php echo $counter?></td>
<td><?php echo $result['username']?></td>
<td><?php echo $result['lastname']?></td>
<td><?php echo $result['email']?></td>
<td><?php echo $result['phonenumber']?></td>
<td>
<?php
if ($result['status']=="active"){
?>
<span class="badge badge-boxed badge-soft-success">Active</span>
<?php
}else if($result['status']=="inactive"){
?>
<span class="badge badge-boxed badge-soft-warning">InActive</span>
<?php
}
?>
</td>
<td>
<input type="checkbox" class="btn-toggle" name="toggle" id="toggle" data-toggle="toggle" data-off="Disabled" data-on="Enabled" <?php
if($result['status']=="active") echo "checked"; ?> >
</td>
</tr>
<?php $counter++?>
<?php endforeach;?>
</thead>
</table>
<script>
function disableUser(id) {
$.ajax({
url: "<?php echo base_url(); ?>admin_controller/AdminController/disableUser",
method: "post",
data: {id:id},
dataType:'json',
})
.done(function( data ) {
if(data.status=="true"){
alert('Enabled');
setTimeout(function(){location.reload();},100);
}else{
alert("Try Again");
}
});
}
function enableUser(id) {
$.ajax({
url: "<?php echo base_url(); ?>admin_controller/AdminController/enableUser",
method: "post",
data: {id:id},
dataType:'json',
})
.done(function( data ) {
if(data.status=="true"){
alert('Disabled');
setTimeout(function(){location.reload();},100);
}else{
alert("Try Again");
}
});
}
$('.btn-toggle').change(function(){
var tr = $(this).parents('tr');
//console.log(tr);
var txt_user_id = tr.find($('input[name="txt_user_id"]')).val();
//console.log(txt_user_id);
var mode= $(this).prop('checked');
console.log(mode);
if($(this).prop('checked'))
{
enableUser(txt_user_id);
}
else
{
disableUser(txt_user_id);
}
});
</script>
I do not know where I wrote the wrong code in my code.
Following is the image of my table on how to look like a toggle bar.
And the color also changes to blue to white.
put this code in your ready function :
$('.btn-toggle').bootstrapToggle({
on: 'Enabled',
off: 'Disabled'
});

looping through a table and storing a particular cell in an array if row is checked

I currently have a table that is triggered by a drop down. Inside the table, there's a checkbox. When the check box is checked and the user clicks on the confirm button, the code should loop through the table and get the email values of all the checked rows and store them in an array. So far, it can check if the rows are checked. I've found a few ways online but its not working. Here's the table:
<?php if ($picked != null){ ;
foreach ($picked as $rows): ?>
echo base_url(); ?>employer/view/send/<?php echo $rows['username']; ?>-->
<!--form action="" method="POST"-->
<?php endforeach; ?>
<table id="view_add"
class="table dataTable table-striped table-dynamic table-hover _tm">
<thead>
<tr>
<th class="sorting_asc" tabindex="0" rowspan="1" colspan="1"
style="width: 250px;">
Applicant Name
</th>
<th class="sorting" tabindex="0" rowspan="1" colspan="1"
style="width: 200px;">
Employer
</th>
<th class="sorting" tabindex="0" rowspan="1" colspan="1"
style="width: 200px;">
Post Header
</th>
<th class="sorting_asc" tabindex="0" rowspan="1" colspan="1"
style="width: 450px;">
Description
</th>
<th class="sorting_asc" tabindex="0" rowspan="1" colspan="1"
style="width: 100px;">
VIEW CV
</th>
<th class="sorting_asc" tabindex="0" rowspan="1" colspan="1"
style="width: 100px;">
</th>
</tr>
</thead>
<tbody>
<?php foreach ($picked as $rows): ?>
<tr>
<td><?php echo $rows['applicantName']; ?></td>
<td><?php echo $rows['employerName']; ?></td>
<td><?php echo $rows['postingName']; ?></td>
<td><?php echo $rows['postDescription']; ?></td>
<td style="display: none;"><?php echo $rows['email']; ?></td>
<td><a id="stress" data-toggle="modal" href="#editButton"
data-full="<?php echo $rows['fullName']; ?>"
data-school="<?php echo $rows['institution']; ?>"
data-state="<?php echo $rows['state']; ?>"
data-location="<?php echo $rows['location']; ?>"
data-dob="<?php echo $rows['dob']; ?>" data-skill="<?php echo $rows['skills']; ?>"
data-sex="<?php echo $rows['sex']; ?>" data-gpa="<?php echo $rows['cgpa']; ?>"
data-call="<?php echo $rows['phone']; ?>"
data-like="<?php echo $rows['favoured']; ?>"
data-award="<?php echo $rows['awards']; ?>"
data-interest="<?php echo $rows['interests']; ?>" class="myeditButton"
>view</a></td>
<td>
<label class="switch m-r-40">
<input type="checkbox" class="switch-input"
id="<?php echo $rows['applicationKey']?>"
data-mail="<?php echo $rows['email']; ?>"
data-confirm="<?php echo $rows['applicationId']; ?>"
id="check" name="check" <?php echo $rows['status'] ? 'checked':''; ?> >
<span class="switch-label" data-on="yes" data-off="no"></span>
<span class="switch-handle"></span>
</label>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="form-group">
<input type="submit" value="Confirm" id="mail" class="btn btn-primary mail">
</div>
<!--/form-->
<?php }else{ ;?>
<div class="alert alert-warning">
<h4>There are no current Applicants for this post.</h4>
</div>'
<?php } ;?>
Here's the little script I've used:
<script>
$(document).on("click", "#mail", function () //<-small mistake here
{
var mail_list = [];
$( 'input[type=checkbox]:checked' ).each(
function(){
var mail = $(this).data("mail");
mail_list.push(mail);
var emailers = mail_list.join(",");
//SEND TO PHP
$.ajax({
type: 'post',
url: '<?php echo base_url(); ?>employer/view/send',
data: {
chosen: emailers
},
success: function( data ) {
console.log( data );
}
});
//the END
}
)
});
</script>
My JS isn't so good.
Lastly, heres the php end
else if ($param1 == 'send')
{
$src1= $_POST['chosen'];
$array = explode(",", $src1);
print_r($array);
First, you should add a way to "find" the email value of a row. So edit the html with something like that :
<td style="display: none;" class="email-value">
<?php echo $rows['email']; ?>
</td>
Now, I think there is a small error in your code, an html id is targetable by # and a class by a .. So with my changement I propose :
$(document).on("click", "#mail", function () //<-small mistake here
{
var mail_list = [];
$( 'input[type=checkbox]:checked' ).each(
function(){
var mail = $(this).parents("tr").find(".email-value").text();
//this line search the "tr" parent of each input checkbox that's checked,
//and then finds the child "email" value of it.
mail_list.push(mail);
}
)
})
Alter solution
Add the email in data parameters of the checkbox
<input type="checkbox" class="switch-input"
id="<?php echo $rows['applicationKey']?>"
data-mail="<?php echo $rows['email']; ?>"
data-confirm="<?php echo $rows['applicationId']; ?>"
data-email="<?= $rows['email']"
id="check" name="check" <?php echo $rows['status'] ? 'checked':''; ?> >
Then, the javascript become quite simple :
$(document).on("click", "#mail", function () //<-small mistake here
{
var mail_list = [];
$( 'input[type=checkbox]:checked' ).each(
function(){
var mail = $(this).data("email");
mail_list.push(mail);
//the END
}
)
})
update : oops, it's parents*, parent can't go upper than one level...
update2 : Add an alternative version, simplified
<script type="text/javascript">
$(document).on("click", ".mail", function ()
{
var emailList = [];
var selectedRows = $( 'table._tm' ).find( 'tbody' ) // select table body and
.find( 'tr' ) // select all rows that has
.has( 'input[type=checkbox]:checked' ) // checked checkbox element
selectedRows.each(function(idx, elem) {
var email = jQuery(elem).find('input[type="checkbox"]').data("mail");
emailList.push(email);
});
console.log( 'elem:', emailList );
} );
This should be quite easy try something like this:
var emailList = [];
selectedRows.forEach(function(idx, elem) {
var email = jQuery(elem).data("mail");
emailList.push(email);
});

sum of rows is not updated when running AJAX code until F5 refresh

Following this link here about sending data into MySQL using AJAX, I have this output:
What I want, is to see the row with the curent rows shown in the div and not at the bottom. And how to refresh the sum, and not wait to refresh the page ?
Here is the final AJAX code:
function addFunction()
{
var selectW = $('#insert_new').val();
var selectW = $('#selectW').val();
var select_at = $('#select_at').val();
var pay = $('#pay').val();
var facture = $('#facture').val();
var select_opt = $('#select_opt').val();
if(pay!="")
{
$.ajax({
data: {'selectW': selectW, 'select_at': select_at, 'pay': pay, 'facture': facture, 'select_opt': select_opt},
type: "post",
url: "insert_buy.php",
success: function(response){
if(response=="success")
{
$('#incident_table').append('<tr><td height="30" align="center">' + selectW + '</td><td align="center">' + select_at + '</td> <td align="center" dir="ltr">' + pay + '</td> <td align="center">' + facture + '</td> <td align="center"><form action="delete.php" method="post"><input type="hidden" name="rowid" value="" /><input class="imgClass_dell" type="submit" onclick="return confirm(\'هل أنت متأكد؟\')" name="delete_sales" value="" /></form></td></tr>');
alert(data);
$('#selectW').val('');
$('#select_at').val('');
$('#pay').val('');
$('#facture').val('');
$('#select_opt').val('');
}
else
{
alert("No Data added");
}
},
error: function(){
//alert('error; ' + eval(error));
}
});
}
else
{
alert("All Fields Are Required!!");
}
}
And here is where PHP calculate the sum:
</tr>
</form>
<?php
$sum = 0;
$selectAll = "SELECT * FROM sales WHERE date_now = :date ORDER BY date_now DESC, time_now DESC";
$stmtAll=$conn->prepare($selectAll);
$stmtAll->bindValue(':date', date("y-m-d"));
$execAll=$stmtAll->execute();
$result=$stmtAll->fetchAll();
?>
<?php foreach($result as $rows){
$sum = $sum + $rows['pay'];
//var_Dump($rows) ?>
<tr>
<td height="30" align="center"><?php echo $rows['type'] ?></td>
<td align="center"><?php echo $rows['provider'] ?></td>
<td align="center" dir="ltr"><?php echo (number_format($rows['pay'], 0, ',', ' ')). ' L.L'?></td>
<td align="center"><?php echo $rows['facture'] ?></td>
<td align="center"><form action='delete.php' method="post">
<input type="hidden" name="rowid" value="<?php echo $rows['id'] ?>" />
<input class="imgClass_dell" type="submit" onclick="return confirm('هل أنت متأكد؟')" name="delete_sales" value="" />
</form></td>
</tr>
<?php } ?>
<tr>
<th colspan="4" align="center" bgcolor="#666666">المجموع</th>
<td dir="ltr" bgcolor="#666666" align="center"><?php
echo ($sum = number_format($sum, 0, ',', ' ')). ' L.L';
?></td>
</tr>
</table>
</div>
</div>
I hope I can get some help.
you can try with this
You'll need a getTable.php page that displays your table, and nothing else: no headers, footers, etc.
PHP (getTable.php) - this can be any server side code (asp, html, etc..)
<?php
echo '<table><tr><td>TEST</td></tr></table>';
?>
Then, in your JS, you can easily refresh the table by using the load() method:
HTML
<div id="tableHolder"></div>
js
<script type="text/javascript">
$(document).ready(function(){
refreshTable();
});
function refreshTable(){
$('#tableHolder').load('getTable.php', function(){
setTimeout(refreshTable, 5000);
});
}
</script>
try and good luck i prefer work with jqgrid

Submit Multiple, dynamically created forms but not all

So here we go. I have a page that lists a bunch of unscored sports games. Here is the query I run to generate the page.
<div id="NFL">
<?php
foreach ($conn->query("SELECT * FROM game_data WHERE sport='NFL' AND awayscore IS NULL ORDER BY date DESC") as $NFL) {
echo '<form method="post" action="update_score.php">
<table class="table table-bordered">
';
echo '
<thead>
<tr>
<th width="5%" class="head0">Rotation</th>
<th width="45%" class="head1">Team</th>
<th width="10%" class="head0">Money Line</th>
<th width="10%" class="head1">Spread</th>
<th width="10%" class="head0">Over/Under</th>
<th width="10%" class="head1">Score</th>
</tr>
</thead>';
echo '
<tr>
<td colspan="6">
';
$date = date_create($NFL['date']);
echo date_format($date, 'l F jS Y \# g:iA');
echo '
</td>
</tr>';
echo '
<tr>
<td>'.$NFL['awayrotation'].'</td>
<td>'.$NFL['awayteam'].'</td>
<td>'.$NFL['awaymoneyline'].'</td>';
echo '
<td>
';
if ($NFL['awaymoneyline'] > 0) {
$line = $NFL['line'] * -1;
echo $line;
}
elseif ($NFL['awaymoneyline'] < 0) {
echo $NFL['line'];
} ;
echo '
</td>';
echo '
<td>'.$NFL['total'].'</td>
<td><input type="text" required name="awayscore"></input></td>
</tr>';
echo '
<tr>
<td>'.$NFL['homerotation'].'</td>
<td>'.$NFL['hometeam'].'</td>
<td>'.$NFL['homemoneyline'].'</td>';
echo '
<td>
';
if ($NFL['homemoneyline'] > 0) {
$line = $NFL['line'] * -1;
echo $line;
}
elseif ($NFL['homemoneyline'] < 0) {
echo $NFL['line'];
} ;
echo '
</td>';
echo '
<td>'.$NFL['total'].'</td>
<td><input type="text" required name="homescore"></input></td>
</tr>';
echo '
<tr><td colspan="6" align="right"><input type="hidden" name="id" value="'.$NFL['id'].'"><span style="padding-right:15px"><input type="submit" value="Submit Score"></span></td></tr>
</table>
</form>';
}
?>
</div>
This is what I'm looking to do, I would like to have a button to submit multiple forms. Only though if they have placed a value in the score. Is this possible? I have read about doing multiple forms based off names but these forms are being created dynamically. I look forward to your insight.
here try this
I placed a counter that increments by one per SQL result processed This will also be a key we will use later
The counter is now added to the end of the name fields of the inputs (in front of a "-" to be exploded later)
At the bottom of the script is a little code how I would handle the back end information
<?php
$count = "0";
echo '<form method="post" action="update_score.php"><table class="table table-bordered">';
foreach ($conn->query("SELECT * FROM game_data WHERE sport='NFL' AND awayscore IS NULL ORDER BY date DESC") as $NFL) {
$count = $count+1;
echo '<thead>
<tr>
<th width="5%" class="head0">Rotation</th>
<th width="45%" class="head1">Team</th>
<th width="10%" class="head0">Money Line</th>
<th width="10%" class="head1">Spread</th>
<th width="10%" class="head0">Over/Under</th>
<th width="10%" class="head1">Score</th>
</tr></thead>';
echo '<tr><td colspan="6">';
$date = date_create($NFL['date']);
echo date_format($date, 'l F jS Y \# g:iA');
echo '</td></tr>';
echo '<tr><td>'.$NFL['awayrotation'].'</td><td>'.$NFL['awayteam'].'</td><td>'.$NFL['awaymoneyline'].'</td>';
echo '<td>';
if ($NFL['awaymoneyline'] > 0) {
$line = $NFL['line'] * -1;
echo $line;
}
elseif ($NFL['awaymoneyline'] < 0) {
echo $NFL['line'];
} ;
echo '</td>';
echo '<td>'.$NFL['total'].'</td><td><input type="text" required name="awayscore-$count"></input></td></tr>';
echo '<tr><td>'.$NFL['homerotation'].'</td><td>'.$NFL['hometeam'].'</td><td>'.$NFL['homemoneyline'].'</td>';
echo '<td>';
if ($NFL['homemoneyline'] > 0) {
$line = $NFL['line'] * -1;
echo $line;
}
elseif ($NFL['homemoneyline'] < 0) {
echo $NFL['line'];
} ;
echo '</td>';
echo '<td>'.$NFL['total'].'</td><td><input type="text" required name="homescore-$count"></input></td></tr>';
echo '<tr><td colspan="6" align="right"><input type="hidden" name="id-$count" value="'.$NFL['id'].'"><span style="padding-right:15px">';
}
echo '<input type="hidden" name="count" value="$count">'
echo '<input type="submit" value="Submit Score"></span></td></tr></table></form>'
// back end
$counter = 0;
while ($counter++ < $_POST['count'])
{
$name = $_POST["name-$counter"];
$awayscore = $_POST["awayscore-$counter"];
$homescore = $_POST["homescore-$counter"];
$id = $_POST["id-$counter"]; // considering you may need to get rid of the count
$name = explode("-", $name);
$name = $name[0];
// ect ect
// enter in to data base
//clear all data in strings
}
?>
Sorry about that this was due to haters :|
more to the point yes the back end code is for your passer (the code the form is pointed at)
NB: your PHP style is older than what most use now, close to what I use - just check that all tutorials you use give you references to PHP 5.3 and when in doubt go to php.net and check the function calls for version use - syntax and alternate options

Auto submit php form

I want to submit a form after some interval periodically.
I have tried as follows.
<script language="JavaScript">
function fncAutoSubmitForm()
{
//alert('test alert');
alert("B : "+document.getElementById('myform').id);
document.getElementById('myform').submit();
alert("A : "+document.getElementById('myform').id);
setTimeout("fncAutoSubmitForm();",5000);}
</script>
displayPage.php code as follows
<body onload="fncAutoSubmitForm();">
<form id="myform" name="myform" action="code.php" method="post">
some controls
</form>
</body>
here, "displayPage.php" submits the page to "code.php"
"code.php" performs required action and redirects to "displayPage.php"
It works fine when I dont use autosubmit. i.e. fncAutoSubmitForm() function
but when I use fncAutoSubmitForm() "displayPage.php" disappears
here is the actual code
<form action="code.php" method="post" id="myform" name="myform" onload='setGenLeadId();'>
<tr><td colspan="2"><?php if($row1['lead_call_type']=="C"){echo"<font color=red>CALLBACK Lead</font>";}?></td>
<td align = "right"><strong>Lead Id :</strong> </td>
<!--<td><b><font color="red"></font>Reference Number</b></td>-->
<td align="left"><?php echo "" . $row1['lead_id'] ."";?></td>
</tr>
<tr>
<td align="right" ><b>Name :</b></td>
<td align="left"><input name="custname" id="custname" class="textbox" style="width: 100%;height: 25%;" maxlength="140" type="text" value="<?php echo htmlspecialchars($row1['lead_fname'])?>"></td>
<td align="right"><b>Phone :</b></td>
<td align="left"><input name="phone" id="phone" style="width: 100%;height: 25%;" maxlength="10" type="text" value = "<?php echo "" . $row1['lead_phone1'] ."";?>" ></td>
</tr>
<tr>
<td align="right"><b>City :</b></td>
<td align="left">
<input name="city" id="city" class="textbox" style="width: 100%;height: 25%;" maxlength="140" type="text" value="<?php echo "" . $row1['lead_city'] ."";?>">
</td>
<td align="right"><b>State :</b></td>
<td align="left" >
<input name="state" id="state" class="textbox" style="width: 100%;height: 25%;" maxlength="140" type="text" value="<?php echo "" . $row1['lead_state'] ."";?>">
</td>
</tr>
<tr>
<td align="right"><b>Email-ID :</b></td>
<td align="left" ><input name="email" id="email" style="width: 100%;height: 25%;" class="textbox" type="text" value = "<?php echo "" . $row1['lead_email'] ."";?>"></td>
<td align="right"><b>Source </b></td>
<td ><input type="text" name="source" id = "source" style ="width:100%;resize: none;" maxlength="900" value="<?php echo "". $row1['lead_source'] ."";?>"></td>
</tr>
<tr>
<td align="right"><b>Address : </b></td>
<td>
<textarea type="text" name="address" id = "address" style ="width:100%;resize: none;" maxlength="900" ><?php echo "". $row1['lead_address1'] ."";?></textarea>
</td>
<td align="right"><b>Zip Code :</b></td>
<td align="left"><input name="zip" id="zip" class="textbox" style="width: 100%;height: 25%;" maxlength="140" type="text" value="<?php echo htmlspecialchars($row1['lead_zip'])?>"></td>
<!--<td align="right"><b>Phone :</b></td>
<td align="left"><input name="phone" id="phone" style="width: 100%;height: 25%;" maxlength="10" type="text" value = "<?php //echo "" . $row1['lead_phone1'] ."";?>" ></td>-->
</tr>
<tr>
<td align="right"><b>Rounds :</b></td>
<td>
<?php
$query = mysql_query("SELECT param_field_value,param_field_itemdata FROM cti_service_parameters where param_service_id=$service_id and param_field_name='rounds'");
$k=0;
echo "<select style='width: 100%;' id='rounds' name ='rounds'>";
echo "<option value=".$row1['lead_rounds']." selected>".$row1['lead_rounds']."</option>";
while($row = mysql_fetch_array($query))
{
$value[$k] = $row['param_field_value'];
$item[$k] = $row['param_field_itemdata'];
if($field_val == $item[$k])
echo "<option value='$value[$k]' selected>$value[$k]</option>";
else
echo "<option value='$value[$k]'>$value[$k]</option>";
$k = $k + 1;
}
echo "</select>";
?>
</td>
<td align="right"><b>Preparing For IIT-JEE :</b></td>
<td align="left">
<?php
$query = mysql_query("SELECT param_field_value,param_field_itemdata FROM cti_service_parameters where param_service_id=$service_id and param_field_name='IIT-JEE'");
$k=0;
echo "<select style='width: 100%;' id='PrepIIT' name ='PrepIIT'>";
echo "<option value=".$row1['lead_prep_iit']." selected>".$row1['lead_prep_iit']."</option>";
while($row = mysql_fetch_array($query))
{
$value[$k] = $row['param_field_value'];
$item[$k] = $row['param_field_itemdata'];
if($field_val == $item[$k])
echo "<option value='$value[$k]' selected>$value[$k]</option>";
else
echo "<option value='$value[$k]'>$value[$k]</option>";
$k = $k + 1;
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td align="right"><b>Which Standard :</b></td>
<td align="left" >
<?php
$query = mysql_query("SELECT param_field_value,param_field_itemdata FROM cti_service_parameters where param_service_id=$service_id and param_field_name='standered'");
$k=0;
echo "<select style='width: 100%;' id='standared' name ='standared'>";
echo "<option value=".$row1['lead_standared']." selected>".$row1['lead_standared']."</option>";
while($row = mysql_fetch_array($query))
{
$value[$k] = $row['param_field_value'];
$item[$k] = $row['param_field_itemdata'];
if($field_val == $item[$k])
echo "<option value='$value[$k]' selected>$value[$k]</option>";
else
echo "<option value='$value[$k]'>$value[$k]</option>";
$k = $k + 1;
}
echo "</select>";
?>
</td>
<td align="right"><b>Promo DVD :</b></td>
<td align="left">
<?php
$query = mysql_query("SELECT param_field_value,param_field_itemdata FROM cti_service_parameters where param_service_id=$service_id and param_field_name='PromoDVD'");
$k=0;
echo "<select style='width: 100%;' id='dvd' name ='dvd'>";
echo "<option value=".$row1['lead_dvd']." selected>".$row1['lead_dvd']."</option>";
while($row = mysql_fetch_array($query))
{
$value[$k] = $row['param_field_value'];
$item[$k] = $row['param_field_itemdata'];
if($field_val == $item[$k])
echo "<option value='$value[$k]' selected>$value[$k]</option>";
else
echo "<option value='$value[$k]'>$value[$k]</option>";
$k = $k + 1;
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td align="right"><b>Percentage in 10th :</b></td>
<td align="left" ><input name="tenth" id="tenth" maxlength="5" style="width: 100%;height: 25%;" class="textbox" type="text" value = "<?php echo "" . $row1['lead_tenth'] ."";?>"></td>
<td align="right"><b>Percentage in 12th :</b></td>
<td align="left" ><input name="twelth" id="twelth" maxlength="5" style="width: 100%;height: 25%;" class="textbox" type="text" value = "<?php echo "" . $row1['lead_twelth'] ."";?>"> </td>
<!--<td align="right"><b>Time of Call</b></td>
<td align="left" ><input name="calltime" id="calltime" style="width: 100%;height: 25%;" class="textbox" type="text" value = "<?php// echo "" . $row1['lead_import_batch_start_date'] ."";?>" readonly> </td> -->
</tr>
<tr>
<td align="right"><b>JEE appearing year :</b></td>
<td align="left" >
<?php
$query = mysql_query("SELECT param_field_value,param_field_itemdata FROM cti_service_parameters where param_service_id=$service_id and param_field_name='JeeYear'");
$k=0;
echo "<select style='width: 100%;' id='jeeyear' name ='jeeyear'>";
echo "<option value=".$row1['lead_jee_year']." selected>".$row1['lead_jee_year']."</option>";
while($row = mysql_fetch_array($query))
{
$value[$k] = $row['param_field_value'];
$item[$k] = $row['param_field_itemdata'];
if($field_val == $item[$k])
echo "<option value='$value[$k]' selected>$value[$k]</option>";
else
echo "<option value='$value[$k]'>$value[$k]</option>";
$k = $k + 1;
}
echo "</select>";
?>
</td>
<td align="right"><b>Joined any classes :</b></td>
<td align="left">
<?php
$query = mysql_query("SELECT param_field_value,param_field_itemdata FROM cti_service_parameters where param_service_id=$service_id and param_field_name='JoinedClasses'");
$k=0;
echo "<select style='width: 100%;' id='classes' name ='classes'>";
echo "<option value=".$row1['lead_classes']." selected>".$row1['lead_classes']."</option>";
while($row = mysql_fetch_array($query))
{
$value[$k] = $row['param_field_value'];
$item[$k] = $row['param_field_itemdata'];
if($field_val == $item[$k])
echo "<option value='$value[$k]' selected>$value[$k]</option>";
else
echo "<option value='$value[$k]'>$value[$k]</option>";
$k = $k + 1;
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td align="right"><b>Remarks :</b></td>
<td colspan="3"><textarea type="text" name="remarks" id = "remarks" style ="width:100%;resize: none;" maxlength="900" ><?php echo "". $row1['lead_remarks'] ."";?></textarea> </td>
</tr>
<tr>
<td colspan=4 class="tableHeading">
<!--<b><font color="red">Note : Fields with * are Mandatory</font></b>-->
</td>
</tr>
<!--<input type="hidden" id="clinicFlag" name="clinicFlag" value="<?php// echo $_GET["clinicFlag"]?>">-->
<tr>
<tr>
<td colspan=4 style="padding:0px">
<div align="center">
<input title="Save [Alt+S]" accessKey="S" class="crmbutton small save" type="button" name="save" value=" Save " style="width:100px;height:30px" >
</td>
</div>
</tr>
</table>
</div>
and Code.php code is as follows
<?php
//session_start();
//echo $_SESSION['user'];
include("connection.php");
$lead = $_POST['lead'];
$callnumber = $_POST['callnumber'];
$service = $_POST['service'];
$lead_fname = $_POST['custname'];
$lead_phone1 = $_POST['phone'];
$lead_city = $_POST['city'];
$lead_email = $_POST['email'];
$lead_state = $_POST['state'];
$lead_address1 = $_POST['address'];
$lead_zip = $_POST['zip'];
$lead_rounds = $_POST['rounds'];
$lead_IIT = $_POST['PrepIIT'];
$lead_standared = $_POST['standared'];
$lead_dvd = $_POST['dvd'];
$lead_tenth = $_POST['tenth'];
$lead_twelth = $_POST['twelth'];
$lead_jee_year = $_POST['jeeyear'];
$lead_classes = $_POST['classes'];
$lead_remarks = $_POST['remarks'];
$lead_source = $_POST['source'];
if($GLOBALS['database_type'] == "MySql")
{
$con=mysql_connect($GLOBALS['database_ip'],$GLOBALS['database_username'],$GLOBALS['database_password']);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($GLOBALS['database_name'],$con);
$sql1 = mysql_query("SELECT service_outbound_lead_dsn_string,
service_outbound_lead_db_user,
service_outbound_lead_db_password,
service_leadstructure_master_tablename,
service_outbound_lead_db_name
FROM cti_services WHERE service_id = $service");
while($row = mysql_fetch_array($sql1))
{
$lead_dsn = $row['service_outbound_lead_dsn_string'];
$lead_user = $row['service_outbound_lead_db_user'];
$lead_pwd = $row['service_outbound_lead_db_password'];
$lead_table = $row['service_leadstructure_master_tablename'];
$lead_db = $row['service_outbound_lead_db_name'];
}
if($_POST['save'])
{
//input_app_datetime = '$lead_appointment',
//input_app_reschedule = '$lead_reschedule',
mysql_select_db($GLOBALS['database_name'],$con);
$sqlquery = ("UPDATE $lead_db.$lead_table set lead_fname = '$lead_fname', lead_phone1 = '$lead_phone1', lead_email = '$lead_email', lead_remarks = '$lead_remarks', lead_address1 = '$lead_address1', lead_state = '$lead_state', lead_city = '$lead_city', lead_zip = '$lead_zip', lead_rounds ='$lead_rounds', lead_prep_iit ='$lead_IIT', lead_standared ='$lead_standared', lead_dvd ='$lead_dvd', lead_tenth ='$lead_tenth', lead_twelth ='$lead_twelth', lead_jee_year ='$lead_jee_year', lead_classes ='$lead_classes', lead_source ='$lead_source' WHERE lead_id=$lead");
$dbSql = mysql_query($sqlquery) or die("Error : " . mysql_error());
$sql="update cti_call_master set crm_remarks='$lead_remarks' where call_number=$callnumber";
$dbSql1 = mysql_query($sql);
//$flag = "saved";
$message = "Lead Id-".$lead." Data Saved .....";
//$message = $sqlquery;
//header("location:vision.php?LEADID=$lead&SERVICEID=$service&CALLNUMBER=$callnumber&MESSAGE=$message&FLAG=$flag&CLI=$lead_phone1&clinicFlag=$clinicFlag&alterno=$alter_no");
header("location:displayPage.php?LEADID=$lead&SERVICEID=$service&CALLNUMBER=$callnumber&MESSAGE=$message&FLAG=$flag&CLI=$lead_phone1");
}
}
?>
You can call the following function at 'onload' event. It will submit the form after 5 second to your code.php
function fncAutoSubmitForm() {
setTimeout(function(){
document.getElementById('myform').submit();
}, 5000);
}
Then your code.php will process the form action and redirect it back to displayPage.php.
Can you check if your form is not submitted at all to code.php or it is being submitted to code.php and due to some error it fails to redirect back to displayPage.php. In the later case you can turn ON the display error settings if it is not already ON. Use following in code.php to enable:
error_reporting(E_ALL);
ini_set('display_errors',1);
It it doesn't help then pls provide the code to get the actual scenario here.
As you call fncAutoSubmitForm() onload of displayPage.php, it immediately triggers document.getElementById('myform').submit();
So you are redirected to code.php, the action of your form.
If you want a delay you should not apply fncAutoSubmitForm() onload of the page.
but more something like:
setTimeout("fncAutoSubmitForm();",5000);}
function fncAutoSubmitForm(){
document.getElementById('myform').submit();
}
But you won't stay on displayPage.php it will redirect you to code.php. If you want to always display the same page you needs to change the action target in your form.
Use jQuery :)
$(document).ready(function(){
setInterval(function(){
submit();
}, 1000);
});
function submit(){
var data;
// extract data from your form and save it to data variable
$.ajax({
type: "POST",
url: "some.php",
data: data
});
}

Categories