adding attributes to form_open_multipart - codeigniter

I was wondering how could we add attributes to file_upload in codeigniter
right now I am using form_open_multipart('controller');
but I want to add an id attribute to it.
Any help appreciated thanks!

From the User Guide:
form_open_multipart()
This function is absolutely identical
to the form_open() tag above except
that it adds a multipart attribute,
which is necessary if you would like
to use the form to upload files with.
So, you would use it in the same way you use form_open(). Example:
form_open_multipart('controller', 'id="my_id"');
Or:
form_open_multipart('controller', array('id' => 'my_id'));

Related

Dynamically add attributes to Laravel Blade components

I'm programatically building a form using Blade components and I can't find how to add attributes dynamically.
For example, I have an $attribute variable that contains ['data-id' => 123, 'step' => 0.01]. I want to integrate it to my form-number component so that the final result is equivalent to:
<x-form-number data-id="123" step="0.01" />.
Thank you.
<x-form-number :data-id="$attribute['data-id']" :step="$attribute['step']" />
from the doc
https://laravel.com/docs/8.x/blade#passing-data-to-components
The keys in the array are dynamic. I don’t know them in advance
Sure you know them in advance they are defined in your class. So you just have to popultae your array with all the keys (with defaut value accepted by your class)

How to add a new field to joomla register form?

I am trying to make a joomla plugin, but I have few questions that I haven't found any answer.
What the plugin has to do: add a new field in register form(let's say Cell Number), and on form submit insert that cell number in database.
My documentation is this tutorial.
Questions:
How do you add a new field in register form? xml file is done, but I am not sure how to write the php code...(please help). What this code do?
$form->setFieldAttribute('something', 'required', $this->params->get('profile-require_something') == 2, 'profile5');
How do I get the cell number variable from that form? $jinput = JFactory::getApplication()->input; ?
Pleas help me with few tips. Thanks!
Just copy the code that is there. What will happen is that the php will automatically loop through all the fields in your xml.
$form->setFieldAttribute('something', 'required', $this->params->get('profile-require_something') == 2, 'profile5');
Is taking the field with the name something and changing it to be required if the parameter called profile-require_something is set to 2 . profile5 is the name of the xml file and the php file for the example plugin. It's the actual name of the plugin. You can have many profile plugins if you want but each needs its own name.
To get the a value you would do something like
$jinput->getString('cell_number', '');

Magento: How to replace all {{example var="something"}} with actual data?

I’m working on custom feed generation.
All logic is in model. This Model called by cron by schedule.
The problem I’m facing is that in description content data like {{store url}}, {{config path="trans_email/ident_sales/email"}}, {{customVar code=phone}}, etc.
Could anyone tell how to properly replace these variables in model?
Thanks in advance!
Try
Mage::getModel('core/email_template_filter')->filter($description);
Some variables are Magento variables, like store_url, but you can add your own to filter:
Mage::getModel('core/email_template_filter')->setVariables(array('custom_url' => Mage::getUrl('*/*/custom'), 'custom_var' => 100))->filter($description);

Extend a Varien Form Element for a Custom Module

Improving on this question:
Is it good practice to add own file in lib/Varien/Data/Form/Element folder
The accepted answer shows how to extend a Varien form element, but this will not work if you want to package it into a custom module.
What would be the proper method of extending the Varien form element in a module? A simple XML setting I'm hoping?
Update:
Thanks Vinai for the response. Although that does work, I was hoping to extend the form element somehow. My extension is using the base File form element to allow administrators to upload files to categories. So, I'm not directly adding the form elements to the fieldset myself.
I suppose it's possible to to check for the file input on my category block on the backend: Mage_Adminhtml_Block_Catalog_Category_Tab_Attributes , and then change the form element if it is 'file' to 'mycompany_file' -- but this seems like a workaround.
Is there an easier way? Thanks again Vinai.
On the Varien_Data_Form instance you can specify custom element types like this:
$fieldset->addType('custom', 'Your_Module_Model_Form_Element_Custom');
Then, add your element with
$fieldset->addField('the_name', 'custom', $optionsArray);
If you are using a form without fieldsets you can do the same on the Varien_Data_Forminstance, too.
EDIT: Expand answer because of new additional details in the question.
In the class Mage_Adminhtml_Block_Widget_Form::_setFieldset() there is the following code:
$rendererClass = $attribute->getFrontend()->getInputRendererClass();
if (!empty($rendererClass)) {
$fieldType = $inputType . '_' . $attribute->getAttributeCode();
$fieldset->addType($fieldType, $rendererClass);
}
Because of this the attribute frontend_input_renderer on the attributes can be used to specify custom element classes.
This property can be found in the table catalog_eav_attribute, and luckily enough it isn't set for any of the category image attributes.
Given this, there are several ways to apply customizaton.
One option is to simply set the element class in the table using an upgrade script.
Another would be using an observer for the eav_entity_attribute_load_after event and setting the input renderer on the fly if the entity_type_id and the input type matches.
So it is a little more involved then just regular class rewrites in Magento, but it is quite possible.
You don't necessarily need to have a file in the lib/Varien/ directory in order to extend it. If you needed to add an element to that collection, you should be able to extend one of the Elements in your app/code/local module. The answer to the question you referenced seems to also indicate this is the case. I would create your custom field, extending its highest-level function set (i.e., lib/Varien/Data/Form/Element/File.php).
If you want to override the Mage_Adminhtml_Block_Catalog_Category_Tab_Attributes block, then you should extend that block in your module and then reference the new one. You may wish to extend the block using an event observer rather than an XML rewrite, for compatibility purposes.

Yii : form values retention for CHtml::checkBoxList on form validaton

I am using CHtml::checkBoxList for my form. For some reason I cannot use CHtml:activeCheckBoxList or CActiveForm::checkBoxList. Everything works fine only problem is that I loose checkbox values on form validation error. What could be the easiest way to fix this ?
If you're making a form, you probably want to use CActiveForm's checkboxlist, which is a form-specific wrapper of CHtml::activeCheckBoxList) instead. Something like
echo $form->checkBoxList(
$model,
'condiments',
array(
'ketchup'=>'Ketchup',
'mustard'=>'Mustard',
'relish'=>'Relish',
'onions'=>'Onions'
)
);
should give you a persistent check box list of hot dog condiments, for example.

Resources