I'm developing a Joomla Website using the T3 Framework.
I followed this article to duplicate and arrange a second layout.
Is it possible to assign this layout to a specific article or using the menu?
It is possible to assign a dynamic layout in the main tamplate file inside "tpls".
Something like this:
<?php if(($article_id == 242) || ($article_id == 238) || ($article_id == 234) || ($article_id == 230)): ?>
<!--/* Slider Comunicações */-->
<jdoc:include type="modules" name="<?php $this->_p('slidercommunications') ?>" style="raw" />
<?php elseif(($article_id == 244) || ($article_id == 240) || ($article_id == 236) || ($article_id == 232)): ?>
<!--/* Slider Energias Renováveis*/-->
<jdoc:include type="modules" name="<?php $this->_p('sliderrenewableenergies') ?>" style="raw" />
<?php elseif(($article_id == 243) || ($article_id == 239) || ($article_id == 235) || ($article_id == 231)): ?>
<!--/* Slider Segurança Electrónica */-->
<jdoc:include type="modules" name="<?php $this->_p('sliderelectronicsecurity') ?>" style="raw" />
<?php elseif(($article_id == 245) || ($article_id == 241) || ($article_id == 237) || ($article_id == 233)): ?>
<!--/* Slider Aeronáutica */-->
<jdoc:include type="modules" name="<?php $this->_p('slideraeronautics') ?>" style="raw" />
<?php else : ?>
Related
My program brings a list of a teacher from a table.
Then I want to show the names in the drop-down but for some reason, it opens an empty dropdown with the number of empty lines like the records in the table.
This is my code for this problem
<div>
<label for="teacher_name"> שם המורה: </label>
<select name="teacher_name" id="teacher_name">
<?php if (empty($teachers)): ?>
<p> No teachers found</p>
<?php else: ?>
<?php if($status == 'new'): ?>
<option value="please_select">נא לבחור</option>
<?php foreach ($teachers as $teacher): ?>
<option value=<?=$teacher['teacher_name']; ?> name="teacher_name" id="teacher_name"></option>
<?php endforeach; ?>
<?php endif; ?>
<?php if($status == 'edit'): ?>
<p> edit</p>
<input type="text" name="teacher_name" id="teacher_name" value="<?= htmlspecialchars($lesson->teacher_name); ?>" >
<?php endif; ?>
<?php endif; ?>
</select>
</div>
If you "view source" of your output I think you will see that the option tags do have data in them - but you haven't set the value to display, it should be more like <option ....>Show this in the list</option>.
Try this (the same code as you were using, but adding the teacher name variable again where it will display)
<option value=<?=$teacher['teacher_name']; ?> name="teacher_name" id="teacher_name"><?=$teacher['teacher_name']; ?></option>
I have a dynamic form that is populated with check boxes. I'm trying to implement a permissions / roles system for my dashboard.
the form is populated depending on what permissions are stored in the db. for this example i only have 2. this is the code for the form :
if (!empty($permissions)) {
foreach ($permissions as $perm) {
?>
<tr>
<td><?php echo $perm->display_name; ?></td>
<td class="text-center"><div class="checkbox checkbox-success checkbox-circle mb-2 ml-2">
<input name="view[]" id="<?php echo $perm->id ?>-view" type="checkbox" value="1">
<label for="<?php echo $perm->id ?>-view"> </label>
</div></td>
<td class="text-center"><div class="checkbox checkbox-success checkbox-circle mb-2 ml-2">
<input name="edit[]" id="<?php echo $perm->id ?>-edit" type="checkbox" value="1">
<label for="<?php echo $perm->id ?>-edit"> </label>
</div></td>
<td class="text-center"><div class="checkbox checkbox-success checkbox-circle mb-2 ml-2">
<input name="create[]" id="<?php echo $perm->id ?>-create" type="checkbox" value="1">
<label for="<?php echo $perm->id ?>-create"> </label>
</div></td>
<td class="text-center"><div class="checkbox checkbox-success checkbox-circle mb-2 ml-2">
<input name="delete[]" id="<?php echo $perm->id ?>-delete" type="checkbox" value="1">
<label for="<?php echo $perm->id ?>-delete"> </label>
</div></td>
</tr>
<input type="hidden" name="permission_id[]" value="<?php echo $perm->id ?>">
<input type="hidden" name="permission_name[]" value="<?php echo $perm->permission_name ?>">
<?php
}
}
?>
the form works great and is displayed like this :
this is my controller code :
public function setPermissions()
{
if ($this->isAdmin() == true) {
$this->loadThis();
} else {
// GET FORM FIELD INPUTS
extract($_POST);
foreach ($permission_id as $key => $permission_id) {
$data = array(
'permission_id'=> $permission_id,
'permission_name' => $permission_name[$key],
'can_view' => $view[$key],
'can_edit' => $edit[$key],
'can_create' => $create[$key],
'can_delete' => $delete[$key],
'role_id' => $roleId,
);
$result = $this->settings_model->setPermissions($data);
}
}
if ($result > 0) {
$this->session->set_flashdata('success', 'Permissions set successfully');
} else {
$this->session->set_flashdata('error', 'Setting permissions failed');
}
// LOAD VIEW
redirect('staffPermissions');
}
and my model :
public function setPermissions($data)
{
$this->db->trans_start();
$this->db->insert('app_staff_permissions', $data);
$this->db->trans_complete();
return true;
}
i have tried the trick of putting a hidden input field above the checkbox's but this only returns a result for the last row added to the db.
The problem i having is when a check box is not checked i get an error that the variable is not declared. Presumably this is because it is returning a null value.
i have tried to check for a value like this :
'can_view' => ($view[$key]) == '1' ? '1' : '0',
'can_edit' => ($edit[$key]) == '1' ? '1' : '0',
'can_create' => ($create[$key]) == '1' ? '1' : '0',
'can_delete' => ($delete[$key]) == '1' ? '1' : '0',
but that also does not work and throws the same error. i have tried an if else statement within the array but that obviously does not work. I'm really stuck with this now and willing to try any suggestions.
Is there any way to check if the value is null and if so assign a '0' to it?
Edit :
i have tried hundreds of different ways to solve this problem and i think by using
'can_view' => isset($view[$i]) ? 'on' : 'off',
'can_edit' => isset($edit[$i]) ? 'on' : 'off',
'can_create' => isset($create[$i]) ? 'on' : 'off',
'can_delete' => isset($delete[$i]) ? 'on' : 'off',
i over come the variable's not being designed and it does write either 'off' or 'on' in the db.
However i get a strange behaviour that only the first row gets inserted. for example if i set my check-boxes (now changed to toggle switches) like this :
i would expect my database to look this
on | off | on | off ---- off | on | off | on
but instead this is what i get :
Another strange thing i have noticed is they are being inserted from the bottom, The first column 'id' is an AI column but the id's are incrementing backwards up the table.
The bottom row was the first one inserted. Now you can see that only the first row contains any of the checkbox's 'on' fields, the second is off or null. when we should see on, off, on, off etc.
I have tried including the db call within the foreach loop in controller and doing a regular $this->db->insert and have also tried removing it out of the for each and using $this->db->insert_batch
The other parameters permission_id and permission_name iterate through the loop fine, its as though something breaks when it gets to the checkbox data.
you can use isset to check if a variable is declared and is different than NULL.
'can_view' => isset(view[$key])? '1' : '0',
'can_edit' => isset($edit[$key])? '1' : '0',
'can_create' => isset($create[$key])? '1' : '0',
'can_delete' => isset($delete[$key])? '1' : '0',
My function is when I will check then 1 will insert and if not then by default the field will fill with 0.At the time of insert problem is not happen, it store '1' to db but at the time of update with check box it not able to send '1' again to db, it sending 0.
AT THE INSERT TIME
View
.
<?php echo form_checkbox("feature_opd","1", set_checkbox("feature_opd","1")); ?>
<?php echo form_checkbox("feature_gyane","1", set_checkbox("feature_gyane","1")); ?>
<?php echo form_checkbox("feature_iui","1", set_checkbox("feature_iui","1")); ?>
Model
public function add_article($array)
{
return $this->db->insert('table_name',$array);
}
AT THE UPDATE TIME
View
<div>
<?php
if($article->feature_opd == 1)
{?>
<input type="checkbox" name="feature_opd" checked >
<?php
}
else
{?>
<input type="checkbox" name="feature_opd" >
<?php
}
?>
</div>
<div>
<?php
if($article->feature_gyane == 1)
{?>
<input type="checkbox" name="feature_gyane" checked>
<?php
}
else
{?>
<input type="checkbox" name="feature_gyane" >
<?php
}
?>
</div>
<div>
<?php
if($article->feature_iui == 1)
{?>
<input type="checkbox" name="feature_iui" checked>
<?php
}
else
{?>
<input type="checkbox" name="feature_iui" >
<?php
}
?>
</div>
Model
public function update_article($article_id , array $article)
{
return $this->db
->where('id',$article_id)
->update('ivf_productsettings', $article );
}
My Query is how I will update db with check box. I am facing problem to update with check box in Codeigniter, Please suggest me , if my code going to tough then please suggest me in simple way how to update with check box in codeigniter .I am new in ci .
You can create your update checkboxes like so:
<?php echo form_checkbox("feature_iui","1", set_checkbox("feature_iui","1", $article->feature_iui)); ?>
The default value will apply from the db.
Aside from that there is nothing aside from user input preventing the checkboxes from being properly sent. Thus, any code that is causing a 0 being put in the db is probably due to how you are processing the checboxes in your controller update function. As I've said in the comments, checkboxes only submit 1's never 0's.
Sorry I am new to WordPress and still having difficulty to retrieve my data from my custom database. So far this is my code for submitting data to my wp_datareg table.
<?php
/*
Template Name: Data-Register
*/
get_header();
?>
<?php
If($_POST['Submit']) {
global $wpdb;
$Data1=$_POST['Data1'];
$Data2=$_POST['Data2'];
if($wpdb->insert(
'wp_datareg',
array(
'Data1' => $Data1,
'Data2' => $Data2
)
) == false) wp_die('Database Insertion Failed');
else echo '<h2>Database Insertion Succesful</h2><p />';
?>
<?php
}
else // else we didn't submit the form so display the form
{
?>
<
<h4>Data Registration Form</h4>
<form action="" method="post" id="addcourse">
<p><label>Put Data1:<input type="text" name="Data1" size="30" /></label></p>
<p><label>Put Data2: <input type="text" name="Data2" size="30" /></label></p>
</div>
<input type="submit" name="Submit" id="addcoursesubmit" value="Submit" />
</form>
What I want to add is put another text form and search button where user can search a data of Data1 and edit its value on the form, (please see the image)
Sorry for being such a noob.
PLEASE SEE THIS IMAGE
Thank you.
br
We can fetch data from wp_datareg table using this code, however putting back the data to the form is my problem.
global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM wp_datareg" );
foreach ( $result as $print ) {
?>
<tr>
<td><?php echo $print->Data1;?></td>
</tr>
I have a zend_form with a checkbox:
$horz = new Zend_Form_Element_Checkbox('horizontal');
$horz->setLabel('Display horizontally?');
$horz->setDecorators(array(array('ViewScript', array('viewScript' => 'partials/forms/checkbox.phtml'))));
My custom viewScript checkbox.phtml looks like this:
<?php
$name = $this->element->getName();
$attrs = $this->element->getAttribs();
$options = $attrs['options'];
?>
<dt id="<?= $name ?>-element">
<input type="hidden" value="<?= $options['uncheckedValue'] ?>" name="<?= $name ?>" />
<label>
<input type="checkbox" class="checkbox" value="<?= $this->element->getValue() ?>" id="<?= $this->element->getId() ?>" name="<?= $name ?>">
<?= $this->element->getLabel(); ?>
</label>
</dt>
It renders beautifully, but when I populate the form from a database record:
$record = array('horizontal'=>1);
$form->populate($record);
The checkbox is not checked. Is there something I need to set in my viewScript to allow it to populate?
You have to check the box in your html view script after the value is populated.
<input type="checkbox" class="checkbox" value="<?= $this->element->getValue() ?>" id="<?= $this->element->getId() ?>" name="<?= $name ?>" <?php echo $this->element->isChecked() ? " checked=\"checked\"" : "" ?> />