2

I'm using a frontend JForm to manipulate some data. The html form is correct, but when it is sent back to the model save function I don't receive all data.

This is the data that save receives through $data parameter:

Array
(
    [created] => XXXXXXXXXXXXXXXXX
    [updated] => XXXXXXXXXXXXXXXXX
    [wasteId] => X
    [price] => XXXX
    [pricenight] => XXX
    [pricefreeday] => XXXX
    [pricefreedaynight] => XXXX
    [tags] => 
)

But when I use

$formData = new JRegistry($this->input->get('jform', '', 'array'));

or when I got the data as the JControllerForm save method does

$formData = new JRegistry($this->input->post->get('jform', array(), 'array'));

I've got

Joomla\Registry\Registry Object
(
    [data:protected] => stdClass Object
        (
            [wasteId] => X
            [price] => XXXX
            [pricenight] => XXX
            [pricefreeday] => XXXX
            [pricefreedaynight] => XXXX
            [contractId] => Array
                (
                    [0] => XX
                    [1] => XX
                )

            [created] => XXXXXXXXXXXXXXXXX
            [updated] => XXXXXXXXXXXXXXXXX
            [id] => XX
        )
)

So fields id and contractId are missing in the $data parameter.

Any idea of what should I do to have contractId and id on the $data parameter of the model save function?

By the way, the model I'm using is derived from JModelAdmin and the controller is derived from JControllerForm. The controller has no overriden functions which may affect the way it collects data from the form.

EDIT

More clues: inspecting the JControllerForm::save more in detail I've seen that $data has the id component with the correct value but it gets overwritten with an empty value around line 637 because of this:

$recordId = $this->input->getInt($urlVar); // around line 634 of JControllerForm

sets $recordId to an empty value, in spite of $urlVar value is "id". Then later, around line 637 of JControllerForm $data["id"] is changed:

$data[$key] = $recordId

$key value is "id" and $recordId is empty.

Thanks.

2

You don't show any of your code, so I'm just going to walk through what I know of JControllerForm and JModelAdmin — which of course will be affected by any overrides in your subclass.

JControllerForm

The save() method in JControllerForm uses the following line to retrieve the JForm array.

$data  = $this->input->post->get('jform', array(), 'array');

Note the extra ->post segment vs. your JRegistry() test, that means it's only getting the data from the post data submitted. Your example uses the combined JInput as a source. It's unlikely, but if those fields are submitted as part of the form URL (i.e. in the get part of the submission) then they won't be found.

Without more details, e.g. form html, your controller & model code (esp. if you override save/bind etc) it's hard to say. If you can add more details I can probably expand on my answer.

  • Thanks for your answer. All data moves via post method, and the only overriden function overrided is the model's save, but because it's the parameter which is not filled correctly the code may be irrelevant. If I got the data from the post exactly as the controller does I've got the expected data. – Pep Lainez Oct 15 '14 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.