PHP Ajax Realtime autosave Fwrite to config.txt - php

Im trying to figure this out but its really getting to me 2nd all day on trying code and searching ...
Trying to see guidance if i am getting to the right direction with ajax and autosaving when a user performs an action on the button (BUT i do need to have a config.txt)
Because its more of an Active running application for enabling/disabling an action with custom options needed on the fly.
Trying to (ON page load ) read file config.txt (and auto change the values on the form to what was read from config.txt like a 2 way async (Without reloading the page)
config.txt
active=1
email=1
markets=chi,nyc,orl,sfo
timer=15
emailaddress=test#gmail.com
logviewer=1
so Being that markets has option to add 1 or more i need to post with commas ...
Thus when active=1 is enabled theres a bash script in the background that will be executed based on the selection of the active (when the user checks the box IN REALTIME) ... (onclick)
MAIN HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>....Tools....</title>
<script src="js/ajaxsbmt.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" media="all" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/ui-darkness/jquery-ui.css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
<script type="text/javascript" src="../src/jquery.multiselect.js"></script>
<script type="text/javascript" src="../src/jquery.multiselect.filter.js"></script>
<script type="text/javascript" src="assets/prettify.js"></script>
<link rel="stylesheet" type="text/css" href="../jquery.multiselect.css" />
<link rel="stylesheet" type="text/css" href="assets/style.css" />
<link rel="stylesheet" type="text/css" href="assets/prettify.css" />
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/ui-lightness/jquery-ui.css" />
<script type="text/javascript">
$(function(){
$("select").multiselect({
selectedList: 4
});
$("select").multiselect().multiselectfilter();
});
</script>
<script type="text/javascript">
function autosave()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("poll").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","save.php?data="+data,true);
if (multiple_id == "marketlist")
{
xmlhttp.send($value1","$value2","$value3","$value4",")
// NEED TO FIGURE OUT HOW TO POST it as CHI,ATL,NYC or however many selected with comma seperated values as the line item Hmmmmmmmmm
}
}
</script>
</head>
<body>
<div id="TESTING">
<h3>ENABLE Debug LOG VIEWER</h3>
<form>
Yes:
<input type="radio" id="logger" name="logviewer" value="logger=1" onclick="autosave(this.value)" />
<br />No:
<input type="radio" id="logger" name="logviewer" value="logger=0" onclick="autosave(this.value)" />
</form>
</div>
<div id="page">
<ul>
<li><label for="ch_effects">ENABLE Diaster Script:</label><input type="checkbox" id="ch_enable" name="ch_enable" data-on="Enable" data-off="Disable" onclick="autosave(this.value)" /></li>
Select Markets To be monitored
<form>
<form name="mkts" method="post" action="save.php">
<select name="marketlist" multiple="multiple" style="width:600px">
<option value="CHI">Chicago-CHI</option>
<option value="CHI">Baltimore-BAL</option>
<option value="NYC">New York-NYC</option>
<option value="BDR">Bridgeport-BDR</option>
<option value="PHL">Philadelphia-PHL</option>
<option value="PHL">Pittsburgh-PIT</option>
<option value="ORL">Orlando-ORL</option>
</select>
<input type="submit" id="marketlist" value="what is selected Seperate by Commas" name="submit" onclick="autosave(this.value)" />
</p>
<li><label for="ch_location">Email notifications</label><input type="checkbox" id="ch_emailnotify" name="ch_emailnotify" data-on="ON" data-off="OFF" onchange="autosave(this.value)"/></li>
<li><label for="ch_emails">Realtime log view</label><input type="checkbox" id="ch_logview" name="ch_logview" data-on="Show" data-off="Hide" onchange="autosave(this.value)"/></li>
</ul>
<p>
<div>
<input id="email" name="email" class="element text medium" type="text" maxlength="255" value="" onchange="autosave(this.value)"/>
</div>
<li class="buttons">
<input type="hidden" name="form_id" value="CONFIG" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
</body>
</html>
SAVE.PHP
<?php
$logger = $_REQUEST["logger"];
$active = $_REQUEST["ch_enable"];
$marketlist = $_REQUEST["marketlist"];
$emailnotify = $_REQUEST["ch_emailnotify"];
$filename="config.txt";
$act = "active='$active'";
$log = "logger='$logger'";
$mkt = "markets='$marketlist'";
$eml = "email='$emailnotify'";
$fin=fopen($filename,"w");
fwrite($fin,$content);
if ( $act = "" ) {
$cmd = "grep 'active=' " . $filename;
$output = system($cmd, $result);
$lines = explode("\n", $result);
}
if ( $log != "" ) {
$cmd = "grep 'logger=' " . $filename;
$output = system($cmd, $result);
$lines = explode("\n", $result);
}
if ( $mkt != "" ) {
$cmd = "grep 'markets=' " . $filename;
$output = system($cmd, $result);
$lines = explode("\n", $result);
}
if ( $eml != "" ) {
$cmd = "grep 'email=' " . $filename;
$output = system($cmd, $result);
$lines = explode("\n", $result);
}
fclose($fin);
echo "Data saved";
?>

