I am trying to give the user to select the date he wants, and it will display the reservations for the day he selected. I am using Codeigniter, the MVC framework.
How am I setting a default value of the current date for an input date selection?
How am I sending the value to the controller and then I am using it for a function in the model.
<form id="form_reDate" name="form_reDate" method="POST" action="form_reDate.php">
<?php $r_date=#date('d-m-y'); ?>
<label for="reservations">Display reservations for :
<input type="date" id="date" name="re_date" style="margin-left: 0;"
min="2020-01-01" max="2020-12-31" value="<?php $r_date?>">
</label>
</form>
Controller:
public function form_reDate(){
$newDate = date("Y-m-d",strtotime($this->input->post('re_date')));
$data['tables'] = $this->Hosting_model->get_tables($newDate);
}
If you're using the default html of input type="date" to set its value you only use this php code.
<?php echo date('Y-m-d') ?>
to sum it:
<input type="date" id="date" name="re_date" style="margin-left: 0;"
min="2020-01-01" max="2020-12-31" value="<?php echo date('Y-m-d') ?>">
and for question #2 on how to send your input value to your Controller. Just make sure you get the data before sending it to your Model.
Related
i have two views, view-1 and view-2.
view-1 has form, which will store data temporary.
i want to get data from view-1 and send it to view-2, which has user profile, where temporary data from view-1 will be shown.
how we can achieve it in Laravel, i know we can store data in SQL
and then fetch it, but how to do it without storing to SQL.
my code:
view: 1
<form >
<div class="form-group">
<label class="col-form-label" >Date</label>
<input type="text" name="sdate" class="form-control">
<input type="submit" class="btn btn-primary" value="Add date" >
</div>
</form>
view 2 Controller:
public function report2($id)
{
$teacher = Teacher::teacher($id);
return View('teachers.report2' ,compact('teacher','today','sdate'));
}
Route:
Route::get('teachers/{id}/report2', 'TeachersController#report2');
Use session, for example in view1 you pass variable of date do this on your controller of view 1
session(['sdate' => $request->sdate]);
and then you can get the value of the session in your controller or view by calling this
$date = session('sdate');
further reading see the docs
i was able to do it using simple php;
in view 1 i added this code:
<form action="report2" method="get">
Date: <input type="text" name="today" placeholder="Date of Birth" class="datepicker form-control"><br>
<input type="submit">
</form>
Laravel view 2:
<?php echo $_GET["today"]; ?><br>
I want to parsing my label name="predictDataTemp" in form into my controller, I already set the value form my label, but when I want to request the data still null
content.blade.php
<div class="form-group" align="center">
<label for="exampleResult" name="result">Result</label>
<label for="examplePredict" id="predictData" class="form-control">
<input type="hidden" name="predictDataTemp">
</label>
</div>
controller
public function result(Request $request){
$this->validate($request,[
'mCalories'=>'required',
'mCholesterol'=>'required',
'mFat'=>'required',
'mProtein'=>'required',
'mSugars'=>'required'
]);
$item= array();
array_push($item,array('Calories'=>$request->mCalories,'Cholesterol'=>$request->mCholesterol,'Fat'=>$request->mFat,'Protein'=>$request->mProtein,'Sugars'=>$request->mSugars,'Predict'=>$request->predictDataTemp));
return json_encode($item);
}
Your input has no value.
If you want to give it a value with jQuery (looking at your previous comments)
Give the input an id
<input type="hidden" name="predictDataTemp" id="predictDataTemp">
Then assign it in jQuery
$('#predictDataTemp').val('pass value here');
label don't have name attribute, it has only two attribute for and form so you can pass value in hidden input tag, Read this article
Instead
<label type="text" for="examplePredict" id="predictData" name="predictDataTemp" class="form-control"></label>
Use this
<label type="text" for="examplePredict" class="form-control"></label>
<input type="hidden" name="predictDataTemp" id="predictData" value="something">
This answer is great! everything works fine with the datepicker.
But I have a problem with datetime-picker. as I see from another datetime field (without default value), the class used by that field defined as datetime-input.
So I tried to use :
$crud->set_js_config('assets/grocery_crud/js/jquery_plugins/config/jquery.datetime.config.js');
...
<script type="text/javascript">var js_date_format = "dd/mm/yyyy HH:mm:ss"; </script>
<input name="date" type="text" value="'.date("d/m/Y H:i:s").'" class="datetime-input" />
<a class="datetime-input-clear ui-button " tabindex="-1" role="button">Clear</a>
even i've tried using class "timepicker" :
<input name="date" type="text" value="'.date("d/m/Y H:i:s").'" class="datetime-input timepicker" />
but the jquery datetime picker function is not available. Any idea how to make it works? Thank you
try to use callback field values.
$crud->callback_add_field('date_feild_name',array($this,'set_default_date'));
public function set_default_date(){
$value = date("d/m/Y");
$return = '<input id="field-date_feild_name" name="date_feild_name" type="text" value="'.$value.'" maxlength="10" class="datepicker-input hasDatepicker">
<a class="datepicker-input-clear" tabindex="-1">Date feild name</a> (dd/mm/yyyy)';
return $return;
}
I'm building the website based on Joomla 3. I need to disable the validation of the fields: name, username, password1 (the second, because the first is password2) and email2 and use email1 as username (I installed the plugin Email for user authorization).
I have tried to remove these fields in file components/com_users/models/forms/registration.xml but the validation is still remaining. If I don't remove them but only change the rows required="true" to false for these fields the registration doesn't work at all and any user stored in the DB. How can I disable these fields?
It's not an easy workaround, and you will need some basic knowledge of Joomla and PHP, but I'll try to explain it to you as simple as i can.
>>> Creating view template override
First of all you will need to create your Registration view template override (to keep it Joomla update proof). To do so, create folder /templates/YOUT_TEMPLATE/html/com_users/registration and copy /components/com_users/views/registration/tmpl/default.php file there.
From now on you can modify registration output in your template folder.
>>> Modifying registration form output
By default Joomla takes all fields from form file /components/com_users/models/forms/registration.xml, where they are defined, and outputs them in a view. But if we don't want to use ALL the fields, we need to output fields manually.
My example code only output E-mail and Password fields for registration. Here's a sample code to do so: (default.php file)
<?php
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
?>
<div class="grid_8" id="register_block">
<div class="content_block">
<h1>Registracija</h1>
<div class="login<?php echo $this->pageclass_sfx?>">
<form id="member-registration" action="<?php echo JRoute::_('index.php?option=com_users&task=registration2.register'); ?>" method="post" enctype="multipart/form-data">
<div>
<div class="login-fields">
<label id="jform_email1-lbl" for="jform_email1">E-mail:</label>
<input type="text" name="jform[email1]" id="jform_email1" value="" size="30">
</div>
<div class="login-fields">
<label id="jform_password1-lbl" for="jform_password1">Password:</label>
<input type="password" name="jform[password1]" id="jform_password1" value="" autocomplete="off" size="30">
</div>
<button type="submit" class="button"><?php echo JText::_('JREGISTER');?></button>
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="registration2.register" />
<?php echo JHtml::_('form.token');?>
</div>
</form>
</div>
</div>
</div>
Please note, that I've also replaced task value from registration.register to registration2.register, I did this to bypass some of validation rules using my own controller.
>>> Creating controller override
Locate file /components/com_users/controllers/registration.php and create a copy of it called registration2.php in same folder.
Open file registration2.php and change It's class name from UsersControllerRegistration to UsersControllerRegistration2
From now on Joomla registration form will use this class to create a new user.
Find a method called register and find this line:
$requestData = JRequest::getVar('jform', array(), 'post', 'array');
This is where Joomla get's registration form data. Add the following lines:
$requestData['name'] = $requestData['email1'];
$requestData['username'] = $requestData['email1'];
$requestData['email2'] = $requestData['email1'];
$requestData['password2'] = $requestData['password1'];
It will add missing registration info, and help you pass validation.
NOTE: This is a sample code, to show the main logic. If anyone has a better solution, I'd be more than happy to hear it.
Following same idea, a simpler solution might be just including hidden inputs with values in com_users\views\registration\tmpl\default.php above
<button type="submit" class="btn btn-primary validate"><?php echo JText::_('JREGISTER');?></button>
add
<input type="hidden" id="jform[username]" name="jform[username]" value="username" />
<input type="hidden" id="jform_name" name="jform[name]" value="name" />
It would pass the validation and you would no longer need to override controllers etc.
i wanna ask something about codeigniter
here is the view
<input class="mws-textinput" name="div_id" type="text" readonly="readonly">
<input class="mws-textinput" name="div_name" type="text" readonly="readonly">
<input id="mws-jui-dialog-mdl-btn" class="mws-button blue small" type="button" value="Show Modal Dialog">
<div id="mws-jui-dialog">
<p><? (**i wanna call the function here**) ?></p>
</div>
here is the function in controller
function dialog(){
$query = mysql_query('select * from tbl_divisi');
while($isi=mysql_fetch_array($query)){
echo '';
}
}
what should i do?
There is two way either you can define this method in model and then call the method of that model in your view file or you can fetch all these values from controller. Here is the detail of how to use model in ci. http://ellislab.com/codeigniter/user-guide/general/models.html