Add form field to com_content in Joomla2.5 - joomla

Can someone help me figure out why this isn't working. It's actually group="content" plugin. I followed examples that I barely found on internet, but it was not enough. Following code was claimed to work but it does not for me.
Here is my onContentPrepareForm
function onContentPrepareForm($form, $data) {
echo "working aroptimizer ";
if (!($form instanceof JForm)) {
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// Check we are manipulating a valid form.
if (!in_array($form->getName(), array('com_contact.article'))) {
return true;
}
// Add the fields to the form.
JForm::addFormPath(dirname(__FILE__) . '/inc');
$form->loadFile('arform', false);
return TRUE;
}
and in inc/arform.xml I have following:
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="aroptimizer">
<fieldset name="ar"
label="AR Optimizer">
<field name="ar" type="list" label="Audience Match" description="Select your audience">
<option value="1">JSELECT</option>
<option value="1">DEPT_SALES</option>
<option value="2">DEPT_SUPPORT</option>
<option value="3">DEPT_BILLING</option>
<option value="4">DEPT_OTHER</option>
</field>
</fieldset>
</fields>
</form>
Goal for the above code is just to display form fields. All I wanna do is show some form fields to com_content(?option=com_content) page.
Thank You.

I made some progress. Basically, field name "aroptimizer" does not exist on com_content, therefore, it was not able to render it. I changed it to .
Secondly, following rule was never returned true. I will look into it later on. I've commented it out for now.
if (!in_array($form->getName(), array('com_contact.article'))) {
return true;
}
I know I am unable to provide enough information here, but that is all I know for now. For further information, visit following link: https://groups.google.com/d/topic/joomla-dev-general/UP8X-slm98E/discussion

Related

Livewire ignore does not receive correct data

I'm using selectize.js for dropdown styling with livewire. I'm using livewire for a data table with sortable columns and pagination. The issue is, every time I make pagination or a sort by column, the javascript goes missing thus, there's no styling for the dropdown. I've solved the styling issue using wire:ignore. Now the new problem that I have is that the data passed to the dropdown is not accurate.
#foreach($applications as $application)
<p>{{$application->status}}</p>
<div wire:ignore>
<select class="selectize" name="status" data-width="200px">
#foreach(['Pending',
'Hired',
'Under consideration'] as $status)
<option
#if($application->status === $status) selected #endif>{{ $status }}</option>
#endforeach
</select>
</div>
#endforeach
Inside the <p>{{$application->status}}</p> tag, I get the status 'Pending' but on the dropdown, it shows 'Hired'. The correct status is 'Pending'.
(from comment) #stalwart1014 for example, when I use "select2" I do this
in content section
<select id="select2" wire:model="some">
//.....
</select>
in script section
$(document).ready(function() {
window.initSelectDrop=()=>{
$('#select2').select2({
placeholder: '{{ __('Select') }}',
allowClear: true});
}
initSelectDrop();
window.livewire.on('select2',()=>{
initSelectDrop();
});
});
and in component
public function hydrate()
{
$this->emit('select2');
}
This not always function properly with JS element...but hope this can help you. Greetings
it's maybe a bit late, but worth to mention for the future, I will do not point directly to your issue but explain the workaround of wire:ignore, the wire:ignore directive ignores the updates or changes for the further requests and updates, this attributes is defined for playing with JS third party library, the wire:ignore directive prevent all it's nested elements from updating if you wish to except Childs from updating you can use wire:ignore.self directive

Keeping select values across pages

I have a couple of routes
Route::get('/route_one', 'IndexController#index');
Route::get('/route_two', 'IndexController#index');
They call the same controller function because these pages need the same array of data. This function is as follows
public function index()
{
$user = Auth::user();
if( $user ) {
$fileData = $this->fillArrayWithFileNodes(new DirectoryIterator( public_path(). '/images'));
$currentPath= Route::getFacadeRoot()->current()->uri();
if(!empty($fileData)) {
return view('index', compact('fileData', 'currentPath'));
}
} else {
return view('auth.login');
}
}
Now the index view is pretty straight forward, but it does has this part
#if($currentPath == 'route_one')
#include('layouts.searchbarRouteOne')
#endif
#if($currentPath == 'route_two')
#include('layouts.searchbarRouteTwo')
#endif
So depending on what route is called, a different sidebar is displayed. Now the sidebars essentially contain a load of select inputs like the following
<div class="col-lg-3">
<div class="form-group">
<label>Year</label>
<select id="year" class="form-control">
<option value=""></option>
#foreach($fileData["route_one"] as $year => $products)
<option value="{{ $year }}">{{ $year }}</option>
#endforeach
</select>
</div>
</div>
Both sidebars have different selects. When select options are selected, an ajax call is made to display an image. This all works fine.
This is my problem. I have a link to get to route_one or route_two. As the page refreshes when the link is clicked, the selects are at their default state. What I would like to do somehow is keep the last state of the select inputs. I am not storing this data within a database which may be an issue?
Furthermore, route_two relies on the select options from route_one. So when route_two is selected, I need to pass it route_ones options.
What would be the best way to achieve what I am after?
Thanks
Think what you are trying to accomplish here: remember the old input values.
You could send the form when clicking the link and flash the data in your controller or use JavaScript saving input values to the browser's storage.
Simple example using plain JavaScript
// Get all select-elements
var inputs = document.querySelectorAll('select');
// Loop through them
for (var i = 0; i < inputs.length; i++) {
// Set the old input value
inputs[i].value = localStorage.getItem(inputs[i].name);
// Start listening changes
inputs[i].addEventListener('change', store);
}
// The function to call when the value has changed
function store(event) {
// Set the new value to the browser's storage
localStorage.setItem(event.target.name, event.target.value);
}
In that example your form elements are required to have unique name attributes. Of course it can be switched out using e.g. id attribute.

