Set default value in form field - php

I have a form in a Joomla component in which the user needs to select a country and then a city depending on the country selected. In my case I only need one country. How can I edit or replace the code below to set the country to a default value and remove it from the form?
<div class="form-group">
<label for="submit-location"><?php echo JText::_('COM_BT_PROPERTY_LOCATION');?></label>
<?php echo $this->form->getInput('country'); ?>
</div>
<div class="form-group">
<?php echo $this->form->getInput('city'); ?>
</div>
Thank you for your time. Any suggestion is much appreciated!

Related

PHP - dropdown list content showing href link content without selection

I have a variable numbr forms I want a user to be able to choose to view via a drop down list. I have assigned each of the form content to array $forms & the associated form name to array $formnames
The idea was to display the variable number of form names as buttons in the drop down selection, and once selected it would display the form content.
I've tried the below code but this leads to the drop down selection immediately showing both the form content as well as name. Could someone point me in the right direction given my limited understanding?
<div class="dropdown">
<button onclick="dropdownfunction()" class="dropbtn">Available List</button>
<div id="avaiablelist" class="dropdown-content">
<?php
$keys = array_keys($forms);
$namekeys = array_keys($formnames);
$arraysize = count($forms);
for($i=0; $i<$arraysize;$i++) { ?>
<?php echo $formnames[$i]['formname']; ?>
<?php
}
?>
</div>
</div>
In this case i would use
<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> method="post">
</form>
to send $forms[$i]['form'] via Post method

How to pass php variable to modal window

I am making a simple page and I have found this little problem. I have this in my template:
<?php foreach ($this->vypis_serie as $value) : ?>
<div class="serie">
<div id="serie_header">
<?= $value['nazev_cviceni'] ?>
</div>
<div id="serie_info">
<p>Number of excercises: TODO</p>
<p>Sport type: <?= $value['typ'] ?></p>
<p>KCal summary: <?= $value['kcal'] ?></p>
</div>
<div class="button_upravit">Edit</div>
<div class="button_smazat">Delete</div>
</div>
<?php endforeach; ?>
basically it is a block that fills in information about particular exercise (it is a sport app). SO If I have 3 entries in DB, it will print this code three times with corresponding info.
The problem I have is with the edit button, which upon clicking opens modal window. It is made purely with CSS, so no Javascript.
When I click the button, it jumps to this code:
<div id="openModal_edit" class="modalDialog">
<div>
X
<div id="editace">
<form id="platba" action="serie/edit/" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Edit serie</legend>
<ol>
<li>
<label for="name">Name of the series</label>
<input id="name" name="nazev_cviceni" type="text" required autofocus>
</li>
<li>
<label for="typ">Sport type</label>
<select name="typ">
<option value="Kolo">Bike</option>
<option value="Běhání" selected="selected">Running</option>
</select>
</li>
</ol>
</fieldset>
<fieldset>
<button type="submit">Save</button>
</fieldset>
</form>
</div>
</div>
</div>
But since I jump to div id and I am not using a new page where I could choose a controller and pass a variable, I need somehow to pass the variable (id of the exercise) to the modal window, so I can know which of the possible buttons I have clicked. Is there any way to do it, without the need to rewrite all other pages where I have used this modal window?
I can't use another foreach like in the first part, because the modal window is always a single object that appears, unlike all the entries on the page that are there as many times as there are entries in the DB.
Hope that it is understandable, sorry for my English :)
The simplest way to do this using a single modal window involves adding some javascript code to your page.
First, add the relevant information to the edit link, with a new data-serie-<name> for each piece of data you want to pass:
<a href="#openModal_edit" data-serie-name="<?= $value['nazev_cviceni'] ?>" ...>
Next, add an onclick event handler to that same link. This handler will extract the embedded data from the <a> element and inject it in the modal window. The dataset element provides access to the data-* attributes from javascript
// Example
onclick="serieName=this.dataset.serieName;document.querySelector('#openModal_edit input#name').value = serieName;return true;"

show the item to edit on dropdown

I am using the same view page for both submitting data to database and editing. When I submit the form all the elements go to database. When editing the input field contains the item to edit but the dropdown form doesnot load and displays error saying $expensetype not defined. the $expensetype is passed through the controller to the form. I am developing in pyrocms. Pyrocms is developed in Codeigniter.
<li>
<label for="expense_type_id">Expense Type</label> <!-- expense_type_id-->
<div class="input">
<?php echo form_dropdown("expense_type_id",$expensetype, set_value("expense_type_id", $expense_type_id)); ?>
</div>
</li><li>
<label for="expense_rs">Expense(NRS)</label> <!-- expense_rs-->
<div class="input">
<?php echo form_input("expense_rs", set_value("expense_rs", $expense_rs)); ?>
</div>
</li>
How to make the dropdown to show the item while editing.

add custom field in com_category joomla 3.x

i need to add a field into component com_categories, this is for i need add new values in categories, for example these are the archives that i modified:
Joomla 3.1.5
administrator\components\com_categories\views\category\tmp\
<div class="control-group">
<div class="control-label">
<?php echo $this->form->getLabel('subtitulo'); ?>
</div>
<div class="controls">
<?php echo $this->form->getInput('subtitulo'); ?>
</div>
</div>
and too in this file:
administrator\components\com_categories\models\forms\category.xml
<field
name="subtitulo"
type="textarea"
label="subtitulo"
description="USE ESTE SUBTITULO"
rows ="4" cols="6" filter="raw"
/>
So, the new field appear in backend administrator but when i save the new data incustom field... disapear!
The problem would be save the new field into Database or another method, because when i modify the template (default_items.php) can i se the changes i do, the new field if is saved must be appear using
<?php
print_r($this);
?>
but dont appear the new data (subtitulo), whats wrong??, how can i do to add new field in mod_categories and access it.

How to add a textfield in form with out model class in YII?

I need to add a text field in YII form in which i am not specify any model class name. But I need to process that value in the action method inside the controller class.
ie
I need to add a text field as
<div class="row">
<input type="text" name="test" id="test" >
</div>
I add text field as
<?php echo $form->textField($model['groupModel'],'group_name',array('size'=>60,'maxlength'=>128)); ?>
But i do't want to specify any model name with the new text field..
Thanks in advance...
This should work
<div class="row">
<?php echo CHtml::textField('User[textvalue]', '', array('size'=>60,'maxlength'=>128)); ?>
</div>
This will give you the text value inside $_POST['User'] as $_POST['User']['textvalue']
You can add a Chtml textfield with an id
It will the show in the: $_POST['mytextField']

Categories