I wish every time I reload or refresh the page. The disabled textbox still disabled. Because my purpose is to modify the textbox once time and then it will be disabled forever. Is this possible?
Below is my code
<tr>
<td><?php echo $lang_txt['leader_id'][$lang]; ?></td>
<td>:</td>
<td><?php if($_POST['txtLeaderID'] == ""){?><input type="text" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="<?php echo $merchant['LeaderID']; ?>" maxlength="20" /><?php }
else
{
?>
<input type="text" disabled="disabled" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="<?php echo $merchant['LeaderID']; ?>" maxlength="20" /><?php
}
?>
</td>
</tr>
Your variant will be worked with
if(!$_POST['txtLeaderID']){echo('<input type="text" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="'.$merchant['LeaderID'].'" maxlength="20" />')} else {echo('<input type="text" disabled="disabled" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="'.$merchant['LeaderID'].'" maxlength="20" />')}
For example:
<?php
if (!$_POST['username']){
echo('
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
Name: <input type="text" name="username" /><br />
Email : <input type="text" name="email" /><br />
<input type="submit" name="submit" value="Send POST!" />
</form>
');}
else{
echo('
<form>
Name: <input type="text" name="username" disabled="disabled"/><br />
Email : <input type="text" name="email" disabled="disabled"/><br />
</form>
');}
?>
But it didn't work, if we open it in a new tab. You must save this propery anywhere (session, cookie, sql)and check the stored values. it will be work in a new tab.
For example with session:
<?php
session_start();
if (!isset($_SESSION['data'])) {
$_SESSION['data'] = true;
echo('
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
Name: <input type="text" name="username" /><br />
Email : <input type="text" name="email" /><br />
<input type="submit" name="submit" value="Send POST!" />
</form>
');}
else{
echo('
<form>
Name: <input type="text" name="username" disabled="disabled"/><br />
Email : <input type="text" name="email" disabled="disabled"/><br />
</form>
');}
?>
Related
Can anyone help me to get the addition of Basic Salary and Allowance I and insert it in Total Day Rate without clicking a button. here's my php code.
Here's a Screen Shot of my UI.
Code :
<?php
$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("laboursalary", $connection);
if(isset($_POST['submit'])){
$ID = $_POST['ID'];
$Name = $_POST['Name'];
$Location = $_POST['Location'];
$Category = $_POST['Category'];
$LabourSupplier = $_POST['LabourSupplier'];
$Home = $_POST['Home'];
$Mobile = $_POST['Mobile'];
$BasicSalary = $_POST['BasicSalary'];
$Allowance1 = $_POST['Allowance1'];
$Allowance2 = $_POST['Allowance2'];
$DayRate = $_POST['$DayRate'];
$OTrate = $_POST['OTrate'];
if($ID !=''||$Name !=''){
$query = mysql_query("insert into attendance(ID, Name, Location, Category,LabourSupplier,Home,Mobile,BasicSalary,Allowance1,Allowance2,DayRate,OTrate) values ('$ID','$Name','$Location','$Category','$LabourSupplier','$Home','$Mobile','$BasicSalary','$Allowance1','$Allowance2','$DayRate','$OTrate')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
mysql_close($connection);
?>
After I enter the values for Basic Salary and Allowance 1, I want to get the addition of those two in Day Rate automatically.
this is my HTML code.
<form id="details" action="" method="POST">
<fieldset> ID:
<input class="input" type="text" name="ID" value="" />
</fieldset>
<fieldset> Name:
<input class="input" type="text" name="Name" value="" />
</fieldset>
<fieldset> Location:
<input class="input" type="text" name="Location" value="" />
</fieldset>
<fieldset> Category:
<input class="input" type="text" name="Category" value="" />
</fieldset>
<fieldset> Labour Supplier:
<input class="input" type="text" name="LabourSupplier" value="" />
</fieldset>
<fieldset> Telephone:
<input class="input" type="text" name="Home" value="" />
</fieldset>
<fieldset>Mobile:
<input class="input" type="text" name="Mobile" value="" />
</fieldset>
<fieldset> Basic Salary:
<input class="input" type="number" name="BasicSalary" value="" />
</fieldset>
<fieldset> Allowance I:
<input class="input" type="number" name="Allowance1" value="" />
</fieldset>
<fieldset>Allowance II:
<input class="input" type="number" name="Allowance2" value="" />
</fieldset>
<fieldset>Total Day Rate:
<input class="input" type="number" name="DayRate" value="" />
</fieldset>
<fieldset>OT Rate:
<input class="input" type="number" name="OTrate" value="" />
</fieldset>
<fieldset>
<button name="submit" type="submit" id="submit">Insert</button>
<button onclick="goBack()" name="Back" type="back" id="details-back">Back</button>
</fieldset>
</form>
As I understood your question, your HTML code should be like,
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<form id="details" action="" method="POST">
<fieldset> ID:
<input class="input" type="text" name="ID" value="" />
</fieldset>
<fieldset> Name:
<input class="input" type="text" name="Name" value="" />
</fieldset>
<fieldset> Location:
<input class="input" type="text" name="Location" value="" />
</fieldset>
<fieldset> Category:
<input class="input" type="text" name="Category" value="" />
</fieldset>
<fieldset> Labour Supplier:
<input class="input" type="text" name="LabourSupplier" value="" />
</fieldset>
<fieldset> Telephone:
<input class="input" type="text" name="Home" value="" />
</fieldset>
<fieldset>Mobile:
<input class="input" type="text" name="Mobile" value="" />
</fieldset>
<fieldset> Basic Salary:
<input class="input" type="number" name="BasicSalary" value="0" id="bassal" />
</fieldset>
<fieldset> Allowance I:
<input class="input" type="number" name="Allowance1" value="0" id="all1" />
</fieldset>
<fieldset>Allowance II:
<input class="input" type="number" name="Allowance2" value="0" id="all2" />
</fieldset>
<fieldset>Total Day Rate:
<input class="input" type="number" name="DayRate" value="" id="DayRate" />
</fieldset>
<fieldset>OT Rate:
<input class="input" type="number" name="OTrate" value="" />
</fieldset>
<fieldset>
<button name="submit" type="submit" id="submit">Insert</button>
<button onclick="goBack()" name="Back" type="back" id="details-back">Back</button>
</fieldset>
</form>
<script >
$(document).ready(function (){
$('#bassal').on('input', function() {
$('#DayRate').val(parseInt($('#bassal').val()) + parseInt($("#all1").val()) + parseInt($("#all2").val()));
});
$('#all1').on('input', function() {
$('#DayRate').val(parseInt($('#bassal').val()) + parseInt($("#all1").val()) + parseInt($("#all2").val()));
});
$('#all2').on('input', function() {
$('#DayRate').val(parseInt($('#bassal').val()) + parseInt($("#all1").val()) + parseInt($("#all2").val()));
});
});
</script>
I've added jQuery, that does your work, and you don't need to do addition on PHP side.
This is how it would be done using a submit for post as these are all _POST values... Though to accomplish this without pressing a button would be JS/Angular/J Query/AJAX...
....
$BasicSalary = $_POST['BasicSalary'];
$Allowance1 = $_POST['Allowance1'];
$Allowance2 = $_POST['Allowance2'];
$DayRate = $_POST['$DayRate'];
$OTrate = $_POST['OTrate'];
//Set a new variable with the addition of the two `Basic Salary` and `Allowance 1`
//for the insertion into your column `dayRate`
$adustedDayRate = $BasicSalary + $Allowance1;
if($ID !=''||$Name !=''){
if($query != false){
$query = mysql_query("INSERT INTO `attendance` (ID, Name, Location, Category,LabourSupplier,Home,Mobile,BasicSalary,Allowance1,Allowance2,DayRate,OTrate) values ('$ID','$Name','$Location','$Category','$LabourSupplier','$Home','$Mobile','$BasicSalary','$Allowance1','$Allowance2','$adustedDayRate','$OTrate')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}esle{ $_SESSION['err'] = "ERROR: ".--- MySQL error handle here --- }
}
else{
echo "Some Fields are Blank....!!</p>";
}
}
mysql_close($connection);
Using Angular, you could place a placeholder element in your form input for `DayRate, then add the call back for the ng-model element for the two inputs you wish to add. Something like this here:
<div ng-app="">
<p>BasicSalary : <input type="number" ng-model="BasicSalary" placeholder="Basic Salary"></p>
<p>AllowanceI : <input type="number" ng-model="AllowanceI" placeholder="Allowance I"></p>
<p>DayRate : <input type="number" ng-model="DayRate" placeholder="{{BasicSalary -- AllowanceI}}"></p>
Your code would look like:
<fieldset> Basic Salary:
<input class="input" type="number" ng-model="BasicSalary" name="BasicSalary" value="" />
</fieldset>
<fieldset> Allowance I:
<input class="input" type="number" ng-model="Allowance1" name="Allowance1" value="" />
</fieldset>
<fieldset>Allowance II:
<input class="input" type="number" name="Allowance2" value="" />
</fieldset>
<fieldset>Total Day Rate:
<input class="input" type="number" name="DayRate" placeholder="{{ BasicSalary -- Allowance1 }}" value="" />
</fieldset>
Here is a working fiddle of the angular method, simply add the angular library to your server using composer or hosted links, no additional JS is required with the Angular library elements. You can change the value of DayRate as the two other combining inputs are being input.
https://jsfiddle.net/qkpfb90o/1/
Hope this helps!
You can also try with this.
<form id="details" action="" method="POST">
<fieldset> ID:
<input class="input" type="text" name="ID" value="" />
</fieldset>
<fieldset> Name:
<input class="input" type="text" name="Name" value="" />
</fieldset>
<fieldset> Location:
<input class="input" type="text" name="Location" value="" />
</fieldset>
<fieldset> Category:
<input class="input" type="text" name="Category" value="" />
</fieldset>
<fieldset> Labour Supplier:
<input class="input" type="text" name="LabourSupplier" value="" />
</fieldset>
<fieldset> Telephone:
<input class="input" type="text" name="Home" value="" />
</fieldset>
<fieldset>Mobile:
<input class="input" type="text" name="Mobile" value="" />
</fieldset>
<fieldset> Basic Salary:
<input class="input" type="number" name="BasicSalary" value="" id="BasicSalary" onkeyup="doSum()"/>
</fieldset>
<fieldset> Allowance I:
<input class="input" type="number" name="Allowance1" value="" id="Allowance1" onkeyup="doSum()"/>
</fieldset>
<fieldset>Allowance II:
<input class="input" type="number" name="Allowance2" />
</fieldset>
<fieldset>Total Day Rate:
<input class="input" type="number" name="DayRate" value="" id="DayRate" />
</fieldset>
<fieldset>OT Rate:
<input class="input" type="number" name="OTrate" value="" />
</fieldset>
<fieldset>
<button name="submit" type="submit" id="submit">Insert</button>
<button onclick="goBack()" name="Back" type="back" id="details-back">Back</button>
</fieldset>
<script>
function doSum() {
var Allowance1 = isNaN(document.getElementById('Allowance1').value) ? document.getElementById('Allowance1').value : 0;
var BasicSalary = isNaN(document.getElementById('BasicSalary').value) ? document.getElementById('BasicSalary').value : 0;
var tot = parseInt(Allowance1) + parseInt(BasicSalary);
document.getElementById('DayRate').value = tot;
}
</script>
I have this wizard that needs to display the previous posted value
index.html
<form method="post" action="posted.php">
<input type="text" name="surname" value="" placeholder="Surname" />
<input type="text" name="firstname" value="" placeholder="Firstname" />
<input type="checkbox" name="php" />
<input type="checkbox" name="jquery" />
<input type="checkbox" name="python" />
<input type="submit" value="Submit" />
</form>
in the posted.php i have a similar form only this time i know the value from $_POST
<form method="post" action="finish.php">
<input type="text" name="surname" value="<?php echo $_POST['surname']; ?>" placeholder="Surname" />
<input type="text" name="firstname" value="<?php echo $_POST['firstname']; ?>" placeholder="Firstname" />
<input type="checkbox" name="php" />
<input type="checkbox" name="jquery" />
<input type="checkbox" name="python" />
<input type="submit" value="Submit" />
</form>
I am having a hard time trying to come up with a solution that shows what checkbox was checked.I have seen several solutions like https://stackoverflow.com/a/11424091/1411148 but i wondering if there more solution probably in html5 or jquery.
How can i show what checkbox was checked?.The probem i am having is that <input type="checkbox" name="jquery" checked /> checked checks the checkbox and no post data can be added to show what the user checked.
This would be a way to go:
<form method="post" action="finish.php">
<input type="text" name="surname" value="<?php echo $_POST['surname']; ?>" placeholder="Surname" />
<input type="text" name="firstname" value="<?php echo $_POST['firstname']; ?>" placeholder="Firstname" />
<input type="checkbox" name="php" <?php if (isset($_POST['php'])) echo 'checked="checked"'; ?> />
<input type="checkbox" name="jquery" <?php if (isset($_POST['jquery'])) echo 'checked="checked"'; ?> />
<input type="checkbox" name="python" <?php if (isset($_POST['python'])) echo 'checked="checked"'; ?> />
<input type="submit" value="Submit" />
</form>
<form action="chngschdl.php" method="post">
<fieldset>
<label class="home">Flight Name</label> <select name="select_catalog_query" ><?php echo $options1; ?></select>
<br/><br/>
<label class="home">Starting Route</label> <input class="text" type="text" name="stroute" onKeyUp="numericFilter(this);" /> <label class="home">Deperture Time</label> <input class="text" type="text" name="stdrt" /><br/>
<label class="home">Ending Route</label> <input class="text" type="text" name="enroute" onKeyUp="numericFilter(this);" /> <label class="home">Arrival Time</label> <input class="text" type="text" name="enart" /><br/>
<label class="home">Break Route Number</label> <input class="text" type="number" name="bpn" maxlength='1' onkeyup="Bpoint(this.value)" /><br/>
<label id='bp' > <?php //$i=$_SESSION['point'];$_SESSION['bp']=$broute[$i];?></label>
<button class="btn">Go</button>
</fieldset>
</form>
ajax getting data from:
<?php
session_start();
if( $_SESSION['type']!='admin')
{
header("Location: index.php");
return;
}
$point=$_GET['q'];
$_SESSION['point']=$point;
$bpoption="";
for($i=0;$i<$point;$i++)
{
echo "<label>Break Route[$i]<label> <input class=text type=text name=broute[$i] /> ";
echo "<label>Arrival Time[$i]<label> <input class=text type=text name=bart[$i] /> ";
echo "<label>Departure Time[$i]<label> <input class=text type=text name=bdrt[$i] /> ";
echo "<br/><br/>";
}
?>
i have to collect every data of Break Route, Arrival time and Departure time... how i suppose to get this data and use it in another page?? is there is other way around by not using ajax... bt it must be remembered that Break Route is not predefined...
since your form fields are named like "name[$i]" it doesn't matter how many ajax-populated fields there are.
All you have to do on the page processing the form submit is:
foreach ($_POST["name"] as $name) {
// do things
}
I want to make a text field and button that will allow the user to fetch his details on the text fields instead of writting his details every time he wants to make a new reservation.
like in this picture:
http://oi41.tinypic.com/23ie70j.jpg
I tried to make this but with my code but gives me double forms one with the details and one without.
<form method="post" action="reserv page.php">
enter the email: <input type = "text" name = "email"/>
<input type = "submit" name = "submit" value="submit" />
</form>
<?php
mysql_connect("localhost","userName","password");
mysql_select_db("database_Name");
if(isset($_POST['submit']))
{
$email = $_POST['email'];
$q = "SELECT * FROM tabe WHERE the_email = '$email'";
$run = mysql_query($q );
while($row = mysql_fetch_array($run))
{
?>
</br></br>
<form action="payment.php" method="post" >
First Name:<input name="fName" type="text" value="<?php echo $row[1]; ?>" />
Last Name: <input name="lNamet" type="text" value="<?php echo $row[2]; ?>" />
User Name: <input name="uName" type="text" value="<?php echo $row[3]; ?>"/>
Email: <input name="email" type="text" value="<?php echo $row[4]; ?>" />
password: <input name="pass" type="password" value="<?php echo $row[5]; ?>"/>
contact: <input name="number" type="text" value="<?php echo $row[6]; ?>" />
<input name="confirm" type="submit" value="Confirm" />
</form>
</br></br>
<?php
}}
?>
<form action="payment.php" method="post" >
First Name:<input name="fName" type="text" />
Last Name: <input name="lNamet" type="text" />
User Name: <input name="uName" type="text" />
Email: <input name="email" type="text" />
password: <input name="pass" type="password" />
contact: <input name="number" type="text" />
<input name="confirm" type="submit" value="Confirm" />
</form>
<form method="post" action="reserv page.php">
enter the email: <input type = "text" name = "email"/>
<input type = "submit" name = "submit" value="submit" />
</form>
<?php
mysql_connect("localhost","userName","password");
mysql_select_db("database_Name");
if(isset($_POST['submit']))
{
$email = $_POST['email'];
//limit the query to one entry :)
$q = "SELECT * FROM tabe WHERE the_email = '$email' LIMIT 1";
$run = mysql_query($q );
//check if email is registered
if(mysql_num_rows($run)>0)
{
//display filled up form
while($row = mysql_fetch_array($run))
{
?>
</br></br>
<form action="payment.php" method="post" >
First Name:<input name="fName" type="text" value="<?php echo $row[1]; ?>" />
Last Name: <input name="lNamet" type="text" value="<?php echo $row[2]; ?>" />
User Name: <input name="uName" type="text" value="<?php echo $row[3]; ?>"/>
Email: <input name="email" type="text" value="<?php echo $row[4]; ?>" />
password: <input name="pass" type="password" value="<?php echo $row[5]; ?>"/>
contact: <input name="number" type="text" value="<?php echo $row[6]; ?>" />
<input name="confirm" type="submit" value="Confirm" />
</form>
</br></br>
<?php
}
}
//display blank form
else{
?>
<form action="payment.php" method="post" >
First Name:<input name="fName" type="text" />
Last Name: <input name="lNamet" type="text" />
User Name: <input name="uName" type="text" />
Email: <input name="email" type="text" />
password: <input name="pass" type="password" />
contact: <input name="number" type="text" />
<input name="confirm" type="submit" value="Confirm" />
</form>
<?php
}
}
?>
You're getting 2 forms because you're echoing one form if $_POST['submit'] is set and then another one regardless of anything. Print the second form only if $_POST['submit'] is not set. Since your code is so poorly written I will just give you an example:
if(isset($_POST['submit'])){
PRINT FETCHED FORM
}else{
PRINT EMPTY FORM
}
This, however, is not the "right" way to go. What people actually do is have variables null'd at start and then fill them up with data if there's a request and have a single form written in the file with input values as those variables.
if(isset($_POST['submit'])){
$domain=$_POST['domain'];
$fname=$_POST['fname'];
$sname=$_POST['sname'];
$tel=$_POST['tel'];
if($domain==""){
$error="<h4>Enter Domain </h4>";
}elseif($fname == ""){
$error="<h4>Enter Firstname </h4>";
}elseif($sname == "")
{
$error="<h4 >Enter Surname</h4>";
}elseif($tel=="")
{
$error="<h4 >Enter telephono no</h4>";
}
else {
$sql11=mysql_query("INSERT INTO domain VALUES('','$domain','$fname','$sname','$tel','$mobile','$email','$company','$address','$city','$country','$pcode','$tele',
'$fax','$qus','$ans')");
echo $sql;
$db->query($sql);
}
}
<div><?php echo $error; ?></div>
<form action="" method="post" name="classic_form" id="classic_form">
<div><h4>Personal details:</h4></div><div style="margin-left: 109px;">
<div>Domain</div>
<input type="text" name="domain" id="domain" value="" />
<div>First name: </div>
<input type="text" name="fname" id="fname" value="" />
<div>Surname:</div>
<input type="text" name="sname" id="sname" value="" />
<div>Telephone:</div>
<input type="text" name="tel" id="tel" value="" />
<div>Mobile:</div>
</form>
In my registration page, i used php validation. After the user submit the form if it shows validation errors it also resets all the fields. How can i resolve this problem? Without reset the fields i have to show the php validation errors. I also used in each input value. But it shows
"Notice: Undefined index: domain in D:\xampp\htdocs\deena\domainreg.php on line 82" . Please help me to resolve this problem
<input type="text" name="domain" id="domain" value="<?php echo isset($domain) ? $domain : ''; ?>" />
You have to pass all your values to php, and send back to html to feed your fields.
Its not 'resetting your fields' .. Your form is being submitted, hence the page is being reset and fields are therefore loading empty. Place the $_POST[] values in the field values upon page load:
<input type="text" name="domain" id="domain" value="<?php echo $domain ?>" />
<div>First name: </div>
<input type="text" name="fname" id="fname" value="<?php echo $fname?>" />
<div>Surname:</div>
<input type="text" name="sname" id="sname" value="<?php echo $sname?>" />
<div>Telephone:</div>
<input type="text" name="tel" id="tel" value="<?php echo $tel?>" />
Simple. Just add the variables to the input values:
<input type="text" name="domain" id="domain" value="<?php echo $domain; ?>" />
You should also protect the outputted value, against cross site scripting:
<input type="text" name="domain" id="domain" value="<?php echo htmlspecialchars($domain); ?>" />
In the value field:
<input type="text" name="domain" id="domain"
value="<?php if(isset($_POST['domain'])){echo $_POST['domain'];} ?>">
Didn't test it. But i think it should work.
In input tag add the php value as like value="" So that it will echo if the variable is posted or it will show the empty one