How to add Date and Time in form field - php

I am building a application form and I want to add a field for visitors to select a date and time. How would I be able to add that to the drop down field that I have added so far. I thinking for a calendar and time dropdown would work for this type of form? I have added the div tag below.
<div class="col-md-12 vehicle-assessment">
<h6>Hirer Details </h6>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Full Name</label>
<input type="text" class="form-control" name="tia_lineholder_text" id="tia_lineholder_email">
</div>
</div>

If you really want to use a dropdown menu this would be done like this assuming you have a list of DateTime objects. Time would be done in a similar way.
<div class="col-md-12 vehicle-assessment">
<h6>Hirer Details </h6>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Full Name</label>
<input type="text" class="form-control" name="tia_lineholder_text" id="tia_lineholder_email">
</div>
<div class="form-group">
<label>Date</label>
<select id="date">
<option value="">--Please choose an option--</option>
<?php
// Assuming $dates is a list of DateTime Objects
foreach $date in $dates {
echo "<option value='" . $date->getTimestamp() . "'>" . $date->format('Y-m-d') . "</option>";
}
?>
</select>
</div>
</div>
But I'd suggest using the inputs time and date. If you have specific time frames you want people to insert this can be added by min and max. If you need additional constraints you could alway write some JS-Code to enforce no sunday or something like that.
<div class="col-md-12 vehicle-assessment">
<h6>Hirer Details </h6>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Full Name</label>
<input type="text" class="form-control" name="tia_lineholder_text" id="tia_lineholder_email">
</div>
<div class="form-group">
<label>Date</label>
<input type="date" name="date"
value="2018-07-22"
min="2018-01-01" max="2018-12-31" />
</div>
<div class="form-group">
<label>Date</label>
<input type="time" name="time"
min="0:00" max="24:00" required />
</div>
</div>

You can use jQuery datepicker
http://jqueryui.com/datepicker/
or you can use
<input type="date" name="date" />
but the last solution wont work for all browsers, if you want to use cross browser than you should use datepicker plugin or any other plugins available on internet

Related

datepicker problem on passing value when submit for second time

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>

Can I block one table from updating?

I have two tables in my database one practitioner and the second one practitioner_specialty, both of them have fields effective_date and expiry_date. When I use the form to update both if those tables the last effective_date and expiry_date are being saved to both of the tables instead of two separate ones.
Is there a way to block one table from updating so I can update only the second one, or maybe is there a way to save it using different id/name so they will be unique ones for practitioner and practitioner_specialty?
Here are my form and controller used for updating tables.
Controller:
public function updatePractitioner(Request $request, $id)
{
$this->validate($request, [
'effective_date' => 'required',
]
);
$fields = $request->all();
$primary_key = $this->PractitionerRepository->getIdName();
$primary_key_specialty = $this->PractitionerSpecialtyRepository->getIdName();
$practitioner_specialty_id = PractitionerSpecialty::where('practitioner_id', $id)->value('practitioner_specialty_id');
$fields[$primary_key] = $id;
$this->PractitionerRepository->update($fields);
$fields[$primary_key_specialty] = $practitioner_specialty_id;
$this->PractitionerSpecialtyRepository->update($fields);
return back()->with('successUpdate', 'Practitioner has been updated!');
}
update form in blade.php :
<div class="edit-practitioner" style="display: none;">
<form style="box-shadow: none;" action="/practitioner/update/{{$practitioner->practitioner_id}}" method="post"
class="j-pro" id="update-practitioner-form">
{{ csrf_field() }}
<div class="j-content">
<div id="j-row-id" class="j-row">
<div class="row">
<div class="col-sm-12 col-lg-12 col-xl-5">
<div class=" j-unit">
<div class="j-divider-text j-gap-top-20 j-gap-bottom-45">
<span>Practitioner Information</span>
</div>
<label class="j-label">{{trans('personalData.effectiveDate')}}</label>
<div class="j-input">
<input type="date" value="{{$practitioner->effective_date}}"
name="effective_date" id="effective_date">
</div>
<label class="j-label">{{trans('personalData.expiryDate')}}</label>
<div class="j-input">
<input type="date" value="{{$practitioner->expiry_date}}"
name="expiry_date" id="expiry_date">
</div>
<label class="j-label">{{trans('personalData.phoneNumber')}}</label>
<div class="j-input">
</label>
<input type="tel" value="{{$practitioner->phone}}"
name="phone" id="phone">
</div>
<label class="j-label">{{trans('personalData.mobileNumber')}}</label>
<div class="j-input">
<input type="tel" value="{{$practitioner->mobile}}"
name="mobile" id="mobile">
</div>
<label class="j-label">{{trans('personalData.email')}}</label>
<div class="j-input">
<input type="email" value="{{$practitioner->email}}"
name="email" id="email">
</div>
</div>
</div>
<div class="col-xl-1 j-unit"></div>
<div class="col-sm-12 col-lg-12 col-xl-6">
<div class="j-divider-text j-gap-top-20 j-gap-bottom-45">
<span>{{trans('settings.specialty')}}</span>
</div>
<select name="practitioner_specialty_id_update"
id="practitioner_specialty_id_update"
class="form-control-practitioner required">
#foreach($specialties as $specialty)
<option
value="{{$specialty->specialty_id}}">{{$specialty->name}}</option>
#endforeach
</select>
<label class="j-label">{{trans('personalData.effectiveDate')}}</label>
<div class="j-input">
#isset($practitioner_specialty->practitioner_specialty_id)
<input type="date" value="{{$practitioner_specialty->effective_date}}"
name="effective_date" id="effective_date">
#endisset
#empty($practitioner_specialty->practitioner_specialty_id)
<input type="date" name="effective_date" id="effective_date">
#endempty
</div>
<label class="j-label">{{trans('personalData.expiryDate')}}</label>
<div class="j-input">
#isset($practitioner_specialty->practitioner_specialty_id)
<input type="date" value="{{$practitioner_specialty->expiry_date}}"
name="expiry_date" id="expiry_date">
#endisset
#empty($practitioner_specialty->practitioner_specialty_id)
<input type="date" name="expiry_date" id="expiry_date">
#endempty
</div>
</div>
</div>
</div>
<div class="j-divider j-gap-bottom-45 j-gap-top-10"></div>
<button type="submit"
class="btn btn-editpanel btn-success btn-round">Save changes
</button>
<!-- end /.footer -->
<button id="update-cancel-button-practitioner" href="javascript:window.location.href=window.location.href" type="button"
class="btn btn-editpanel btn-danger btn-round">Cancel
</button>
</div>
</form>
</div>
Well you use the same array for both of the tables, hence the reason to update all the fields. You can try to exclude the ones for one form and add them to the other, for example:
$practictionerFields = $request->except('expiry_date', 'effective_date');
$practictionerFields[$primary_key] = $id;
$this->PractitionerRepository->update($practictionerFields);
// and use the other $fields array for the PractitionerSpecialty model.
You can use LOCK query here.
lock is a flag associated with a table. MySQL allows a client session to explicitly acquire a table lock for preventing other sessions from accessing the same table during a specific period. A client session can acquire or release table locks only for itself. It cannot acquire or release table locks for other sessions.
You can read more here: http://mysqltutorial.org/mysql-table-locking

