Forums

Store several form values in one db field

maxdesign 11 Feb, 2013
Firstly, I have been using Chronoforms for a few years now and still feel I have hardly scratched the surface. Epic, and endless in possibilities, its tools like this that make Joomla the versatile platform that it is.

So here is my current project = I need to create a form that can add K2 items/articles into Joomla from the front-end without loggin in. Many reasons why thats not a good idea, not the issue at hand 😀

I have got it all to work with astounding simplicity, all apart from one field in the table, called the Extra Fields; stored in the table as:
extra_fields
with a value of

[{"id":"1","value":"LOCATION"},
{"id":"2","value":"TELEPHONE"},
{"id":"3","value":"EMAIL"},
{"id":"4","value":"TYPE"},
{"id":"5","value":"SKILLS"}]


How can I possibly fill in this single database field keeping the formatting, yet replacing the CAPS text with answered form fields?
GreyHead 12 Feb, 2013
Hi maxdesign,

It looks as though this is a JSON encoded array of arrays. If so then this (or something similar) should work in a Custom Code action:
<?php
$extra_fields = array (
  array('id' => 1, 'value' => '{$form->data['location']}',
  array('id' => 2, 'value' => '{$form->data['telephone']}',
  array('id' => 3, 'value' => '{$form->data['email']}',
  array('id' => 4, 'value' => '{$form->data['type']}',
  array('id' => 5, 'value' => '{$form->data['skills']}',
);
$form->data['extra_fields'] = json_encode($extra_fields);
?>

Bob
maxdesign 12 Feb, 2013
Will give that a try! In the meantime I have had a play with Heredoc? and put this together:

[code]
<?php
$extra = $form->data['extra1'];
$form->data['extra_fields'] = <<<EX1
[{"id":"1","value":"$extra"},
EX1;
?>
[/code]

Just my random figuring out using your tutorials and some googling! Need to learn PHP 🙄
This topic is locked and no more replies can be posted.