datepicker problem on passing value when submit for second time - php

i have an issue on passing value thru datepicker. i have an appointment system which i use datepicker. i need to get the date and pass the value (on the same page) to my query and check it with my mysql database whether the date available or not. First pick date is ok and it send the right value, but when i try pick another date and submit it, it passing the first date that i choose. Is anyone know what is the problem?
<?php
if (isset($_POST['check']))
{
$appdate = $_POST['appdate'];
}
?>
<form method="post" enctype="multipart/form-data" id="form" name="form">
<div class="form-group row">
<div class="col-md-6">
<label for="jenis">Date Appointment</label>
<input name="appdate" readonly="readonly" id= "appdate" type="text" class="form-control datepicker" data-format="dd-mm-yyyy" data-lang="en" data-RTL="false">
<span class="help-block" id="error" style="color:red"></span>
</div>
<div class="col-md-6">
<label for="jenis"> <br></label>
<input type="submit" name="check" id="check" value="Check" class="btn btn-3d btn-pink"/>
</div>
</div>
<?php
if (isset($_POST['check']))
{
$appdate = $_POST['appdate'];
?>
<div>
<p><?php echo $appdate; ?></p>
</div>
<?php
}
?>
</form>

Related

Cannot handle a form in php

I'm learning now php and i'm stuck in one place with handling form submit action.
Im my input i'm trying to store user name in $_GET['firstname'] variable. But it's empty. I mean, that after checking if $_GET['firstname'] isset I get false. Where is my mistake?
<body>
<div class="container">
<div class="section back">
<form class="form myform" action="addcustomer.php" method="get">
<span class="myformtitle">
Add new User
</span>
<div class="form-group">
<div class="col validate-input">
<span class="label-input">Firstname</span>
<input id="firstname" class="input myinput" type="text" name="firstname" placeholder="Enter your firstname" value="<?php if (isset($_GET['firstname'])) echo $_GET['firstname']?>">
<span class="focus-input"></span>
</div>
</div>
<div class="col col-btn">
<button type="button" name="submit" class="btn sb-btn btn-block">
<span class="btn-sp">
Submit
</span>
</button>
</div>
</form>
</div>
</div>
<?php
if (isset($_GET['firstname'])) {
echo '<script>console.log("' . $_GET['firstname'] . '")</script>';
} else {
echo '<script>console.log("no name")</script>';
}
?>
</body>
Change your button type from button to submit.
button types are for Javascript (JS).
submit types are used to process PHP (form) directives.

Form posting does not work

