passing value joomla - joomla

I have this selectbox and I want to pass the value selected
I have this in my view
<form id="search-restaurant" method="post" action="<?php echo JURI::root()?>index.php/hardware/buscarCategoria">
<?php
echo JHTML::_('select.genericlist', $options ,'myfilter','onChange="this.form.submit()"','value','text');
?>
</form>
I take the value seleted like this
$input=JFactory::getApplication()->input;
$value=$input->get('myfilter');
the value is correct but I do a print_r or echo of value
print_r($value);
I obtain 0combo or 1combo
why the combo works, it is ok??

Are you looking for something like this.
http://docs.joomla.org/API16:JHtmlSelect/options
You can pass the $selected argument with proper value,It will set the default list option for you.

Related

open a modal windows in a server

Hi everyone I have a modal windows in joomla 3.0!
I pass the router to javascript like this
<?php $link =JURI::root().'index.php?option=com_projects&view=proyectos&format=raw&task=todosProyecto&id='. $item->id;?>
<li class="item" data-id="id-<?php echo $item->id ?>" data-type="<?php echo $item->categoria ?>">
<a href="#modal" id="<?php echo $link;?>" role="<?php echo $item->id ?>" class="picture" data-toggle="modal">
<img src="<?php echo JURI::root()?><?php echo $item->imagen_portada; ?>"/></a>
<p class="titulo"><?php echo $item->nombre; ?></p>
<p> <?php echo $item->municipio; ?>(<?php echo $item->pais; ?>)<br><?php echo $item->year; ?>
</p>
In local when I open the modal windows it work well, but in the server the modal windows show me the index.php view of this component.
I think that my problem is here, when I take the request for the model I have this.
public function elegirSeleccionados(){
$this->pagination = $this->get('pagination');
$this->items = $this->get('recientes');
$this->list = $this->get('list');
parent::display();
}
But $this->get('list'); is null so I have to asigned a null value to list.
I changed by that..
$this->list = $this->items;
but dont work to!
Any idea!!!
Where is this code?
First part looks like a Layout (views\proyectos\tmpl\default.php) and the second one like a View (views\proyectos\view.html.php).
If it is so, I'd say you are not really loading items in View from the Model. Try using $this->items = $this->get('Items');
But this doesn't explain different results on server and local host.
Hi everyone I solved the problem... the name of my view hava a Camelcase for example itemId and joomla try to find itemid, so donĀ“t find the view and show the default view in the modal.
So I change the name of file without camelCase and now work.!

Update multilingual content with AJAX in Yii

Refer to my code below, when user click on en button, the content will be changed to English, while clicking tw button, the content will be changed to Chinese.
However, the page will be refreshed each time when user click either en or tw button. I want to ask how can I implement AJAX content update in this case?
The result is when user click either en or tw button, the page won't be refreshed to change the content language.
Thanks
I have refer to Yii docs here, but seem that it is not appropriate for my case
C:\wamp\www\website\protected\views\site\index.php
<?php
$lang = isset($_GET["lang"]) ? $_GET["lang"] : "en_uk";
$lang = $lang == "en" ? "en_uk" : "zh_tw";
Yii::app()->setLanguage($lang);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="submit" value="en" name="lang" />
<input type="submit" value="tw" name="lang" />
</form>
<div class="main">
<?php echo Yii::t(Yii::app()->controller->id, "Causeway Bay"); ?>
</div>
Best practice is to reload the page in these cases, because usually you have to update so much, that it is just not worth it.
That said, CHtml's ajaxSubmitButton is the cleanest way to implement this, because you can map every event of your call very easily. It looks something like this:
<?php
echo CHtml::ajaxSubmitButton('en', CHtml::normalizeUrl(array('site/changeLanguage')),
array(
'error'=>'js:function(){
alert("error");
}',
//if you add a return false in this, it will not submit.
'beforeSend'=>'js:function(){
alert("beforeSend");
}',
'success'=>'js:function(data){
alert("success, data from server: "+data);
}',
'complete'=>'js:function(){
alert("complete");
}',
//'update'=>'#where_to_put_the_response',
)
);
?>
You don't have to use every parameter of course. The update parameter can update a HTML tag instantly.
EDIT:
This can be done easily if you use the controller's renderPartial method, for instance in your site controller if you have the action responsible for the index.
public function actionIndex(){
//get variables, etc
if(Yii::app()->request->isAjaxRequest) {
$lang = $_POST['nameOfSubmit'];
}else {
//...
}
//if the 3rd parameter is true, the method returns the generated HTML to a variable
$page = $this->renderPartial('_page', array(/*parameters*/ ), true);
echo $page;
}
And then, in your view file you can simply have
<?php echo CHtml::ajaxSubmitButton('en', CHtml::normalizeUrl(array('site/index')),
array('update'=>'#content_div',));?>
and
<?php echo CHtml::ajaxSubmitButton('tw', CHtml::normalizeUrl(array('site/index')),
array('update'=>'#content_div',));?>