Forms fields filtering issue in Magento 1.8.1.0

In account form fields or user registration page form fields for First name and Last name, when i place the following JS code :
<script>alert("Here")</script>
It is saved and is run on page load. This is very strange, because i checked the template files and values are escaped as below:
<?php echo $this->escapeHtml($this->getObject()->getFirstname()) ?>
I have also confirmed if i am in correct template file by changing the label of field.
I have read the following questions and tried to used them but did not worked for me.
https://magento.stackexchange.com/questions/569/how-to-escape-output-data
https://magento.stackexchange.com/questions/8179/is-there-a-generic-way-i-can-apply-input-filtering-to-magento-form-processing
Regarding to the observer method, it works, but when i try to login to magento admin, i cant, but when iremove the observer, i can login again.
Check the two attached screenshots.
Kindly help me with this issue.
Thank you
I have created an observer. For login forms at admin and front end (and may be some other forms), the form fields for user name and password are in array format like below:
<input type="text" id="username" name="login[username]" value="" class="required-entry input-text">
<input type="password" id="login" name="login[password]" class="required-entry input-text" value="">
TO fix this issue, i have modified the code in observer as below:
public function sanitizeParams($observer)
{
if(!Mage::app()->getStore()->isAdmin())
{
$post = Mage::app()->getRequest()->getParams();
foreach($post as $pkey => $pvalue)
{
if(is_array($post[$pkey]))
{
foreach($post[$pkey] as $key => $value)
{
$post[$pkey][$key] = filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS);
}
}
else
{
$post[$pkey] = filter_var($pvalue, FILTER_SANITIZE_SPECIAL_CHARS);
}
}
$_POST = $post;
}
}
And it fixed my problem, and is working fine now.
Thanks.

Getting the target element name in data- attribute of the parent element through JQuery

I have two elements a source and target (sort of linked select). I wish to get the target element's name in the source element's data- attribute. Is it possible? The following code does not work.
<label>States</label>
<select class='sparent' data-select-target='child'>
<option value=''>Select State</option>
<option value='AZ'>AZ</option>
<option value='PA'>PA</option>
<option value='TX'>TX</option>
</select>
</label>
<div name='child' class='schild'>value</div>
JQuery Code :
$(".sparent").change(function(){
var id = $(this).val();
var target = $(this).data("select-target");
$.get("includes/chainedselect.php", {id:id}, function(data){
$(target).html(data);
});
});
However, if I replace $(target).html(data); with $("child").html(data); it works.
Can anyone help me figure this out? Thanks for your time.
Rename your data attribute data-select-target='child' to this:
data-select-target='schild'
And $(target).html(data); to this:
$('.' + target).html(data);
and try again.
try this,
$('div[name="'+target+'"]').html(data);
you are providing 'child' in the selector, but you missed to provide whether it is an 'id', 'class' or 'tag'.

codeigniter input fields with same name

sorry if its a stupid question but i need a bit of a help.
I made a signup form, and i would like to people select 2 phone numbers.
If i select hungarian a hungarian phone type input slides down, if he selects ukraine than an ukraine phone input type slides down.
here is the html
<input type='text' name='telefon' id='magyar' class='input_title' value='<?php echo set_value('telefon'); ?>' />
<input type='text' name='telefon' id='ukran' class='input_title' value='<?php echo set_value('telefon'); ?>' />
<div class='hiba'><?php echo form_error('telefon'); ?></div>
magyar = hingarian
ukran = ukraine
telefon = phone
telo_tipus = phoe type
my problem is the validation, if i select hungarian and fill it out it says i need to add a phone number but if i select ukraine its ok
here is the validation
$this->form_validation->set_rules('telefon', 'Telefon', 'required|callback_hasznalt_telefon');
could please someone point out what im missing with the validation?
i tried with na=telefon[] but in that case the validation wont work
the callback only validates if the phone is taken thats ok but here it is
function hasznalt_telefon()
{
$telefon = trim($this->input->post('telefon'));
$query = $this->db->query(' SELECT telefon FROM felhasznalok WHERE telefon = "'.$telefon.'" ');
if($query->num_rows() > 0)
{
$this->form_validation->set_message('hasznalt_telefon', 'Ez a telefonszám már használatban van ');
return false;
}
else
{
return true;
}
}
Your codeigniter code is fine, but your html/javascript is what needs to change.
Instead of having two input fields with the same name (which the php script will only read the last one, btw), you should make a select field that changes what input type slides down from the 'telefon' field.
I'm not sure what javascript you are using, but in jquery you can have the the input field event bound on selection from the select field.
If you need more specific guidance for this, let me know and I'll edit my answer.
<select id="telefon_type">
<option>Telefon Type</option>
<option value="magyar">Magyar</option>
<option value="ukran">Ukran</option>
</select>
<input type="text" name="telefon" id="telefon" disabled />
$("#telefon_type").bind("change", function() {
$("#telefon").removeAttr("disabled");
if ($(this).val() == "magyar") {
$("#telefon").bind("focus",function() {
// onfocus event for #telefon for magyar
});
} else if ($(this).val() == "ukran") {
$("#telefon").bind("focus",function() {
// onfocus event for #telefon for ukran
});
} else {
$("#telefon").attr("disabled","disabled");
$("#telefon").val('');
}
});
Please note: I have not tested this code. The general idea behind it is that the filter you are running for the telefon field changes based on your selection of the select field.
Your question has beeen already answered. Phil Sturgeon is working on that issue, so you can try to use the development branch of CI from github.
If you want only ONE telephon number (depends on nationality) I think it would be simplier when you use only ONE input field and write its value to database (or do anything what you want). Or is there any reason to use two input fields?

Resources