I am having trouble to post a html form. I am posting one form and getting the post value to my variable and then I am post this form but this form is not posting.
HTML code:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" autocomplete="off">
<div class="widget-box">
<div class="widget-title"> <span class="icon"> <i class="icon-user"></i> </span>
<h5>Amc details</h5>
</div>
<div class="widget-content">
<div class="controls controls-row">
<div class="control-group span3">
<label for="normal" class="control-label">Installation Date<span style="color:red">*</span></label>
<div class="controls">
<input type="text" id="amc-ins-date" data-date="01-02-2016" name="amc-ins-date" data-date-format="dd-mm-yyyy" class="datepicker span12" placeholder="Enter installation date">
</div>
</div>
<div class="control-group span3">
<label for="normal" class="control-label">Start Date<span style="color:red">*</span></label>
<div class="controls">
<input type="text" id="amc-start-date" data-date="01-02-2016" name="amc-start-date" data-date-format="dd-mm-yyyy" placeholder="Enter amc start date" class="datepicker span12 ins-date">
</div>
</div>
<div class="control-group span3">
<label class="control-label">End Date<span style="color:red">*</span></label>
<div class="controls">
<input type="text" id="amc-end-date" data-date="01-02-2016" name="amc-end-date" data-date-format="dd-mm-yyyy" placeholder="Enter amc end date" class="datepicker span12 ins-date">
</div>
</div>
<div class="control-group span3">
<label class="control-label">Amount<span style="color:red">*</span></label>
<div class="controls">
<input type="text" id="amc-amount" name="amc-amount" class="span12" placeholder="Enter amc amount">
</div>
</div>
</div>
</div>
<div class="form-actions">
<input style="float:right" type="submit" name="amc-installation" class="btn btn-success" value="Save">
</div>
</form>
PHP code:
// i have submitted a form here and its posted
// installation details
$mc_serial = $_POST['mc-serial'];
$mc_model = $_POST['mc-model'];
$contract_type = $_POST['contract_type'];
$no_of_copies = $_POST['no-of-copies'];
$spare_part = join(",",$_POST['spare-part']);
$eng_name = $_POST['eng-name'];
$review = $_POST['review'];
// check if the machine already exits
if(IsMachine($mc_serial,$con)){
echo msgIsMachine();
exit();
}
if($contract_type == 'AMC'){
require './forms/amc.php'; // this is the html i have shown above
} elseif ($contract_type == 'ASC') {
require './forms/asc.php';
} elseif ($contract_type == '4C') {
require './forms/4c.php';
} elseif ($contract_type == 'RENTAL') {
require './forms/rental.php';
} elseif ($contract_type == 'WARRANTY') {
require './forms/warranty.php';
}
if(isset($_POST['amc-installation']) && !empty($_POST['amc-installation'])){
echo "posted";
var_dump($_POST);($_POST);
}
The output of var_dump is NULL. I don't get any problem.
You echo the second form (during the script which responds to the submission of the first one), but then immediately check for values returned from it within the same script execution. You have to wait for the user to post the form back before you can check the submitted values. This would be a separate postback, and therefore a separate execution context for the PHP.
So the code to check the values from the second form needs to be in a separate section (or file) which is triggered by the submission of the second form.
There's no $POST in PHP you should use $_POST instead :
if(isset($_POST['amc-installation']) && !empty($_POST['amc-installation'])){
echo "posted";
var_dump($_POST);
}
NOTE : You should place the var_dump($_POST); inside the if statement, so it will be trrigered just after the submit.
Hope this helps.
if(isset($_POST['amc-installation']) && !empty($_POST['amc-installation'])){
echo "posted";
var_dump($_POST);
}
You should use $_POST not $POST.
Hope this will helps you :)

HTML form not passing checkbox value trough $_POST in php file

I have a form in HTML with some checkboxes and I want to send an email with the selected checkboxes in the body, the problem is that the "text" fields are passing to the PHP variables, but the checkboxes values are always set to uncheck when I test it on the PHP file:
HTML:
<div class="col-md-6">
<div class="c-checkbox-list">
<div class="c-checkbox">
<input type="checkbox" name="checkbox1citadina" id="checkbox1citadina" value="checkbox1citadina" class="form-control c-check" >
<label for="checkbox1citadina">
<span></span>
<span class="check"></span>
<span class="box"></span> Citadina
</label>
</div>
PHP:
$reservas_bicicletas = '';
if (isset($_POST['checkbox1citadina'])) {
$reservas_bicicletas .= "Citadina: checked\n";
} else {
$reservas_bicicletas .= "Citadina: unchecked\n";
}
echo $reservas_bicicletas;
$reservas_bicicletas always retrieves the else value.
Need help guys, thanks in advance.
remove c-check
<div class="col-md-6">
<div class="c-checkbox-list">
<div class="c-checkbox">
<input type="checkbox" name="checkbox1citadina" id="checkbox1citadina" value="checkbox1citadina" class="form-control " >
<label for="checkbox1citadina">
<span></span>
<span class="check"></span>
<span class="box"></span> Citadina</label>
</div>
Basically i have this (i shorted out the form because there are too many elements):
HTML:
<form name="quick_booking" id="quick_booking" method="post" action="assets/reserva-bicicletas.php">
<div class="col-md-6">
<div class="c-checkbox-list">
<div class="c-checkbox">
<input type="checkbox" name="checkbox1citadina" id="checkbox1citadina" value="checkbox1citadina" class="form-control " >
<label for="checkbox1citadina">
<span></span>
<span class="check"></span>
<span class="box"></span> Citadina</label>
</div>
<button type="submit" class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square">Reservar</button>
</form>

