Set the value of a field ?

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
duddy67
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 229
Joined: Sun Jul 12, 2009 12:04 pm

Set the value of a field ?

Post by duddy67 » Fri Mar 11, 2011 10:05 pm

Hi,

I'm desperatly trying to set the value of a backend component field but I can't make it.
I tried with the setValue function from the JForm class:

Code: Select all

$this->form->setValue('title', 'some value'); 
in the view.html.php file and in the default.php file but it doesn'nt work.
I checked my form file and all seems ok, so I don't understand what's wrong.

Is any specific way to use the setValue function ?


Thanks for your help.

duddy67
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 229
Joined: Sun Jul 12, 2009 12:04 pm

Re: Set the value of a field ?

Post by duddy67 » Sat Mar 12, 2011 5:04 pm

Ok I've got it.

First the API documentation (http://docs.joomla.org/API16:JForm/setValue) is slightly wrong.
It says that the prototype of the function is :

Code: Select all

public function setValue($field, $value, $group = '_default')
BUT in the joomla/form/form.php file the prototype is:

Code: Select all

public function setValue($name, $group = null, $value = null)
The arguments order is different.
Next, I therefore modified my code as follow:

Code: Select all

$this->form->setValue('title', 'details', 'some value'); 

'details' is the name of the fieldset wich contains the title field, but setValue doesn't work either.
So, either I don't understand what $group means or there's a bug somewhere in the setValue function.

Finally I modified my code again :

Code: Select all

$this->form->setValue('title', null, 'some value'); 
and that's works ! :) (at last).

I don't know if the setValue gonna be modified in the next Joomla's updates but
it worth to keep an eye on it.

ShopperJeanny
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Wed Jul 07, 2010 1:08 pm

Re: Set the value of a field ?

Post by ShopperJeanny » Wed Mar 16, 2011 10:52 am

Hello,

so maybe you can help me with my issue?
http://forum.joomla.org/viewtopic.php?f=625&t=602721

I think the problem is similar?

duddy67
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 229
Joined: Sun Jul 12, 2009 12:04 pm

Re: Set the value of a field ?

Post by duddy67 » Wed Mar 16, 2011 12:25 pm

I think the problem is similar?
Nope it doesn't.
First did you learned about the JForm class and the way to create a form
in a component ?
The form creation is totally different between Joomla1.5 and Joomla1.6

Once you'll be comfortable with that, you could get your calendar with some code looking like that:

Code: Select all

<field name="created" type="calendar"
		label="JGLOBAL_FIELD_CREATED_LABEL" description="JGLOBAL_FIELD_CREATED_DESC"
		class="inputbox" size="22" format="%Y-%m-%d %H:%M:%S"
		filter="user_utc" />
Hope it helps

ShopperJeanny
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Wed Jul 07, 2010 1:08 pm

Re: Set the value of a field ?

Post by ShopperJeanny » Thu Mar 17, 2011 11:22 am


mbaa2
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Sat Mar 12, 2011 10:36 pm

Re: Set the value of a field ?

Post by mbaa2 » Mon Apr 11, 2011 1:38 am

duddy67 wrote:Ok I've got it.
Hey duddy67... THANKS!

I spent hours trying to get the setvalue to work and your post saved me. Unfortunately, I still can't get the bind() function to work. I don't suppose that you have hand any related difficulty there?

Thanks!

User avatar
MrRoyce
Joomla! Ace
Joomla! Ace
Posts: 1176
Joined: Mon Oct 09, 2006 9:52 pm
Location: Tampuh Floriduh - The jewels of America's wang.
Contact:

Re: Set the value of a field ?

Post by MrRoyce » Mon Nov 07, 2011 9:03 pm

I struggled with trying to get the setValue to work for the form fields but it works great just using:

$this->form->bind($associated_array)

I execute that before the $this->form->getFieldset() and it pre-filled the values.

User avatar
foto50
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Mon May 14, 2007 9:47 am

Re: Set the value of a field ?

Post by foto50 » Mon Apr 16, 2018 4:51 pm

wow ... this post is 7 years old (here now on J3.8.6) and still helped me saving time :D

Thanks a lot!


Locked

Return to “Joomla! 2.5 Coding”