joomla component save creates a new instance instead of update - joomla

I am working on a Joomla 3.0 component built by notwebdesign.com.
In administrator, each time I try to save the data it creates a new instance of data instead of updating the data already loaded in form.

Simple fix. Find the respective form xml file and in this file find the id field as below. Then, just remove the default parameter. It should look like:
<field name="id"
type="text"
default="" // remove this
readonly="true"
class="readonly"
label="JGLOBAL_FIELD_ID_LABEL"
description="JGLOBAL_FIELD_ID_DESC"/>
The id (generally speaking) should not have a default value, so find any occurrences of "id" in your fields parameters. Hope it helps

Related

Laravel populate form with cloned model data

I'm implementing a "Clone" button in my application, which should allow to perform the following:
create a copy of the chosen model;
redirect to the create view, whose form field should be populated with the cloned model's data;
allow the user edit some fields;
save the new model.
So far, my ModelController#clone method is:
$newModel = $existingModel->replicate();
$newModel->title = "Copy of ".$existingModel->title;
$newModel->created_at = now() // not sure if necessary, or if it'll be changed once the model is stored in the database
return redirect(route('models.create')); // I know this doesn't do what I need
As it is, obviously, nothing gets passed to the create view, but I can't find any clue on how to do that.
I have tried adding ->withInput(compact($newModel)) to the redirect() call, but I don't see the field being populated.
In the models.create view, I have set up the form field to use the old(...) data, if available.
This answer is almost what I need, but it would imply changing every field to check if there is some sort of input other than the old session data, like this:
<input [other attributes omitted] value="{{ $newModel['title'] ?? old('title') }}">
Is it the right way to do so, or is there a quicker/more standardized way of proceeding?
you could overriding the session old input data by:
Session::put('_old_input', $newModel);
and then just render the old() in form inputs

spring form input fields type attribute

I am converting some plain HTML to using spring form tags.Although it looks like
spring form input does not have the attribute type. I was able to successfully
pass a hidden variable as follows:
<form:input type="hidden" name="displayId" id="displayIdentifier" path="displayIdentifier" value="${value1}"/>
Earlier the plain HTML was as follows:
<input type="hidden" name="displayId" id="displayIdentifier" value="${value1}"/>
I looked online and saw that the for:input does not have the type attribute, yet it seems to be working correctly.
The input tag is declared with
<dynamic-attributes>true</dynamic-attributes>
That allows passing dynamic attributes, not explicitely declared in the tag. The tag simply stores their name and value and writes them as is on the generated HTML input. That allows adding a type, or a data attribute, or any attribute you want to the tag.
See http://docs.oracle.com/javaee/6/api/javax/servlet/jsp/tagext/DynamicAttributes.html for more information.

In struts-config.xml, an action has an "attribute" attribute in it. What's it do?

In our web app's struts-config.xml file, there are a bunch of <action>s defined, and they have both a name and an attribute attribute on most of them, with the form name in both. For example:
<action
attribute="LoginForm" <-- this line
name="LoginForm"
path="/welcome"
type="com.foo.presentation.action.LandingActionPre">
<forward name="SUCCESS" path="landing.welcome" />
<forward name="ALREADY_LOGGED_IN" path="/landing.do?m=getLandingPage" redirect="true"/>
</action>
What does the attribute attribute do? Or is it not used and is present here by mistake?
This app has been around for ~10 years, and has seen over 40 programmers touch the code base during that time. So it's possible that one added it to a few actions and every one else copied and pasted it throughout the rest of the app not knowing any better.
According to the Struts 1 doc type definition, it is used as a sort of alias for the ActionForm.
If it's the same as name, it does nothing. But if name is specified and attribute is specified and different from name, then the form can be accessed using the value of either name or attribute.
Relevant section:
<!-- The "action" element describes an ActionMapping object that is to be used
to process a request for a specific module-relative URI. The following
attributes are defined:
attribute Name of the request-scope or session-scope attribute that
is used to access our ActionForm bean, if it is other than
the bean's specified "name". Optional if "name" is specified,
else not valid.

Freemarker Checkboxes input in Spring form

I have an HTML form bound to a Spring model to take in user data and add it to a database. This works fine. I have used Spring Freemarker macros for the fields to take input and validate before sending, e.g.
<#spring.formInput path="myForm.username"/>
<#spring.showErrors ", "/>
This also works fine for text input. What is causing me problems is rendering multiple checkboxes with the Spring macro. My original HTML was:
<input name="roleList" type="checkbox" value="1"/>Adminstrator
<input name="roleList" type="checkbox" value="2"/>Developer
<input name="roleList" type="checkbox" value="3"/>Customer
I created a Java Map<String, String> of this information with the keys as "1", "2", "3" in my controller method and added it to the model, then replaced the HTML with this macro in my ftl template:
<#spring.formCheckboxes path="quickForm.roleList" options="${roleMap}" separator="<br>"/>
But I get an error
Expecting a string, date or number here, Expression roleMap is instead a freemarker.template.SimpleHash
Why would it give that message if it requires a Map? (as in the Spring Docs for FreeMarker macros) Can anyone explain how I should be providing the checkbox data?
Finally worked this out, so for anyone who's interested: it wasn't as straightforward as just creating a HashMap of values and adding them with model.addAttribute("roleMap", myHash) - I had to create a service class to do this instead: it retrieved my list of roles from a database table and then converted them into a HashMap<String, String>. I then called this in my controller method, added it to my model (called "roleMap" here) and used it within my FreeMarker template without the usual formatting, like this:
<#spring.formCheckboxes path="quickForm.roleList" options=roleMap separator="<br>"/>
Having the data converted in a service method was key for Spring to use it as checkbox options.

Joomla component "attachments" allow html in input

this question might be a bit special. I am using this Joomla 2.5 extensions to give authors the abilty to add Attachments to articles: Joomla Attachments
The extension renders an input field called "description" in a backend form to insert an file description for the provided file. Unfortunately it´s not taking HTML tags which I need. By saving the form it seems a strip_tags() or preg_replace() or something similar cleans the input. I combed through the code of the attachments extension but couldn´t find a place where the input is cleaned or saved.
To hopefully stay in the Question + Answer rule of Stackoverflow:
Is there a class which extensions inherit from the Joomla Core to save form data to a DB-table ( which also could be responsible to clean and validate user input )?
thanks for any idea,
tony
You should see how the field is defined first:
1. Form definition
look into the
administrator/component/yourcomponent/models/forms/somename.xml
there you could find a form definition, if so it will also specify the field type: depending on the type there are several available filters; for example the default textarea will strip html, and you need to set
filter="raw"
in order to enable it. see http://docs.joomla.org/Standard_form_field_and_parameter_types for a list of fields, click and you can find the available format options.
2. model
If the model inherits from JModelAdmin or JModelForm or other JModel* it will automatically handle binding of the forms' data to the database, look for the Save function which should receive the form $data.
3. more
There are at least another dozen possibilities. If the above didn't help, try finding the form: possibly you could find it just by looking at the markup. Once you have the form, check the following fields:
option
task
view
This should help you find the php code that is invoked based on the form:
if view is set, maybe in ./views/someview/view.html.php you could find the saving logic.
if task is set, look for a function with the same name in ./controller.php
if task contains a ".", look for the controller in the ./controllers/ folder.
if option is not the name of your component, your component is sending the data to another component for saving, and most likely set a return-url

Resources