Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Populate form 30 Sep 2016 14:41 #14609

  • albert
  • albert's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 70
  • Thank you received: 2
Hi,I would like to make a modifications on a model, insert data a recover the updated model for a form

i have a view that it is the item one, where i can insert new entries, so the view.html.php i like this :
protected function displayEditprofile($tpl = null)
{
// Initialiase variables.
$this->model = $model = $this->getModel();
$this->state = $state = $this->get('State');
$this->params = $state->get('params');
$state->set('context', 'nameofcomponent.editprofile');
$this->item = $item = $this->get('Item');
$this->form = $form = $this->get('Form');
....

here i do some inserts in the table and i get the value of the id

then i would like to do something like
$model->setState( 'id', $recovered_id);
$this->model = $model = $this->getModel();

and obtain the form as it would be edited not just blank
but i am doing something wrong, because all time i get blank form,
i do
$item = $model->getItem($recovered_id);
print_r($item);

I obtain the correct data, but the form still is empty
can someone give me a tip?

Albert

Please Log in or Create an account to join the conversation.

Populate form 01 Oct 2016 06:04 #14611

Hi Albert.

I don't think I full understand what you want.
You say you would like to make modfications to a model, but you then talk about the view?
My question is WHEN you want to insert data, and WHERE.
The code you post, will insert data in "the table" (what table?) everytime you open a profile item. Is that what you want?

I assume you only want to do that under certain circumstances? What are those?
Also, as the name of the function indicates, the function is for displaying, not for inserting data/.

Can you please discribe the functionality you want, without referring to any code/technical stuff like table etc? We can give you better pointers then.
This is because I think you are on the wrong track here.

Please Log in or Create an account to join the conversation.

Populate form 04 Oct 2016 08:26 #14619

  • albert
  • albert's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 70
  • Thank you received: 2
I did a component for a kind of profile. So i want that everyuser have a profile page, so he can edit an update it.
I am editing the page-frontend-item.
So the first time, if the entry is empty, i take data from another database, i fulfill the entry and i re-edit the form.

so initially I got an empty form, in the view.html.php i modify the code to get initial data is there is no entry, and then i want to receive this data.
i do via $item = $model->getItem($recovered_id);
but i still continue displaying emty form, somehow i do not know how to call a form fulfilled with a default values (corresponding to a concrete id)

Please Log in or Create an account to join the conversation.

Populate form 05 Oct 2016 07:50 #14620

Ok, you can solve it like this:

You have already the view and stuff and are able to get default data.
What you can do next is to fork the form template (profile_form.php in your case I guess)
- Copy the profile_form.php into the tmpl folder of your fork folder.
- In the you will find <fieldset> stuff.

Manipulate like so:"
<fieldset class="fieldsform form-horizontal">

	<?php
//check if this is a new item,
if ($this->model->getId() == 0) {
    //get default data
     $fieldSet['jform_field1']->jdomOptions = array(
			'dataValue' => $default_value1
		);
}
	echo $this->renderFieldset($fieldSet);
	?>
</fieldset>

In short: in the view the data is already populated, you need to save and get the default data in the form.
There might be a better way, but this will work :)

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.058 seconds

WOW.. WOW... WOW... This is awesome... in less than 3 hours of work I have my application done... this is simply the best tool I ever tried to generate Joomla Components... Thank you very much for this tool and your answer.. it helped me a lot... My friends here in Brazil are going nuts with this...
Griiettner (Forum)

Get Started