How to change my <select> out with <input> to use with barcode scanner

I'm about to change a script, and right know the script are using an <select> with one options and echo to be used to show the products.
Now I'll like to change the <select> to a <input> so I can scan a barcode, and the information from the product should be added to the DB as it is right now, but I'm lost, I have used several hours to figuere out how to change it, I thought the solution was to use a hidded but then I can't add the first knowen product to my list.
Could someone please help me? :)
I've tried to use more boxes to get the products, but that was a big mess.
<div class="col-md-6">
<div class="form-group">
<label for="date">Product Name</label>
<select class="form-control select2" name="prod_name" tabindex="1" autofocus required>
<?php
$branch=$_SESSION['branch'];
$cid=$_REQUEST['cid'];
include('../dist/includes/dbcon.php');
$query2=mysqli_query($con,"select * from product where branch_id='$branch' order by prod_name")or die(mysqli_error());
while($row=mysqli_fetch_array($query2)){
?>
<option value="<?php echo $row['prod_id'];?>"><?php echo $row['prod_name']." Available(".$row['prod_qty'].")";?></option>
<?php }?>
</select>
<input type="hidden" class="form-control" name="cid" value="<?php echo $cid;?>" required>
</div><!-- /.form group -->
</div>
<div class=" col-md-2">
<div class="form-group">
<label for="date">Quantity</label>
<div class="input-group">
<input type="number" class="form-control pull-right" id="date" name="qty" placeholder="Quantity" tabindex="2" value="1" required>
</div><!-- /.input group -->
</div><!-- /.form group -->
</div>
<div class="col-md-2">
<div class="form-group">
<label for="date"></label>
<div class="input-group">
<button class="btn btn-lg btn-primary" type="submit" tabindex="3" name="addtocart">+</button>
</div>
</div>
The code should be changed to use a <input> or something simular, so I can use a barcode scanner to add my items to a list.
What I did to get my result was:
I changed the prod_id to be the barcode, and on scan the form is submitted to a temp_db, to show every items, and then added a "finish db" called inStock, and everything was as it should be! :)
/Kenneth

Data from JSON response not displaying after assigning to instance variable