Related

Writing form to a text file PHP

I'm new here.
Anyway, I'm working on an application system that logs your answers to the form into a text file called data.txt It was working for a while and then I tinkered with some stuff and it's not working anymore.
<html>
<head>
<link rel="stylesheet" href="style.css"
<meta charset="utf-8">
<title>Apply</title>
<link rel="icon" type="image/png" href="favicon.png">
</head>
<body>
<h1 class="unselectable">PvPCity Application</h1>
<form target=_blank action="index.php" method="post">
<input type="text" name="IGN" placeholder="IGN" autocomplete="off"><br>
<input type="text" name="Discord" placeholder="Discord" autocomplete="off"><br>
<input type="text" name="Age" placeholder="Age" autocomplete="off">
<textarea name="Why" placeholder="Why do you want to be staff?" autocomplete="off"></textarea>
<input onclick="window.location.href = 'http://pvpcity.dx.am/submitted/index.html';" type="submit" value="Apply" />
</form>
</body>
</html>
<?php
if( isset($_POST['IGN'] ) && isset( $_POST['Discord'] ) && isset( $_POST['Age'] ) && isset( $_POST['Why'] ) )
{
$txt=' ##### IGN: '.$_POST['IGN'].' ##### Discord: '.$_POST['Discord'].' ##### Age: '.$_POST['Age'].' ##### Why: '.$_POST['Why'] . PHP_EOL;
file_put_contents('data.txt', $txt, FILE_APPEND);
}
?>
Here is the code.
If you could tell me what is wrong that would be great.
The code here is from index.php
The submit button redirects to a different page when you click.
I honestly have no idea why it's not working
You should allow PHP to perform the redirection rather than allow people to potentially spoof others from your site. That said - you can simplify the collection of POSTed data a little by processing the POST array. The form will submit OK and redirect but the remote site will perhaps inaccurately report back that the application has been submitted - presumably this will be hosted on that site also so not necessarily an issue.
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' ){
$payload=array();
foreach( $_POST as $field => $value )$payload[]=sprintf('##### %s %s', $field, $value );
file_put_contents( 'data.txt', implode( ' ',$payload ).PHP_EOL, FILE_APPEND );
header('Location: http://pvpcity.dx.am/submitted/index.html');
}
?>
<html>
<head>
<link rel="stylesheet" href="style.css"
<meta charset="utf-8">
<title>Apply</title>
<link rel="icon" type="image/png" href="favicon.png">
</head>
<body>
<h1 class="unselectable">PvPCity Application</h1>
<form target=_blank method="post">
<input type="text" name="IGN" placeholder="IGN" autocomplete="off"><br>
<input type="text" name="Discord" placeholder="Discord" autocomplete="off"><br>
<input type="text" name="Age" placeholder="Age" autocomplete="off">
<textarea name="Why" placeholder="Why do you want to be staff?" autocomplete="off"></textarea>
<input type="submit" value="Apply" />
</form>
</body>
</html>
I believe you don't need onclick="window.location.href = ... Your submission can go to same file (index.php), you just need a better condition and since your inputs are not marked as required you might use something like this:
<?php
if(!empty($_POST)){
$txt = '';
foreach ($_POST as $key => $value){
$txt = $txt. " ##### ".$key.': '.$value;
}
file_put_contents('data.txt', $txt, FILE_APPEND);
}
?>
<html>
<head>
<link rel="stylesheet" href="style.css"
<meta charset="utf-8">
<title>Apply</title>
<link rel="icon" type="image/png" href="favicon.png">
</head>
<body>
<h1 class="unselectable">PvPCity Application</h1>
<form target=_blank action="" method="post">
<input type="text" name="IGN" placeholder="IGN" autocomplete="off"><br>
<input type="text" name="Discord" placeholder="Discord" autocomplete="off"><br>
<input type="text" name="Age" placeholder="Age" autocomplete="off">
<textarea name="Why" placeholder="Why do you want to be staff?" autocomplete="off"></textarea>
<input type="submit" value="Apply" />
</form>
</body>
</html>
<?php
if( isset($_POST['IGN'] ) && isset( $_POST['Discord'] ) && isset( $_POST['Age'] ) && isset( $_POST['Why'] ) )
{
$txt=' ##### IGN: '.$_POST['IGN'].' ##### Discord: '.$_POST['Discord'].' ##### Age: '.$_POST['Age'].' ##### Why: '.$_POST['Why'] . PHP_EOL;
if(file_put_contents('data.txt', $txt, FILE_APPEND)){
header('Location: http://pvpcity.dx.am/submitted/index.html');
}else{
echo 'data is not saved';
}
}
?>
I did some alteration in that above code for redirect to another website. You don't want to redirect on click, you can do that via PHP header().
header('Location: http://pvpcity.dx.am/submitted/index.html');
This will redirect after submit the form...