To get record of two dates

I want two dates if I post start date and end date from submit form. I have attendance record table. I want to retrieve this table. How can I do that?
This is my code. It redirects to test.php. How can I retrieve another page? Who can help me kindly?
<form method="post" class="form-horizontal" role="form" action="test.php">
<!--Start Date-->
<div class="col-lg-12">
<div class="form-group required">
<label for="startdate" class="control-label">Start Date:</label>
<input class="form-control" placeholder="Choose Date " type="text" id="datepicker-8" name="startdate" required="required" />
</div>
</div>
<!--End Date-->
<div class="col-lg-12">
<div class="form-group required">
<label for="enddate" class="control-label">End Date:</label>
<input class="form-control" placeholder="Choose Date " type="text" id="datepicker-9" name="enddate" required="required" />
</div>
</div>
<!--Create Button-->
<div class=""> <br/>
<input class="btn btn-success" type="submit" value="Search" />
</div>
</form>
You need to first get both start date and end date in vairable using $_REQUEST like that way.
$start_data = $_REQUEST['startdate'];
$end_data = $_REQUEST['enddate'];
Now you need to use sql query to fetch data from table :
$query = mysql_query("select * from table_name where startdate='$start_data' AND enddate='$end_data'");
while($row=mysql_fetch_array($query)) {
// Print your variable here
}
in test.php:
<?php
var_dump($_POST);
Then submit your form. You will see all the fields and values that were contained in the form. You can access individual fields like so: $startdate = $_POST['startdate']
Good luck!
When you click the submit button the page will be redirected to test.php file, the content which you will write in test.php will be shown. Now to retrieve date from post u can use $startdate=$_POST['startdate'] simillarly for $enddate=$_POST['enddate']. After this use queries to fetch the data from database using the startdate and enddate variable

Display jquery datepicker value in php

I have a form with a datepicker and I want to pass the selected date to my php file but it doesn't seem to work.
My html is like this
<form method="post" action="http://www.domainname.com/?from=20/04/2014&to=25/04/2014" name="easy_widget_form" id="easy_widget_form">
<div class="input_container">
<div class="input_prefix">
Check in:
</div><input id="easy-widget-datepicker-from" type="text" name="from" value="20.04.2014" class="hasDatepicker">
</div>
<div class="input_container">
<div class="input_prefix">
Check out:
</div><input id="easy-widget-datepicker-to" type="text" name="to" value="25.04.2014" class="hasDatepicker">
</div>
<p class="easy-submit"><input type="submit" class="easybutton" value="Reserve now!"> </p>
</form>
Javascript :
jQuery('#easy-form-from,#easy-widget-datepicker-from').val(d);
But when I echo $easy-widget-datepicker-from in my php file, it doesn't show anything. Any help is appreciated!
make your page as this
contact.php
<?PHP
if($_REQUEST['Submit']=='Reserve now!'){
echo $from= $_POST['from'];
echo $to= $_POST['to'];
}
?>
<form method="post" action="contact.php" name="easy_widget_form" id="easy_widget_form">
<div class="input_container">
<div class="input_prefix">
Check in:
</div><input id="easy-widget-datepicker-from" type="text" name="from" value="20.04.2014" class="hasDatepicker">
</div>
<div class="input_container">
<div class="input_prefix">
Check out:
</div><input id="easy-widget-datepicker-to" type="text" name="to" value="25.04.2014" class="hasDatepicker">
</div>
<p class="easy-submit"><input name="Submit" type="submit" class="easybutton" value="Reserve now!"> </p>
</form>
i have made changes to your form, and submit button. Please try the above code.
php only takes "name" not "id"
so echo "$_POST['from']" to get "easy-widget-datepicker-from"'s value

Categories