Forums

UPDATE Jos_content TABLE USING CUSTOM CODE

solfri 28 Feb, 2012
Hi people,
im Piter and i need a help for my work.

I have created a form with:

- hide label (id of article)
- hide label (id of categories)
- upload image
- textarea (for description of the image)- [textarea_2]

In the events i have

- upload image
- image resize
- custom code
- db save assigned to the Jos_content table

In the custom code i have put inside

<?php
jimport( 'joomla.filesystem.file' );
$small_image = $form->data['introtext']; 
$ext = JFile::getExt($small_image);
$name = JFile::stripExt($small_image);
$name = 'big_'.$name.'_big.'.$ext;
$uri = JFactory::getURI();
$img_tag = "<table border='0' cellpadding='1' cellspacing='1' style='width: 500px;'><tbody><tr><td><a class='jcepopup' href='{$uri->root()}images/stories/{$name}'><img width='200px'; height='auto'  src='{$uri->root()}images/stories/{$name}' style='float:left;' ; hspace='5px'/></a>";

// add the image to the introtext
$form->data['introtext'] = $img_tag.$form->data['textarea_2'];
?>
<?php
$form->data['introtext'] = "{$form->data['introtext']}</td></tr></tbody></table>"; 
?>


EVERYTHING WORK WHEN I SUBMIT AND THE ARTICLE IS CHANGED WHIT THE CONTENT I HAVE SUBMITTED

MY QUESTION IS

If i want only to add to article something and not replace every time the content
what i have to do?

I HAVE TRY WITH ADD THIS IN THE CUSTOM CODE:

<?php
jimport( 'joomla.filesystem.file' );
$small_image = $form->data['introtext']; 
$ext = JFile::getExt($small_image);
$name = JFile::stripExt($small_image);
$name = 'big_'.$name.'_big.'.$ext;
$uri = JFactory::getURI();
$img_tag = "<table border='0' cellpadding='1' cellspacing='1' style='width: 500px;'><tbody><tr><td><a class='jcepopup' href='{$uri->root()}images/stories/{$name}'><img width='200px'; height='auto'  src='{$uri->root()}images/stories/{$name}' style='float:left;' ; hspace='5px'/></a>";



// add the image to the introtext

$form->data['introtext'] = $img_tag.$form->data['textarea_2'];
?>
<?php
$form->data['introtext'] = "{$form->data['introtext']}</td></tr></tbody></table>"; 
$query = "
  UPDATE `#__content` 
    SET `fulltext` = '{$img_tag}' 
    WHERE `id` = {290}; 
";
$db->setQuery($query);
$db->query();
?>


BUT DON'T WORK - IN THE ARTICLE I CAN SEE ONLY THE FILE NAME OF THE IMAGE.

PLEASE I NEED HELP🙂
Max_admin 28 Feb, 2012
Hi Piter,

If you want to update the article "content" then you will need to get a copy of it before overwriting it with an "UPDATE" statement, you can load it using a "SELECT" statement or using the "DB Record loader" action, then you should process it using some PHP code then "UPDATE".

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
solfri 28 Feb, 2012
Please Max
can you explain me better the way for do this?
The code i have posted before is correct?
I have to make a copy of article?
in the db loader wath i have to write?
The db loader is onload on in onsubmit?
im very confused but i hope you can help me.
GreyHead 29 Feb, 2012
Hi Piter,

As Max and I hae both said, you need to ge the existing article content, edit it to add the new content; then re-save it again using the same article ID.

You need to make sure that you have the article id available when the article is re-saved so that the article is updated.

You may need to get help from someone with some more Joomla! and MySQL experience.

Bob
solfri 29 Feb, 2012
Tanks Bob for your reply

i try to explain better my form

the label are

- hide label (id of article) (value=id)
- hide label (id of categories) (value=catid)
- upload image (VALUE= introtext)
- textarea (for description of the image)- [textarea_2]
- submit

In On load event
[attachment=2]onload.png[/attachment]
in db record loader
[attachment=1]dbrecordloader.png[/attachment]
In On submit
[attachment=0]onsubmit.png[/attachment]

