Welcome Guest, Not a member yet? Register   Sign In
Data type edit input
#1

Hi, having to edit an article already present, I come across the field composed of an input data.

PHP Code:
<div class="form-group mb-3 row">
   <label class="form-label col-3 col-form-label">Birth Date</label>
        <div class="col">
            <input type="date" name="birth" class="form-control" value="<?= esc($item->birth); ?>">
            <?= $validation->showError('birth'?>
        </div>
</div> 


Taking the current value (therefore a date and a date type field) unfortunately I do not take the date that I saved in the database in "strtotime" format.

PHP Code:
'birth' => strtotime(str_replace('/','-',$this->request->getVar('birth'))), 


How can I do?
Reply
#2

@Marcolino92,

Are you asking how to convert the date from your input field into a date that can be saved in the database?
Reply
#3

I was looking for a way to trace an input date, the date saved in the database in strtotime().

I solved it like this:


PHP Code:
<div class="form-group mb-3 row">
     <label class="form-label col-3 col-form-label">Birth Date</label>
      <div class="col">
         <input type="date" name="birth" class="form-control" value="<?= isset($item->birth) ? set_value('birth', date('Y-m-d', $item->birth)) : set_value('birth'); ?>">
         <?= $validation->showError('birth'?>
     </div>
</div> 


But now with the same speech, I can not show the category already present referred to a post, selected. I don't know how to explain it better, but imagine that you are editing a post and want to show yourself selected from a list, the category to which it belongs.

PHP Code:
<?php if (!empty($categories) && is_array($categories)) : ?>
<?php 
foreach($categories as $cat): ?>
<label class="form-selectgroup-item">
    <input type="radio" name="category" value="<?= $cat->id?>" class="form-selectgroup-input" <?= set_radio('category'$cat->id); ?>>
        <span class="form-selectgroup-box"><?= $cat->category_name?></span>
</label>
      <?php endforeach; ?>
  <?php else : ?>
     <span class="text-danger">There are no categories. <strong><a href="<?= site_url('admin/add_categories'); ?>">Add categories</a></strong> before inserting a new obituary.</span>
   <?php endif; ?>

I tried this, but it doesn't work (it shows the selected only after choosing a category and keeps it, but I want it to show me initially selected the category in which it is already present.)
Reply
#4

@Marcolino92,

I don't know if I understand what you are asking but I'm wondering if you can have the model pull the category related to the specific record and if it doesn't exist then use a default category value.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB