This is my code :
<div class="form-group">
<div class="col-md-4">
<label class="control-label">Mobile Number:</label>
</div>
<div class="col-md-8">
{!! Form::input('number', 'mobile', null, ['type' => 'number', 'min' => 0, 'id' => 'mobile', 'class' => 'input-lg form-control TabOnEnter', 'placeholder' => 'Eg: 9876543210', 'tabindex' => 15]) !!}
</div>
</div>
Here i want to give this mobile number field as required, how can i add it in my code?
And i am having 3 steps in the creation of form and i am having mobile number in step1, when i am clicking the next button without adding mobile number, it should display an alert message..Now it is displaying alert message of mobile field required, only after clicking submit button in last step (i.e) in step 3..
Add 'required' => true to the array:
{!! Form::input('number', 'mobile', null, ['required' => true, 'type' => 'number'....
You need to check it with your next_button using jquery
<div class="form-group">
<div class="col-md-4">
<label class="control-label">Mobile Number:</label>
</div>
<div class="col-md-8">
{!! Form::input('number', 'mobile', null, ['type' => 'number', 'min' => 0, 'id' => 'mobile', 'class' => 'input-lg form-control TabOnEnter', 'placeholder' => 'Eg: 9876543210', 'tabindex' => 15]) !!}
<button style="margin-right:20px;" class="next_button btn btn-info active nextBtn btn-md pull-right" type="next" >Next</button>
</div>
</div>
$(document).ready(function(){
$('.next_button').click(function(event){
if ($('#mobile').val() == ""){
event.preventDefault();
alert('Enter the number');
}
});
});
Added next_button class in your existing code
Related
my problem is i cannot search and cannot disply the values in my texboxes.
what i want is to search the id of each user and display its data to my textbox
How can I do this on this video This Video in Laravel?
as of now I have this
here is my page
View
{!! Form::open(['action' => 'Admin\EmployeeFilemController#search', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
<input type="text" name="id" class="form-control" placeholder="Enter ID to Search"><br>
<input type="submit" class="btn btn-primary btn-md" name="search" value="Search Data">
{!! Form::close() !!}
Controller
public function search(Request $request){
$output = "";
$employees = DB::table('employeefms')->where('id')->get();
return redirect('/admin/employeemaintenance');
}
my View Inputs
<div class="form-group col-md-2">
{{Form::label('employee_no', 'Employee No.')}}
{{Form::text('employee_no', '',['class' => 'form-control', 'placeholder' => 'Employee No.'])}}
</div>
<div class="row">
<div class="form-group col-md-4">
{{Form::label('last_name', 'Last Name')}}
{{Form::text('last_name', '',['class' => 'form-control', 'placeholder' => 'Last Name'])}}
</div>
<div class="form-group col-md-4">
{{Form::label('first_name', 'First Name')}}
{{Form::text('first_name', '',['class' => 'form-control', 'placeholder' => 'First Name'])}}
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
{{Form::label('middle_name', 'Middle Name')}}
{{Form::text('middle_name', '',['class' => 'form-control', 'placeholder' => 'Middle Name'])}}
</div>
<div class="form-group col-md-4">
{{Form::label('nick_name', 'Nick Name')}}
{{Form::text('nick_name', '',['class' => 'form-control', 'placeholder' => 'Nick Name'])}}
</div>
</div>
You don't seem to pass the id entered by the user in your controller function.
$employees = DB::table('employeefms')->where('id')->get();
You may have to do the following changes
$input = $request->all();
$id = $input['id']
// $employees = DB::table('employeefms')->where('id', $id)->get();
// actually, if 'id' is the primary key, you should be doing
$employee = DB::table('employeefms')->find($id);
// now pass the data to the view where you want to display the record
// like so
return view('name_of_view', compact('employee'));
Then, use Laravel's Form-Model binding
{!! Form::model($employee,
['action' => ['Admin\EmployeeFilemController#update', $employee->id],
'method' => 'patch' // or whatever method you have defined
]) !!}
// your form fields specified above will go here
{!! Form::close() !!}
I have two form in one view when I leave the text field empty it redirects to wrong action. I am looking forwrad for the solution of this problem. Thanks in hope.
Form one works fine when I enter data in ll the input fields. /inquiry/store also contains http request validation.
View code which contains two forms.
<div class="col-lg-6">
{!! Form::open(['role' => 'form', 'url' => '/inquiry/store', 'class' => 'form-horizontal', 'method'=>'POST']) !!}
<div class='form-group'>
{!! Form::label('name', 'Student Name *', ['class' => 'control-label col-md-4']) !!}
<div class="col-md-8">
{!! Form::text('name', $student->name,['autocomplete'=>'off' , 'placeholder' => 'Student Name', 'class' => 'form-control']) !!}
</div>
</div>
<div class='form-group'>
{!! Form::label('father_name', 'Father Name *', ['class' => 'control-label col-md-4']) !!}
<div class="col-md-8">
{!! Form::text('father_name',$student->father_name, ['autocomplete'=>'off' , 'placeholder' => 'Father Name', 'class' => 'form-control']) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('class', 'Class', ['class' => 'control-label col-md-4']) !!}
<div class="col-md-8">
{!! Form::text('class', $student->admission_class,['autocomplete'=>'off' , 'placeholder' => 'Class', 'class' => 'form-control']) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('roll_no', 'Roll Number', ['class' => 'control-label col-md-4']) !!}
<div class="col-md-8">
{!! Form::text('roll_no', $student->roll_no,['autocomplete'=>'off' , 'placeholder' => 'Roll Number', 'class' => 'form-control']) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('date', 'Date',['class' => 'control-label col-md-4']) !!}
<div class="col-md-8 date">
<div class="input-group input-append date" id="dateRangePicker">
{!! Form::input('date', 'date', null, ['autocomplete'=>'off' , 'placeholder' => 'Date of Birth', 'class'=>'form-control col-height datepicker']) !!}
<span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
</div>
<div class="form-group">
{!! Form::label('teacher_name', 'Teacher Name', ['class' => 'control-label col-md-4']) !!}
<div class="col-md-8">
{!! Form::select('teacher_name', $teacher, ['autocomplete'=>'off' , 'placeholder' => 'Teacher Name', 'class' => 'form-control']) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('remarks', 'Remarks', ['class' => 'control-label col-md-4']) !!}
<div class="col-md-8">
{!! Form::textarea('remarks', null, ['autocomplete'=>'off' ,
'placeholder' => 'Remarks',
'class' => 'form-control']) !!}
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-3 col-md-12">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
<input type="reset" class="btn btn-default" value="Reset">
</div>
</div>
{!! Form::close() !!}
second form for searching the student. When I submit the first form with out some empty field it redirect to /inquiry/search_stu. and displays MethodNotAllowedHttpException .
<form role="form" id="search_form" action="/inquiry/search_stu" method="post" class="form-inline">
<div class='form-group'>
<label class="control-label col-md-4">Search Student *</label>
<input class="form-control" type="text" name="search" placeholder="Admission No" required>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class='form-group'>
<input type="submit" form="search_form" class="btn btn-primary" name="submit">
<input type="reset" class="btn btn-default">
</div>
</form>
Controller function for search student.
public function search_student(Request $request)
{
$teacher = \App\Teacher::lists('name', 'name');
$adminid = $request['search'];
$student = Admission::where('admission_no',$adminid)->first();
return View::make('/inquiry/create', ['student'=> $student,'teacher' => $teacher]);
}
When I submit the store form it redirects to search student.
store function .
public function store(Requests\StoreInquiryRequest $request) {
$input = Input::all();
$inquiry = new Inquiry();
$inquiry->name = $input['name'];
$inquiry->father_name = $input['father_name'];
$inquiry->date = $input['date'];
$inquiry->class = $input['class'];
$inquiry->teacher_name = $input['teacher_name'];
$inquiry->roll_no = $input['roll_no'];
$inquiry->remarks = $input['remarks'];
try {
$inquiry->save();
return redirect()->to('inquiry')->with('message', 'success| Student details have been saved.');
} catch (Exception $ex) {
\Log::error($ex);
return redirect()->to('inquiry')->with('message', 'error| There was an error adding new student, please try again later.');
}
}
Http request for validation when wants to store data
public function rules()
{
$cid = \Route::input('id');
$isEdit = isset($cid) ? true : false;
$rules = array(
'name' => 'required|string|Max:50',
'father_name' => 'required|string|Max:50',
'class' => 'required|string|Max:50',
'date' => 'required|date|Max:50',
'teacher_name' => 'required|string|Max:50',
'remarks' => 'required',
'roll_no' => 'required',
);
return $rules;
}
You can performe as many forms on one page as you wish. As far as I see you should have proper validtion in your controller - different validation for each form.
You need to use proper Laravel Validation. Reading this will make your coding process easier and faster: https://laravel.com/docs/5.0/validation
Example of validation in controller in Laravel 5.0:
public function store(Request $request)
{
$this->validate($request, [
'title' => 'required|unique|max:255',
'body' => 'required',
]);
}
Laravel Valiation also let you perform validations with query to database qithout writing whole SQL query: https://laravel.com/docs/5.0/validation#available-validation-rules
To display errors in view use:
#if($errors->has())
#foreach ($errors->all() as $error)
<div>{{ $error }}</div>
#endforeach
#endif
Good luck!
I wrote this script to show hidden label and whole select field on change in other select field CakePHP,
script function is showing label but not select field.
Here is the htmlhelper:
<div class="form-group">
<label for="job_category" class="col-sm-5 control-label">Tutor City</label>
<div class="col-sm-7">
<?php echo $this->Form->input('city_id',
array('class' => 'user_login form-control',
'placeholder' =>'TutorCity',
'label' => false,
'div' => false,
'id' => 'city'
));
?>
</div>
</div>
<div class="form-group">
<label for="job_category" class="col-sm-5 control-label" id="area_label" hidden>Tutor Access Areas</label>
<div class="col-sm-7">
<?php echo $this->Form->input('area_id',
array('class' => 'user_login form-control',
'placeholder' => 'TutorAreas',
'id' => 'area',
'div' => false,
'label' => false,
'multiple' => true,
'type' => 'hidden'
));
?>
</div>
</div>
Script:
<script type="text/javascript">
$("#city").change(function () {
$("#area_label").show();
$("#area").show();
})
</script>
Any help is appreciated. Thanks.
The second input is hidden input <input type="hidden"> so to generate select field remove type => hidden
<?php echo $this->Form->input('area_id',
array('class' => 'user_login form-control',
'placeholder' => 'TutorAreas',
'id' => 'area',
'div' => false,
'label' => false,
'multiple' => true,
'type' => 'hidden' // remove this
));
?>
You need to remove the type hidden first. You can try using type text with display none. You can change the input field display block on change.
I have my index.php where i am implementing searching functionality, the functionality is working, like user input some business name, and input some city name, after submit the form the business is retrieve from the database. Now my next task is to implement submission of form by using cjuiautocomplete. Like when user start typing the name of business, the businesses should come down in the drop down. The main hurdle in my way is that I am in index.php. I was following this http://www.yiiframework.com/wiki/162/a-simple-action-for-cjuiautocomplete/ but this is for view file of a controller. How can i implement this in my index.php. Given below is my form in index.php.
<form action="business/searchingtesting" method="GET">
<div class="form-group form-group-lg">
<h2 class="title">Find the best places to eat, drink, shop, or visit in Islamabad. </h2>
<div class="col-sm-5 col-md-5 col-lg-5 col-md-offset-1">
<input type="text" class="form-control" name="business" id="lg" placeholder="I'm looking for....">
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<input type="text" class="form-control" id="sm" name="city" placeholder="Islamabad">
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<input type="submit" class="btn btn-primary btn-lg" value="submit">
</div>
</div>
</form>
If I follow the above link and use the below code in my form I get this error "undefined variable model".
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'attribute' => 'my_name',
'model' => $model,
'sourceUrl' => array('my/aclist'),
'name' => 'business_name',
'options' => array(
'minLength' => '3',
),
'htmlOptions' => array(
'size' => 45,
'maxlength' => 45,
),
)); ?>
First of all read documentation. You may use CJuiAutoComplete like with model as without it. To use with model you need to specify two params: model and attribute. If you use it without model then only name. As I can see you doesn't use model in your form, so this example for you:
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'my_name',
'sourceUrl' => array('/my/aclist'), // you need first slash if you want properly working URL from web root
));
<form action="business/searchname" method="GET">
<div class="form-group form-group-lg">
<h2 class="title">
Find the best places to eat, drink, shop, or visit in Islamabad.
</h2>
<div class="col-sm-5 col-md-5 col-lg-5 col-md-offset-1">
<?php
$model = Business::model()->findAll();
$modelcity = Address::model()->findAll(array(
'select' => 't.city',
'group' => 't.city', //selecting distinct values as many businesses hass same cities, so the drop down was filled with only one city
'distinct' => true,
));
foreach ($model as $mo) {
$store[] = $mo->business_name;
}
foreach ($modelcity as $c) {
$city[] = $c->city;
}
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'business',
'source' => array_values($store),
// additional javascript options for the autocomplete plugin
'options' => array(
'minLength' => '2',
),
'htmlOptions' => array(
'style' => 'height:45px;width:415px;',
'placeholder' => ' I am Looking for................ ',
),
));?>
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'city',
'source' => array_values($city),
// additional javascript options for the autocomplete plugin
'options' => array(
'minLength' => '2',
),
'htmlOptions' => array(
'style' => 'height:45px; width:250px;',
'placeholder'=>' City................ ',
),
));
?>
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<input type="submit" class="btn btn-primary btn-lg" value="submit"/>
</div>
</div>
</form>
I have been trying to load remote content for different bootstrap modal on same yii2 view
<?php
$label = $model->getAttributeLabel('educationId');
$addon = [
'prepend' => [
'content' => Html::icon('book')
],
'append' => [
'content' => Html::button(
Html::icon('plus'), [
'class' => 'btn btn-success',
'title' => 'Add New' . $label,
'onclick' => new JsExpression('showModal();'),
]
),
'asButton' => true
]
];
echo Html::tag('label',$model->getAttributeLabel('educationId'), ['class'=>'control-label']);
echo Select2::widget([
'model' => $model,
'attribute' => 'educationId',
'data' => ArrayHelper::map ( EducationLevel::find ()->all (), 'id', 'name' ),
'options' => ['placeholder' => 'Select Education Level ...','template' => 'label}\n{error}'],
'addon' => $addon,
'pluginOptions' => [
'maximumInputLength' => 10
],
]);
JS function
Function showModal(){
$('#addEducationModal').modal({
remote: 'modal.html',
show: true
});
}
So the user will click on the addon button of a text field and the modal will show up, and other text fields shall have same mechanism with different modal content.
However all what I get is faded background.
I was able to make it work and more than that.
The issue i had mainly because the yii cashes generated files so to resolve i deleted the generated files and made sure the content is generated fresh :)
and i havent used the JQuery load function.
see below code:
PHP View Code
$label = $model->getAttributeLabel('majorId');
$addon = [
'prepend' => [
'content' => Html::icon('book')
],
'append' => [
'content' => Html::button(Html::icon('plus'), [
'class' => 'btn btn-success',
'title' => 'Add New' . $label ,
'data-toggle' => 'modal',
'data-target' => '#addModal',
'href'=> 'addMajorModal.html',
]),
'asButton' => true
]
];
echo Html::tag('label',$model->getAttributeLabel('majorId'),['class'=>'control-label']);
echo Select2::widget([
'model' => $model,
'attribute' => 'majorId',
'data' =>ArrayHelper::map ( Major::find ()->all (), 'id', 'name' ),
'options' => ['placeholder' => 'Select Major ...','template' => 'label}\n{error}'],
'addon' => $addon,
'pluginOptions' => [
'maximumInputLength' => 10
],
]);
<div class="modal fade" id="addModal" >
<div class="modal-dialog" dir="rtl">
<div class="modal-content" dir="rtl">
<!-- Content will be loaded here from "addMajorModal.html" file -->
</div>
</div>
</div>
The Modal file content
<div class="modal-header panel-primary" dir="rtl" horizantal-aligned="">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">إضا�ة جديد</h4>
</div>
<div class="modal-body" dir="rtl">
<div id="login-boxs" class="login-popup>
<form id="newCat" method="post" class="signin" dir="rtl" action="#">
<div class="form-group">
<label for="certName" class="control-label">مسمى التخصص </label>
<input type="text" name="name" data-val="true" data-val-required="ErrMsg" data-rule-required="true" placeholder="مسمى الشهادة" class="form-control" id="certName">
</div>
<div class="form-group">
<label for="certShortDesc" class="control-label">وص� قصير </label>
<input type="text" name="shdesc" data-rule-required="true" placeholder="وص� قصير" class="form-control" id="certShortDesc" required>
</div>
</form>
</div>
</div>
<div class="modal-footer" dir="rtl">
<div class="col-lg-6" dir="rtl">
<div class="progress" >
<div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 100%;" id="progresBarUpload">
</div>
</div>
</div>
<div class="col-lg-6" dir="rtl">
<button type="button" class="btn btn-danger" dir="rtl" data-dismiss="modal"><i class="glyphicon glyphicon-remove"> </i>Close</button>
<button id="submitButton" type="button" dir="rtl" class="btn btn-primary" onclick="createCertificate()"><i class="glyphicon glyphicon-ok"> </i>Save changes</button>
</div>
</div>
Thats all, with this the modal will be loaded based on yii append generation of the HTML
As far as i know, this will be workable till Bootstrap 3.3 as remote content will be deprecated in version 4