Getting data from another URL using form input and reading that data

I am trying to do something that I think should be relatively straightforward but I am not sure exactly how to do it and despite much searching and looking through examples, I am still not sure how to do it.
I have a form which has a date input field and a days (7/14) selector and when the use changes either the date or the days it should query a separate URL and then return the results.
The problem I have is:
How to select date/days in the form but read the URL and not redirect the user but refresh the page to echo the results from reading the URL?
I have put together a simple example to show what I mean:
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>$( function() { $( "#datepicker" ).datepicker(); } ); </script>
</head>
<body>
<?php
// Example fully formatted URL
http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=2017-06-23&days=7
// http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=[DATESELECTED]&days=[DAYSSELECTED]
?>
<form action="http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&" method="GET">
<input class="datepicker" type="text" id="datepicker" name="date" value="">
<select><option value="7" id="days" name="days">7 days</option><option value="14">14 days</option></select>
<input type="hidden" name="c" value="3" />
<input type="submit" />
</form>
</body>
<?php
// Read contents of the URL
// dateselected = datepicker output
//$angelfish = file_get_contents('http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=' . $dateselected . '&days=' . $days);
// Display contents of the URL, i.e.
echo '<hr>';
echo 'Show example output that we are trying to achieve using above
selection but with defaults of date today and days of 7.';
echo '<br /><br />';
$dateselected = date('Y-m-d');
$daysselected = '7';
$angelfish = file_get_contents('http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=' . $dateselected . '&days=' . $daysselected);
echo $angelfish;
//At this point we'll format nicely with coloured rows, etc
?>
</body>
Would someone be able to point me in the right direction?
Many thanks,
Rob
<pre>Please use below code <?php
$dateselected = date('Y-m-d');
$daysselected = '7';
if(isset($_POST['date']) && isset($_POST['days'])){
$dateselected=date('Y-m-d',strtotime($_POST['date']));
$daysselected = $_POST['days'];
}
?>
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>$( function() { $( "#datepicker" ).datepicker(); } ); </script>
</head>
<body>
<?php
// Example fully formatted URL
http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=2017-06-23&days=7
// http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=[DATESELECTED]&days=[DAYSSELECTED]
?>
<form name="form1" method="POST">
<input class="datepicker" type="text" id="datepicker" name="date" value="">
<select name="days"><option value="7" id="days" name="days">7 days</option><option value="14">14 days</option></select>
<input type="hidden" name="c" value="3" />
<input type="submit" />
</form>
</body>
<?php
// Read contents of the URL
// dateselected = datepicker output
//$angelfish = file_get_contents('http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=' . $dateselected . '&days=' . $days);
// Display contents of the URL, i.e.
echo '<hr>';
echo 'Show example output that we are trying to achieve using above
selection but with defaults of date today and days of 7.';
echo '<br /><br />';
echo 'http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=' . $dateselected . '&days=' . $daysselected."<bR>";
$angelfish = file_get_contents('http://www.angelfishbooking.co.uk/feeds/roomavailability.aspx?id=Belle_Tout&date=' . $dateselected . '&days=' . $daysselected);
echo $angelfish;
//At this point we'll format nicely with coloured rows, etc
?>
</body></pre>