$js in select dropdown in codeigniter

I have a js in a folder js. I call the file in the header.
I have the next code in my view:
<?php echo form_dropdown('mydropdown',$options) ?>
I need to pass the paramether $js, could you help me with the syntax?
$js = 'id="shirts" onChange="display(this,\'id1\',\'id2\');"';
<?php echo form_dropdown('mydropdown',$options, $js) ?>
When I see the source code of my dropdown I can't see the id="shirts", then I believe that the function javascript is not recognized.
What's my error. My codeigniter version is 2.0.
Thanks.
javascript should be the fourth parameter to this call. So add a null parameter in the third (which is for the selected value of the dropdown):
<?php echo form_dropdown('mydropdown',$options, null, $js) ?>
http://ellislab.com/codeigniter/user_guide/helpers/form_helper.html

How to remove the action attribute in the form_open_multipart() in Codeigniter?

Is there a way that I can remove the action attribute in CodeIgniter?
The code would normally be like this:
form_open_multipart('person/add', $attributes);
I was hoping that I could omit the first parameter so that I could not have an action attribute in the mark-up.
Thanks for those who could help.
Sure you can but consider:
1) The action attribute has a meaning and a function, don't know why you want it out
2) You can always pass it an empty string :
<?php echo form_open('');?>
or <?php echo form_open_multiaction('');?>
gives:
<form action="" method="post">
In case you're really sure about this, just open up the form_helper.php file, located in system/helpers/form_helper.php.
Pick lines 59 - 65 :
$action OR $action = $CI->config->site_url($CI->uri->uri_string());
$form = '<form action="'.$action.'"';
$form .= _attributes_to_string($attributes, TRUE);
$form .= '>';
and change line 60 to
$form = '<form ';
form_open_multiaction() just picks the form_open() and adds the enctype attribute, so you change form_open() and you're set.
It's up to you now, I still fail to see why an empty action won't suffice to your goals.

CodeIgniter - Setting Checkbox/Radio values from SQL query

I'm trying to create an edit page, which brings all of the original values from the database in at first, then let's the form_validation library take over afterwards. I have managed to get everything working as intended but checkboxes and radio buttons.
Here's an example of my form, pretty generic...
<input type="checkbox" name="protocols[]" value="online" <?php echo set_checkbox('protocols[]', 'online');?> />
<input type="checkbox" name="protocols[]" value="network" <?php echo set_checkbox('protocols[]', 'network');?> />
<input type="checkbox" name="protocols[]" value="splitscreen" <?php echo set_checkbox('protocols[]', 'splitscreen');?> />
The database values return as a comma separated string (online,splitscreen).
I also have another 3 field checkbox array to populate, a 9 field checkbox field, and a 3 field radio section to fill.
Any help would be greatly appreciated, thanks.
Remove the brackets from the field name in your call to set_checkbox():
<input type="checkbox" name="protocols[]" value="online" <?php echo set_checkbox('protocols', 'online');?> />
<input type="checkbox" name="protocols[]" value="network" <?php echo set_checkbox('protocols', 'network');?> />
<input type="checkbox" name="protocols[]" value="splitscreen" <?php echo set_checkbox('protocols', 'splitscreen');?> />
The form validation library will take care of checking the box or not, but it responds to the $_POST array only, so you'll have to use the third parameter to get the inputs checked by default:
set_checkbox()
Permits you to display a checkbox in the state it was submitted. The
first parameter must contain the name of the checkbox, the second
parameter must contain its value, and the third (optional) parameter
lets you set an item as the default (use boolean TRUE/FALSE).
Not a great explanation, but here's an example. First get your values from the comma separated string:
The database values return as a comma separated string (online,splitscreen).
// Something like this
$values = explode(',', $my_data); // Now it's an array
Then check if each checkbox's value is in that array:
<?php echo set_checkbox(
'protocols',
'splitscreen',
in_array('splitscreen', $values) // TRUE checks the box, FALSE does not
);?>
I'd do this in a loop for convenience reasons if nothing else. It's also worth looking at form_checkbox() which will make this a good deal easier.
See user guide for details: http://ellislab.com/codeigniter/user_guide/helpers/form_helper.html

Resources