Codeigniter : Validating - date not to be longer than two date - codeigniter

I need resolve this problem:
1) I have in my project two Date input
2) I need the registration(first date) date not to be longer than the date of the tournament(second date).
<div class="form-group">
<label for="date"><?php echo $lang['date_tournament']; ?></label>
<input type="text" class="form-control datepicker" name="date_tournament" required>

<?php $first = strtotime($registrationdate);
$second = strtotime($tournamentdate);
$datediff = $first - $second;
if(floor($datediff / (60 * 60 * 24))<2){
echo 'valid';
} ?>

Related

October CMS: AJAX form

My aim is to update a partial to show course dates when a date range is specified and submitted.
I have a function that works as expected.
user selects a start date
user selects an end date
the user clicks search
results are logged to the console
Here is the function
function onFetchDataFromServer()
{
$course = Course::findOrFail( $this->param('id') );
$start = Input::get('start_date');
$end = Input::get('end_date');
$dates = $course->coursemetas->whereBetween('date', array($start, $end));
return $dates;
}
Here is the markup
<form class="row gx-3 align-items-center" data-request="onFetchDataFromServer" data-request-success="console.log(data)"">
<div class="col-12 col-lg pxp-has-left-border">
<div class="input-group mb-3 mb-lg-0">
<span class="input-group-text"><span class="fa fa-calendar-o"></span></span>
<input type="date" class="form-control" id="startPicker" name="start_date" placeholder="Choose a start date">
</div>
</div>
<div class="col-12 col-lg pxp-has-left-border">
<div class="input-group mb-3 mb-lg-0">
<span class="input-group-text"><span class="fa fa-calendar-o"></span></span>
<input type="date" class="form-control" id="endPicker" name="end_date" placeholder="Choose an end date">
</div>
</div>
<div class="col-12 col-lg-auto">
<button type="submit">Search dates</button>
</div>
</form>
So the rather than logging the results to the console, I now would like to update a partial.
I have a partial in the view called 'course/metas'.
Can someone please help me?
Thanks in advance.
You can try something like this. Check the documents here.
This is for a page's PHP section:
function onFetchDataFromServer()
{
$course = Course::findOrFail( $this->param('id') );
$start = Input::get('start_date');
$end = Input::get('end_date');
$dates = $course->coursemetas->whereBetween('date', array($start, $end));
$this['dates'] = $dates;
return [
'#myDiv' => $this->renderPartial('coursemetas')
];
}
This is for component plugin:
function onFetchDataFromServer()
{
$course = Course::findOrFail( $this->param('id') );
$start = Input::get('start_date');
$end = Input::get('end_date');
$dates = $course->coursemetas->whereBetween('date', array($start, $end));
$this->page['dates'] = $dates;
return [
'#myDiv' => $this->renderPartial('#coursemetas')
];
}
Note the # sign sent with the renderPartial as this tells the framework to look inside the plugin folder for the partial. Or you can specify the partial path by component and partial name like this return $this->renderPartial('course::coursemetas');.

Pass a date input value from View to Controller using Codeigniter

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.

Populate input field from a dropdown using codeigniter

chapter_number | chapter_title |
1 | Introduction |
2 | Number System |
<select type="text" name="chapter_number" class="form-control form-control-line" value="">
<option selected="option" disabled="selected">Select</option>
<option value="1">1</option>
<option value="2">2</option>
</select
<input type="text" name="chapter_title" id="title" class="form-control"/>
above is my table and next is my code the select option and the input field. I want that when I select '1' automatically the input field will print chapter title 'Introduction' and If I select '2' the input field will became 'Number System'.
If you want to get data from database you need to call ajax on onchange event of select box.
Add "setinput" class to select box
<select type="text" name="chapter_number" class="form-control form-control-line setinput" value="">
Add below script
$('body').on('change','.setinput',function(){
$.ajax({
url: 'your_base_url/controller_name/your_method',
type:'POST',
data:{id:$(this).val()},
success:function(result){
$('input[name="chapter_title"]').val(result);
}
})
});
Controller method would be like below
public function your_method(){
$id = $this->input->post('id');
$this->db->select('*');
$this->db->from('database_table_name');
$this->db->where('chapter_number',$id);
$result = $this->db->get()->row();
echo $result->chapter_title;
}
I hope, it would be helpful to you.

How to block emoticons from input text field in codeignitier

I want to make input text field in such a way that it will block emoticons entry in text input field. I have made validation on controller for particular route by passing.Is it is a right way to block emoticons.
Controller code.
$this->form_validation->set_rules('registration', 'Registration', 'required|alpha_numeric');
$this->form_validation->set_rules('odometer', 'Odometer', 'required|alpha_numeric');
view code:
<input type="text" name="odometer" placeholder="Odometer" class="form-control profileControl odometer required number" id="odometer-<?php echo $vehicle_count; ?>" value="<?php echo $vehicle->intCarOdometer ?>"/>
<input type="text" placeholder="Registration" name="registration" class="form-control profileControl registration required" id="registration-<?php echo $vehicle_count; ?>" value="<?php echo $vehicle->vchCarRegistration ?>" pattern="[a-zA-Z0-9]+"/>
You can remove emoticons before sending to the server with jquery.
test this code.
var ranges = [
'\ud83c[\udf00-\udfff]', // U+1F300 to U+1F3FF
'\ud83d[\udc00-\ude4f]', // U+1F400 to U+1F64F
'\ud83d[\ude80-\udeff]' // U+1F680 to U+1F6FF
];
setTimeout(removeInvalidChars, 100);
function removeInvalidChars() {
var str = $('.valid-text').val();
str = str.replace(new RegExp(ranges.join('|'), 'g'), '');
$(".valid-text").val(str);
setTimeout(removeInvalidChars, 100);
}
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<input id="myinput" class="valid-text" type="email" name="myinput" value=" 😀 value 1 2 3 ? / "></input>

Where to find the select html tag for countries on the checkout page in Magento 1.8

Where can I the html select tag for countries on the checkout page?
<div class="field form-group">
<label for="billing:country_id" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
<div class="input-box">
<?php echo $this->getCountryHtmlSelect('billing') ?>
</div>
</div>
with this $this->getCountryHtmlSelect('billing'), it returns the html select tag below,
<select name="billing[country_id]" id="billing:country_id" class="validate-select" title="Country" >
<option value="" > </option>
<option value="AF" >Afghanistan</option><option value="AL" >Albania</option>
<option value="DZ" >Algeria</option>
...
But I need to add a class name to the select tag,
class="form-control validate-select"
But where can I find this select tag?
For add new class in select ...you need to flow below steps:
Step:copy app\code\core\Mage\Checkout\Block\Onepage\Abstract.php
to app\code\local\Mage\Checkout\Block\Onepage\Abstract.php
Here you have find the function getCountryHtmlSelect($type)
COde
$select = $this->getLayout()->createBlock('core/html_select')
->setName($type.'[country_id]')
->setId($type.':country_id')
->setTitle(Mage::helper('checkout')->__('Country'))
->setClass('validate-select')
->setValue($countryId)
Change to and i have added a new class mynewclass..
if($type=='billing')
{
$select = $this->getLayout()->createBlock('core/html_select')
->setName($type.'[country_id]')
->setId($type.':country_id')
->setTitle(Mage::helper('checkout')->__('Country'))
->setClass('validate-select mynewclass')
->setValue($countryId)
}else{
$select = $this->getLayout()->createBlock('core/html_select')
->setName($type.'[country_id]')
->setId($type.':country_id')
->setTitle(Mage::helper('checkout')->__('Country'))
->setClass('validate-select')
->setValue($countryId)
}

Resources