Change href in another PHP page using a variable

I'm brand new to this and trying to scab together two different ideas. Each of them work individually, but I'm trying to integrate them.
I am able to upload and image (which creates a list itme with an href="javascript:void(0).
I can allow user input to assign a url to an existing text link.
what I'm trying to do is target the dynamically created list item in the upload.php page and change the href="javascript:void(0) to the user specified variable from index.php
index.php code
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>image upload</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="jquery.form.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#images').on('change',function(){
$('#multiple_upload_form').ajaxForm({
target:'#images_preview',
beforeSubmit:function(e){
$('.uploading').show();
},
success:function(e){
$('.uploading').hide();
},
error:function(e){
}
}).submit();
});
});
</script>
</head>
<body>
<div style="margin-top:50px;">
<div class="upload_div" >
<form name="multiple_upload_form" id="multiple_upload_form" enctype="multipart/form-data" action="upload.php">
<input type="hidden" name="image_form_submit" value="1"/>
<label>Choose Image</label>
<input type="file" name="images[]" id="images" multiple >
<div class="uploading none">
<label> </label>
<img src="uploading.gif"/>
</div>
</form>
</div>
<div class="gallery" id="images_preview">
</div>
</div>
<div class="form_div" id="url_input">
<form id="form1">
URL - example http://www.yourdomain.com: <input name="name" type="text" size="20">
</form>
<button onclick="outputname()">Submit</button>
<script>
function outputname() {
var x,y,name,a,b,answer;
x=document.getElementById("form1") ;
y=x.elements["name"].value;
document.getElementById("upload.php#web").setAttribute("href",y);
}
</script>
<p id="demo">
<a id="link">this is a link</a>
</p>
</div>
</body>
</html>
upload.php code
<?php
if($_POST['image_form_submit'] == 1)
{
$images_arr = array();
foreach($_FILES['images']['name'] as $key=>$val){
$image_name = $_FILES['images']['name'][$key];
$tmp_name = $_FILES['images']['tmp_name'][$key];
$size = $_FILES['images']['size'][$key];
$type = $_FILES['images']['type'][$key];
$error = $_FILES['images']['error'][$key];
############ Remove comments if you want to upload and stored images into the "uploads/" folder #############
/*$target_dir = "uploads/";
$target_file = $target_dir.$_FILES['images']['name'][$key];
if(move_uploaded_file($_FILES['images']['tmp_name'][$key],$target_file)){
$images_arr[] = $target_file;
}*/
//display images without stored
$extra_info = getimagesize($_FILES['images']['tmp_name'][$key]);
$images_arr[] = "data:" . $extra_info["mime"] . ";base64," . base64_encode(file_get_contents($_FILES['images']['tmp_name'][$key]));
}
//Generate images view
if(!empty($images_arr)){ $count=0;
foreach($images_arr as $image_src){ $count++?>
<ul class="reorder_ul reorder-photos-list">
<li id="image_li_<?php echo $count; ?>" class="ui-sortable-handle">
<img src="<?php echo $image_src; ?>" alt="">
</li>
</ul>
<?php }
}
}
?>
Like I said, I'm brand new to this and there may be a far more elegant solution, but I've gotten this far from just hunting and pecking... thanks in advance for any help.