So, I have my SPA at about 98% functional. The app pulls data from a MySQL database and allows the user to edit/delete records. For the page in question, it will edit/delete data of the specified student ID but it will not properly display the data in the text fields.
If you do not input a value it will display the first item in the JSON array but not the one you specify in the search field.
I did not do a very good job at explaining that but here is the HTML page that uses a function to pass data to the controller which then selects the corresponding student by ID and assigns it to the variable $scope.student. I then try to display the student data on the HTML page by using student.first_name (or any property) but it does not work correctly.
<h3>Edit/Delete Student with ID: {{student.student_id}}</h3>
<div class="form-group">
<label for="sid">Student ID:</label>
<input type="text" class="form-control" id="sid" ng-model="sid">
</div>
<p><button type="button" class="btn btn-primary" ng-click="getRecord(sid)">
Get Student Info </button> </p>
<div class='row'>
<div class="col-md-6">
<div class="form-group">
<label for="first_name">First Name:</label>
<input type="text" class="form-control" id="first_name" ng-model="student.first_name">
</div>
<div class="form-group">
<label for="last_name">Last Name:</label>
<input type="text" class="form-control" id="last_name" ng-model="student.last_name">
</div>
<div class="form-group">
<label for="hrs_completed">Hrs Completed:</label>
<input type="text" class="form-control" id="hrs_completed" ng-model= "student.hrs_completed">
</div>
<div class="form-group">
<label for="hrs_attempted">Hrs Attempted:</label>
<input type="text" class="form-control" id="hrs_attempted" ng-model= "student.hrs_attempted">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="gpa_points">GPA Points:</label>
<input type="text" class="form-control" id="gpa_points" ng-model= "student.gpa_points">
</div>
<div class="form-group">
<label for="major">Major:</label>
<input type="text" class="form-control" id="major" ng-model="student.major">
</div>
<div class="form-group">
<label for="advisor_id">Advisor ID:</label>
<input type="text" class="form-control" id="advisor_id" ng-model="student.advisor_id">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="text" class="form-control" id="email" ng-model="student.email">
</div>
</div>
<button type="button" class="btn btn-primary" ng-click="updateRecord()">Update</button>
<button type="button" class="btn btn-primary" ng-click="deleteRecord()">Delete</button>
And here is my controller on my Javascript page:
app.controller('editCtrl', function($scope, $http) {
$http.get("getStudentData.php")
.then(function (response) {
$scope.students = response.data;
});
$scope.getRecord = function(sid) {
id = sid;
$scope.student = $scope.students.find(s=>s.id == sid);
};
Do I need to make a seperate GET request to the server for this to work properly or do I just need to reference the student object differently?
I think there is mismatch in what you are getting as response.data and what you are trying to .find() and then what you are binding on html.
Check this plunkr.
You are trying to render by searching id property.
$scope.students.find(s=>s.id == sid);
where as you are rendering on UI using student_id property.
{{student.student_id}}
So, surely there is mismatch in what you are getting as response.data and what you are rendering using $scope.student properties. I think my plunkr will show that your function is correct.
In case this answer doesn't work, share your response.data.

Inserting data into MySQL server

I'm doing a e-commerce admin panel and I need a quick script for inserting data into MySQL. Here's what i've done and it does nothing.
<form action="#" id="form_sample_1" class="form-horizontal" method="post">
<div class="control-group">
<label class="control-label">Package Name<span class="required">*</span></label>
<div class="controls">
<input type="text" name="pkg_name" data-required="1" class="span6 " value=""/>
</div>
</div>
<div class="control-group">
<label class="control-label">Package Price <span class="required">*</span><small>(In Dollars)</small></label>
<div class="controls">
<input name="pkg_price" type="number" class="span6 " value=""/>
</div>
</div>
<div class="control-group">
<label class="control-label">Package Contains</label>
<div class="controls">
<input name="pkg_contains" type="text" class="span6 " value=""/>
</div>
</div>
<div class="control-group">
<label class="control-label">Your Password</label>
<div class="controls">
<input name="sifre" type="password" class="span6 " value=""/>
</div>
</div>
<div class="form-actions">
<button type="button"name="btn" class="btn btn-primary">Send request to server.</button>
</div>
</form>
<!-- END FORM-->
</div> <!--widget box light-grey end-->
<!-- Mass PHP starts here! -->
<?php
echo mysql_error();
include("include/baglan.php");
// set posts here.
$_POST['pkg_name'] = $pkg_name;
$_POST['pkg_price'] = $pkg_price;
$_POST['pkg_contains'] = $pkg_contains;
$sifre = mysql_real_escape_string(md5($_POST['sifre']));
if($_POST['btn'] and $_POST["sifre"] = $sifre){
mysql_query("INSERT INTO packages (pkg_name, pkg_price,pkg_contains) VALUES $pkg_name $pkg_price $pkg_contains");
echo "Success.";
}
else {
echo mysql_error();}
It returns nothing! I've re-written all code but nothing! please help me. The databae variables are;
id, auto incerment
pkg_name text
pkg_price int
pkg_contains mediumtext
Assign variable name should be the left side.
// set posts here.
$pkg_name=$_POST['pkg_name'];
$pkg_price=$_POST['pkg_price'];
$pkg_contains=$_POST['pkg_contains'];
Values() is function, put all vars in bracket and split them with ','.
mysql_query("INSERT INTO packages (pkg_name, pkg_price,pkg_contains) VALUES($pkg_name,$pkg_price,$pkg_contains)");

Categories