Save form data as json in a single column in database Topic is solved

For Joomla! 4.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
neojw1505
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 142
Joined: Wed Aug 11, 2021 12:44 pm

Save form data as json in a single column in database

Post by neojw1505 » Mon Jan 17, 2022 1:29 am

Hi I would like to know how can I save a form data into a single column called 'params' in my database as json?
I have a 'modules' tab in my form and I would only like to save fields from this tab as a json object into the database column 'params'
Last edited by toivo on Mon Jan 17, 2022 3:51 am, edited 1 time in total.
Reason: mod note: moved from 4.x General Questions

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 14580
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Save form data as json in a single column in database

Post by toivo » Mon Jan 17, 2022 6:42 am

Your next topic was about accessing JSON data. Does that mean you managed to store the JSON data into a column in the database?
Toivo Talikka, Global Moderator

neojw1505
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 142
Joined: Wed Aug 11, 2021 12:44 pm

Re: Save form data as json in a single column in database

Post by neojw1505 » Tue Jan 18, 2022 1:17 am

toivo wrote:
Mon Jan 17, 2022 6:42 am
Your next topic was about accessing JSON data. Does that mean you managed to store the JSON data into a column in the database?
Yes, I just followed this https://docs.joomla.org/J3.x:Developing ... figuration
The part where it mentioned about overloading the bind method to convert the array of parameters to JSON string.

Code: Select all

public function bind($array, $ignore = '')
	{
		if (isset($array['params']) && is_array($array['params']))
		{
			// Convert the params field to a string.
			$parameter = new JRegistry;
			$parameter->loadArray($array['params']);
			$array['params'] = (string)$parameter;
		}
		return parent::bind($array, $ignore);
	}
I did not understand what is the code doing, all I know is that by copying this bind method and pasting into my table folder entry point file, it stores into the column called 'params' a JSON string


Post Reply

Return to “Joomla! 4.x Coding”