PHP form to CSV with multiple entries

I am trying to create a simple online form using html and php tooutput to a .csv. I have no problem doing this for a single form but the users of this form will usually have multiple entries at once. To make it easier for them I am using a form of which you can add lines to submit more entries in one submission. Below is the HTML and PHP code.
The issue I am having is the PHP part. I can only get it to ever submit the first entry.
Any ideas? I have a working version of the site/form here, but again, only the first entry every gets entered into the .csv. Thanks for the help.
HTML:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="mdcstyle.css" />
<title>Submission form</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type='text/javascript'>
//<![CDATA[
$(document).ready(function() {
var currentItem = 0;
$('#addnew').click(function(){
currentItem++;
$('#items').val(currentItem);
var strToAdd = '<tr><td>Area:<input class="textfield" name="area'+currentItem+'" id ="area'+currentItem+'"type="text" /></td><td>Contractor:<input class="textfield" name="contractor'+currentItem+'" id ="contractor'+currentItem+'"type="text" /></td></tr>';
$('#data').append(strToAdd);
});
});
//]]>
</script>
</head>
<body>
<div class="content">
<h2>header text</h2>
<p>Please complete this form for Udpates. Add a new line if you have more than one project.</p>
<form id="myform" name="form1" method="post" action="signup2.php">
<table class="dd" width="100px" id="data">
<tr>
<td>Area:<input class="textfield" name="area0" id="area0" type="text" /></td>
<td>Contractor:<input class="textfield" name="contractor0" id="contractor0" type="text" /></td>
</tr>
</table>
<input class="subbutton" type="submit" name="Submit" value="Submit Form">
</form>
<button id="addnew" name="addnew" value="Add new item">Add new entry</button>
<input type="hidden" id="items" name="items" value="1" />
<br>
</div>
</body>
</html>
PHP:
<?php
for( $i = 0; $i <= $count; $i++ )
{
date_default_timezone_set('America/New_York');
$today = date("m.d.y");
$area0 = $_POST['area'.$i];
//the data
$data = "$today, $area0, $contractor, $hours, $project, $town, $street\n";
//open the file and choose the mode
$fh = fopen("users2.csv", "a");
fwrite($fh, $data);
//close the file
fclose($fh);
}
?>
Well, if this is all of the code and you didn't leave anything out I'd say you need to initialize $count.
Also, I'd probably open the file handle before the loop and close it after the loop instead of needlessly opening and closing it.
Edit - adding code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="mdcstyle.css" />
<title>Submission form</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type='text/javascript'>
//<![CDATA[
$(document).ready(function() {
var currentItem = 0;
$('#addnew').click(function(){
currentItem++;
$('#items').val(currentItem);
var strToAdd = '<tr><td>Area:<input class="textfield" name="area['+currentItem+']" id =" area['+currentItem+']" type="text" /></td><td>Contractor:<input class="textfield" name="contractor['+currentItem+']" id ="contractor['+currentItem+']"type="text" /></td></tr>';
$('#data').append(strToAdd);
});
});
//]]>
</script>
</head>
<body>
<div class="content">
<h2>header text</h2>
<p>Please complete this form for Udpates. Add a new line if you have more than one project.</p>
<form id="myform" name="form1" method="get" action="signup2.php">
<table class="dd" width="100px" id="data">
<tr>
<td>Area:<input class="textfield" name="area[0]" id="area[0]" type="text" /></td>
<td>Contractor:<input class="textfield" name="contractor[0]" id="contractor[0]" type="text" /></td>
</tr>
</table>
<input class="subbutton" type="submit" name="Submit" value="Submit Form">
</form>
<button id="addnew" name="addnew" value="Add new item">Add new entry</button>
<input type="hidden" id="items" name="items" value="1" />
<br>
</div>
</body>
</html>
php:
<?php
$area = $_GET['area'];
$count = count($area);
//open the file and choose the mode
$fh = fopen("users2.csv", "a");
for( $i = 0; $i <= $count; $i++ )
{
date_default_timezone_set('America/New_York');
$today = date("m.d.y");
$area0 = $area[$i];
//the data
$data = "$today, $area0, $contractor, $hours, $project, $town, $street\n";
fwrite($fh, $data);
}
fclose($fh);
?>
I just made the minimal edits, you aren't using anything but the area variable from your form, and there are a lot of values you have listed that aren't initialized anywhere (hours, project, etc). Also, I haven't got access to anyplace to do actual php code right now, and this is from memory, so there may be typos/etc.