In custom Code before Db Save this is the code:
<?php
jimport( 'joomla.filesystem.file' );
$small_image = $form->data['introtext']; 
$ext = JFile::getExt($small_image);
$name = JFile::stripExt($small_image);
$name = 'big_'.$name.'_big.'.$ext;
$uri = JFactory::getURI();
$img_tag = "<table border='0' cellpadding='1' cellspacing='1' style='width: 750px;'><tbody><tr><td><img width='450px'; height='auto'  src='{$uri->root()}images/stories/{$name}' style='float:left;' ; hspace='5px'/>";


// add the image to the introtext
$form->data['introtext'] = $img_tag.$form->data['textarea_2'];
?>
<?php
$form->data['introtext'] = "{$form->data['introtext']}</td></tr></tbody></table>"; 
?>
<?php 
$form->data['title'] = "{$form->data['title']} SOME TEXT"; 
?>
<?php 
$form->data['metadesc'] = "Some text {$form->data['title']}some text"; 
?>
<?php
$form->data['introtext'] = nl2br($form->data['introtext']);
?>

In the other Custom Code this is the code:
<?php 
$introtext=$_POST['introtext']
$textarea_2=$_POST['textarea_2']
$id=$_POST['id']
$query = "
  UPDATE `jos_content` 
    SET `introtext` = 'introtext+{$textarea_2}' 
    WHERE `id` = {$form->data['id']};  
";
$db->setQuery($query);
$db->query();
?>

In the Db save this is the setup:
-Enabled:yes
-Table: jos_content
-Model id: chronoform_data
-Save under Model Id: No
Testing the form this is the debugger:
Data Array: 
Array
(
    [catid] => 33
    [id] => 290
    [title] => TEST TITLE SOME TEXT
    [introtext] => 
TEST DESCRIPTION

    [textarea_2] => TEST DESCRIPTION
    [input_submit_12] => Submit
    [42435a4d57db43d61b6cc3e1f79df33d] => 1
    [option] => com_chronoforms
    [chronoform] => PRIMAFASE-Copy
    [event] => submit
    [Itemid] => 
    [_PLUGINS_] => 20120229121033_round.png,/some-url/images/stories/20120229121033_round.png,17620,http://some-url/components/com_chronoforms/uploads/PRIMAFASE-Copy/20120229121033_round.png
    [metadesc] => Some text TEST TITLE SOME TEXTsome text
    [chronoform_data] => Array
        (
            [cf_modified] => 2012-02-29 12:10:33
            [catid] => 33
            [id] => 290
            [title] => TEST TITLE SOME TEXT
            [introtext] => 
TEST DESCRIPTION

            [textarea_2] => TEST DESCRIPTION
            [input_submit_12] => Submit
            [42435a4d57db43d61b6cc3e1f79df33d] => 1
            [option] => com_chronoforms
            [chronoform] => PRIMAFASE-Copy
            [event] => submit
            [Itemid] => 
            [_PLUGINS_] => 20120229121033_round.png,/some-url/images/stories/20120229121033_round.png,17620,http://some-url/com_chronoforms/uploads/PRIMAFASE-Copy/20120229121033_round.png
            [metadesc] => Some text TEST TITLE SOME TEXTsome text
        )

    [chronoform_data_id] => 290
Debug Data
Upload routine started for file upload by : introtext
/some-url/images/stories/20120229121033_round.png has been uploaded OK.


THE ARTICLE IS MODIFIED BUT I NEED ONLY TO ADD TO ARTICLE SOMETHING NOT REPLACE IF I RESUBMIT.

PLEASE I FEEL CRAZY FOR THIS
GreyHead 29 Feb, 2012
Hi solfri,

Please see my previous post here.

You need to either (a) think carefully about what you are trying to do here. It is not difficult but you have to be precise at each step or (b) get some help.

I'm sorry but there just isn't time in the day to answer every long post especially when the problem isn't mainly about ChronoForms.

Bob
This topic is locked and no more replies can be posted.