The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed May 09, 2012 6:51 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Sep 21, 2008 3:31 am
Posts: 214
Hi,
I am creating a component, everything's great. but I need "New Record" form to be filled with "Last Record's Data"
I could have done this the Hard way, but I want to play by joomla rules.
Any Ideas?

_________________
http://www.joomlux.com - Joomla! Extensions and Templates


Top
 Profile  
 
PostPosted: Wed May 09, 2012 7:27 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Sun Feb 25, 2007 10:07 pm
Posts: 58
Location: @nchamilton
there is two ways of creating a "new record".

Create a dummy object with all the defaults and an id of 0 (which is what I useally do)
Actually create a row in the table and return that id (which is what I think you are doing)

the reason I go with the first is that if you cancel you then have to delete the row.

When you add this item to the db (before or after the user edits it) then you need to get the row id (which is what your asking, so you can just select that one)

On my save I do:
Code:
        if ($category['id'] == 0)
        {
            $category['id'] = $db->insertid();
        }


the insertid will give you the id of that row.

***** assumption ****
the table has an id row that is auto incrementing

_________________
http://www.conquerjoomla.com<--- Click to Conquer Joomla!
https://twitter.com/#!/nchamilton <--- Follow me on twitter


Top
 Profile  
 
PostPosted: Thu May 10, 2012 5:32 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Sep 21, 2008 3:31 am
Posts: 214
I think its not what I meant to do,
I want "New Record Form" inputs have some default values.
which will be values from latest record in database table.

_________________
http://www.joomlux.com - Joomla! Extensions and Templates


Top
 Profile  
 
PostPosted: Thu May 10, 2012 6:44 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Sun Feb 25, 2007 10:07 pm
Posts: 58
Location: @nchamilton
MeeDNite wrote:
I think its not what I meant to do,
I want "New Record Form" inputs have some default values.
which will be values from latest record in database table.


The forms are useally a jform loaded from xml.

You have to bind data to this form, this useally comes from a record you have loaded.

Another way is to create an object with all the variable set with the defaults you want and bind this data with the form.

Is this more what your looking for ?

_________________
http://www.conquerjoomla.com<--- Click to Conquer Joomla!
https://twitter.com/#!/nchamilton <--- Follow me on twitter


Top
 Profile  
 
PostPosted: Thu May 10, 2012 9:59 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Sep 21, 2008 3:31 am
Posts: 214
Thnx :D Thats more like it.

_________________
http://www.joomlux.com - Joomla! Extensions and Templates


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 



Who is online

Users browsing this forum: No registered users and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group