searching a solution to get/post DOUBLE DATA SUBMISSION [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Avoiding form resubmit in php when pressing f5
I need help on how to prevent the DOUBLE DATA SUBMISSION to mysql database.
This usually occurs when after the submit, user hits REFRESH button.
Whenever I send data using html web forms to handle them in sever side I'd better omit action attribute of a form which explains that the file will be processed by itself and starting from the first line i place server side php scripts. Before sending data I sctrictly check if all fields are filled correctly and then send that data to future processing. Using php script I'll check if web form button which was clicked is not null and then via established connection to mysql execute manipulation queries.
Is using header function to redirect to itself is an optimal way to prevent Double Data Submission???
Haven't you any ideas?
In addition I'll include the code
<?php
include_once '../config.php';
include_once '../functions.php';
if (isset($_POST['bDep'])){
$flt=$_POST['flt'];
$num=$_POST['fltNum'];
$acr=$_POST['acr'];
$city=$_POST['city'];
$fTime=$_POST['fTime'];
$bReg=$_POST['bReg'];
$eReg=$_POST['eReg'];
$acomp=$_POST['aircomp'];
$gate=$_POST['gate'];
$dte=$_POST['data'];
$tm=explode(":",$fTime);
if ($tm[0]<3) $p=1;
else $p=0;
$otmena=$_POST['cancel'];
if ($otmena==1) $stat=4;
else $stat=7;
$sql="INSERT INTO fltdep(FID, FLT, NUM, DEP, TO_FROM, IN_OUT, dte, Stat, BReg, EReg, Gate, AType, ALn, Cir, Hide ) VALUES (0, '$flt', '$num','$fTime', $city,1, '$dte',$stat,'$bReg','$eReg','$gate',$acr,$acomp,$p,0)";
if (mysql_query($sql)){
echo "<p style='text-color:red;text-align:center;'>Успешно добавлена запись № </p>";
}else {
echo "<p style='text-color:red;text-align:center;'>Ощибка при добавлении к базе</p>";
}
unset($_POST['bDep']);
unset($_POST['flt']);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Заполнение вылетов</title>
<link rel="stylesheet" href="../css/validationEngine.jquery.css" type="text/css"/>
<link rel="stylesheet" href="../css/template.css" type="text/css"/>
<link rel="stylesheet" href="../themes/base/jquery.ui.all.css" type="text/css">
<link rel="stylesheet" href="../themes/base/flts.css" type="text/css">
<link rel="stylesheet" href="../themes/base/tipsy.css" type="text/css" />
<link rel="stylesheet" href="../themes/base/tipsy-main.css" type="text/css" />
<link href="../themes/base/table.css" rel="stylesheet" type="text/css" />
<script src="../js/jquery-1.6.min.js" type="text/javascript"></script>
<script src="../js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/jquery.maskedinput-1.3.js" type="text/javascript"></script>
<script src="../ui/jquery.ui.core.js"></script>
<script src="../ui/jquery.ui.widget.js"></script>
<script src="../ui/jquery.ui.button.js"></script>
<script src="../ui/jquery.ui.tabs.js"></script>
<script src="../ui/jquery.ui.datepicker.js"></script>
<script type="text/javascript" language="javascript">
jQuery(document).ready(function(){
// binds form submission and fields to the validation engine
$("#data").datepicker({ numberOfMonths: 1, dateFormat: 'yy-mm-dd' });
jQuery("#Departures").validationEngine();
});
$(function(){
$('#fTime').mask('99:99',{placeholder:"_"});
$('#bReg').mask('99:99',{placeholder: "_"});
$('#eReg').mask('99:99',{placeholder: "_"});
});
function SetAline()
{
var fl=new String($('#flt').val());
if (fl.substr(0,2)=='TD' || fl.substr(0,2)=='td' ) { $('#aircomp').val(1); $('#gate').val(2);}
else if (fl.substr(0,2)=='TJ' || fl.substr(0,2)=='tj' ) { $('#aircomp').val(1); $('#gate').val(1);}
else if (fl.substr(0,2)=='SM' || fl.substr(0,2)=='sm' ) { $('#aircomp').val(2); $('#gate').val(1);}
else if (fl.substr(0,2)=='SB' || fl.substr(0,2)=='sb' ) { $('#aircomp').val(3); $('#gate').val(1);}
else if (fl.substr(0,2)=='OR' || fl.substr(0,2)=='or' ) { $('#aircomp').val(4); $('#gate').val(1);}
else if (fl.substr(0,2)=='TA' || fl.substr(0,2)=='ta' ) { $('#aircomp').val(5); $('#gate').val(1);}
else if (fl.substr(0,2)=='SV' || fl.substr(0,2)=='sv' ) { $('#aircomp').val(6); $('#gate').val(1);}
else if (fl.substr(0,2)=='UT' || fl.substr(0,2)=='ut' ) { $('#aircomp').val(7); $('#gate').val(1);}
else if (fl.substr(0,2)=='SD' || fl.substr(0,2)=='sd' ) { $('#aircomp').val(8); $('#gate').val(1);}
else if (fl.substr(0,2)=='YA' || fl.substr(0,2)=='ya' ) { $('#aircomp').val(9); $('#gate').val(1);}
else if (fl.substr(0,2)=='CS' || fl.substr(0,2)=='cs' ) { $('#aircomp').val(10);$('#gate').val(1);}
else if (fl.substr(0,2)=='D9' || fl.substr(0,2)=='d9' ) { $('#aircomp').val(11);$('#gate').val(1);}
}
function SetRegTime()
{
var depTime=$('#fTime').val();
var fl=new String($('#flt').val());
var start,end;
if (fl.substr(0,2)=='TD' || fl.substr(0,2)=='td'){
start='01:30';
end='00:20';
}else {
start='03:00';
end='00:40';
}
$('#bReg').val(TimeDiff(depTime,start));
$('#eReg').val(TimeDiff(depTime,end));
}
function TimeDiff(a,b)
{
var first = a.split(":")
var second = b.split(":")
var xx;
var yy;
if(parseInt(first[0]) < parseInt(second[0])){
if(parseInt(first[1]) < parseInt(second[1])){
yy = parseInt(first[1]) + 60 - parseInt(second[1]);
xx = parseInt(first[0]) + 24 - 1 - parseInt(second[0])
}else{
yy = parseInt(first[1]) - parseInt(second[1]);
xx = parseInt(first[0]) + 24 - parseInt(second[0])
}
}else if(parseInt(first[0]) == parseInt(second[0])){
if(parseInt(first[1]) < parseInt(second[1])){
yy = parseInt(first[1]) + 60 - parseInt(second[1]);
xx = parseInt(first[0]) + 24 - 1 - parseInt(second[0])
}else{
yy = parseInt(first[1]) - parseInt(second[1]);
xx = parseInt(first[0]) - parseInt(second[0])
}
}else{
if(parseInt(first[1]) < parseInt(second[1])){
yy = parseInt(first[1]) + 60 - parseInt(second[1]);
xx = parseInt(first[0]) - 1 - parseInt(second[0])
}else{
yy = parseInt(first[1]) - parseInt(second[1]);
xx = parseInt(first[0]) - parseInt(second[0])
}
}
if(xx < 10)
xx = "0" + xx
if(yy < 10)
yy = "0" + yy
return (xx + ":" + yy);
}
</script>
</head>
<body>
<form id="Departures" class="formular" method="post" action="">
<fieldset>
<legend>
ЗАПОЛНЕНИЕ ВЫЛЕТОВ <i>Прилет</i>
</legend>
<label>
<span>Дата : </span>
<input class="validate[required] text-input" type="text" name="data" id="data" maxlength="12" value="<? (isset($_POST['data']))?($_POST['data']): date('Y-m-d') ;?>" />
</label>
<label>
<span>Рейс : </span>
<input value="" class="validate[required] text-input" type="text" name="flt" id="flt" maxlength="5" onkeyup="SetAline();"/>
</label>
<label>
<label>
<span>№ рейса : </span>
<input value="" class="validate[required] text-input" type="text" name="fltNum" id="fltNum" maxlength="5"/>
</label>
<label>
<span>Тип ВС :</span>
<select name="acr" id="acr" class="validate[required]">
<option value="">Выберите</option>
<?php
$AC= & getAC();
while ($rowAC=mysql_fetch_array($AC)){
$i++;
echo "<option value='".$rowAC['acode']."'>".$rowAC['name_ru']."</option>";
}
?>
</select>
</label>
<label>
<span>А/П прибт :</span>
<select name="city" id="city" class="validate[required]">
<option value="">Выберите</option>
<?php
$city= & getCity();
while ($rowCi=mysql_fetch_array($city)){
$i++;
echo "<option value='".$rowCi['code']."'>".$rowCi['abbr_ru']."</option>";
}
?>
</select>
</label>
<label>
<label>
<span>Время отправления : </span>
<input value="" class="validate[required] text-input" type="text" name="fTime" id="fTime" maxlength="5" onBlur="SetRegTime();"/>
</label>
<label>
<label>
<span>Начало регистрации : </span>
<input value="" class="validate[required] text-input" type="text" name="bReg" id="bReg" maxlength="5" readonly="readonly" />
</label>
<label>
<label>
<span>Конец регистрации : </span>
<input value="" class="validate[required] text-input" type="text" name="eReg" id="eReg" maxlength="5" readonly="readonly"/>
</label>
<label>
<span>Авиакомпания :</span>
<select name="aircomp" id="aircomp" class="validate[required]">
<option value="">Выберите авиакомпанию</option>
<option value="option1">Таджик Эйр</option>
<?php
$Aline= & getAComp();
while ($rowAline=mysql_fetch_array($Aline)){
$i++;
echo "<option value='".$rowAline['acode']."'>".$rowAline['name_ru']."</option>";
}
?>
</select>
</label>
<label>
<span>Терминал :</span>
<select name="gate" id="gate" class="validate[required]">
<option value="">Выберите</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</label>
<label>
<span>Отмена</span>
<input class="checkbox" type="checkbox" name="cancel" id="cancel" value="1"/>
</label>
</fieldset>
<input name="bDep" class="submit" type="submit" value="Заполнить"/><hr/>
</form>
</body>
</html>
Your method (Header redirect after post) is necessary, but insufficient.
Some users press links twice (doubleclick). And your code sometimes might insert the same record twice in this case. You need to write a JavaScript that would disable submit button after first click.

Categories