Forums

Adding image to article submit form

fribse 22 Jan, 2012
Hi All

I've been asked to add the possibility to add images to my article submit form.
I've added the form element, the path for the action is set to /images/log (will it include JOOMLA_PATH before that automagically?)

How do I modify the article so that it will show the image? I had an idea that if I could add an <img src="image.jpg" alt="Image" height="200" width="200" /> in a custom code, but I'm not really sure how to do that properly
mkusens 16 May, 2012
I too would like to accomplish this task. Has anyone been able to do it successfully? If so, please let us know.
GreyHead 16 May, 2012
Hi both,

There's another thread here about doing this using the image resizer action but the code for an uploaded image is simpler.

In a custom code action add this code:
<?php
$uri = JFactory::getURI();
$img_tag = "<img src='{$uri->root()}image/log/{$name}' alt='image' style='height:200px; width:200px;' />";
// add the image to the introtext
$form->data['introtext'] = "some text . . . {$img_tag} . . . more text";
?>

Bob
massimiliano1212 04 Apr, 2013
I've tried you code, i've put it in a "Custom Code" module with the mode "controller" but I have made this modifies:
<?php
$uri = JFactory::getURI();
$img_tag = "<img src='{$uri->root()}images/nuovi-annunci/{$name}' alt='image' style='height:200px; width:200px;' />";
?>


because my form upload images in this folder : images/nuovi-annunci/

It doesn't work.. can you help me?
GreyHead 04 Apr, 2013
Hi massimiliano1212,

At a guess you may not have set $name to the name of the uploaded image. It will be something like $form->data['input_name']

Bob
massimiliano1212 04 Apr, 2013
I've tried it put it seems not to work..Can you help me? I can pay for your work. Thank you very much.
here what i have written:

<?php
$uri = JFactory::getURI();
$img_tag = "<img src='{$uri->root()}images/nuovi-annunci/{$form->data['input_name']}' alt='image' style='height:200px; width:200px;' />";
?>
GreyHead 04 Apr, 2013
Hi massimiliano1212,

Yes, but you need to replace 'input_name' with the name of the file upload input in your form :-(

Bob
massimiliano1212 04 Apr, 2013
yes, yes.. i have tried it..i wrote:

<?php
$uri = JFactory::getURI();
$img_tag = "<img src='{$uri->root()}images/nuovi-annunci/{$form->data['input_file_14']}' alt='image' style='height:200px; width:200px;' />";
?>

where "input_file_14" is the field name of the file that the client upload.
GreyHead 05 Apr, 2013
Hi massimiliano1212,

Please post a link to the form so I can take a quick look.

Bob
GreyHead 06 Apr, 2013
Hi massimiliano1212,

Sorry, my mistake, I can’t see anything when the form submits :-( Please take a Form Backup using the icon in the Forms Manager and post it here (as a zipped file) or PM or email it to me and I'll take a closer look.

Bob
massimiliano1212 10 Apr, 2013
Hi GreyHead, have you seen my mail?
Do you need something else?
GreyHead 10 Apr, 2013
Hi massimiliano1212,

I took a look, the problem is that you are defining the variable but not doing anything with it. I added echo $img_url; to the code and that now displays the image.

You can also probably use just one Upload Files action rather than having separate ones.

Bob
massimiliano1212 11 Apr, 2013
I've tried it Greyhead but it seems it isn't work..I need that the image is uploaded in the body of the article but it doesn't do that..Do you have tried? It was working?, the image was uploaded in the body of the article that you submitted?

thank you
GreyHead 11 Apr, 2013
Hi massimiliano1212,

Please see this post earlier in this thread. The Custom Code action needs to be before the Submit Article action.

Bob
massimiliano1212 11 Apr, 2013
Hi GreyHead,
I have moved the custom Code action before the Submit Article action but it still doesn't work.
what it can be?
thank you
GreyHead 18 Apr, 2013
Hi Massimiliano,

Please see this post earlier in the thread. As far as I can see you don't have the intro-text part which adds the image to the article text.

Bob
leon101noel 09 May, 2013
Hi GreyHead,

I am desperately trying to follow this but really struggling to get it to work. Its the last thing I have to achieve on a website im building and just simply cant get it to work.

All I need is a user to be able to select a title, content of thier article and then for an attached image to be placed at the top of the article body.

Got a form doing this (except for the image) and submtting the article, tried following the code but just doesnt want to work 😟 😟 it is also not uploading the image to the path i specified.

Been trying for hours before posting thinking I might master it and get it sorted to no avail.

I have made a backup of the form and can be got here - http://www.lcwebdesign.co.uk/form.zip

Could you or anybody else be able to take a look and see what probably is a tiny thing im getting wrong then once got it working I can buy the premium version as I think this is the only extension out there to do this job properly!
GreyHead 10 May, 2013
Hi leon101noel,

You have the Custom Code action before the Upload Files action so there is no file info to use in the link building.

Please try dragging the Custom Code down after the upload files action.

You've also used $name in the link without defining it. That probably needs to be $form->data['input_file_4'] to get the name of the uploaded file.

Bob
leon101noel 10 May, 2013
Hi GreyHead,

Have moved the Custom Code down after the image upload and have set the code as below. But still no image😟

<?php
$uri = JFactory::getURI();
$img_tag = "<img src='{$uri->root()}images/{$form->data['input_file_4']}' alt='image' style='height:200px; width:200px;' />";
// add the image to the introtext
$form->data['introtext'] = "some text . . . {$img_tag} . . . more text";
?>

leon101noel 10 May, 2013
Have noticed one fatal flaw in my plan too lol, just made a simple form with the easy wizard, upload box and submit button, left all config to default and its not saving a file to components/com_choronoforms/uploads

Set the dir to 777 just to check still nothing, any ideas??
GreyHead 10 May, 2013
Hi leon101noel,

Please drag a Debugger action into the On Submit event, then submit the form and post the debug - including the 'dummy emails' results here.

Note: if you are using the Easy Wizard you can turn on Debug on the Others tab.

Bob
leon101noel 10 May, 2013
Data Array: 
Array
(
    [chronoform] => Content
    [event] => submit
    [Itemid] => 167
    [option] => com_chronoforms
    [view] => form
    [title] => Debugger on
    [content1] => Debugger on to show errors
    [input_file_4] => 
    [input_submit_3] => Submit
    [509f73fd5983f5ad4a71319e6e03a8a2] => 1
    [introtext] => 
    [created_by] => 42
    [created] => 2013-05-10 17:43:01
    [catid] => 8
    [sectionid] => 0
    [state] => 1
    [fulltext] => Debugger on to show errors
    [created_by_alias] => 
    [language] => *
    [alias] => debugger-on
    [id] => 
    [Article] => Array
        (
            [cf_uid] => 24d5ff621eb83d21620eda71fa10842b
            [cf_created] => 2013-05-10 17:43:01
            [cf_created_by] => 42
            [cf_ipaddress] => 90.214.246.250
            [cf_user_id] => 42
            [chronoform] => Content
            [event] => submit
            [Itemid] => 167
            [option] => com_chronoforms
            [view] => form
            [title] => Debugger on
            [content1] => Debugger on to show errors
            [input_file_4] => 
            [input_submit_3] => Submit
            [509f73fd5983f5ad4a71319e6e03a8a2] => 1
            [introtext] => 
            [created_by] => 42
            [created] => 2013-05-10 17:43:01
            [catid] => 8
            [sectionid] => 0
            [state] => 1
            [fulltext] => Debugger on to show errors
            [created_by_alias] => 
            [language] => *
            [alias] => debugger-on
            [id] => 273
        )

    [article_id] => 273
)
Validation Errors: 
Array
(
)
GreyHead 12 May, 2013
Hi leon101noel,

I don't see any trace of an Upload Files action in the Debug output.

Bob
leon101noel 12 May, 2013
Yeah thats what i thought!

I added a file, i saw Chrome uploading it in its status bar but then nothing. This is probably my problem. Any specific server requirements etc??
GreyHead 12 May, 2013
Hi leon101noel,

Just to check, there is an Upload Files action in your form On Submit event? What settings does it have?

Bob
leon101noel 12 May, 2013
Have got the file upload working now. But still not showing in the article😟

Array
(
    [chronoform] => Content
    [event] => submit
    [Itemid] => 167
    [option] => com_chronoforms
    [view] => form
    [title] => Here we go again
    [content1] => Yet again1
    [input_file_4] => 20130512173802_20130217_105952.jpg
    [input_submit_3] => Submit
    [7813f9254d25d9b8529738914b4e90dd] => 1
    [_PLUGINS_] => Array
        (
            [upload_files] => Array
                (
                    [input_file_4] => Array
                        (
                            [name] => 20130512173802_20130217_105952.jpg
                            [original_name] => 20130217_105952.jpg
                            [path] => images/20130512173802_20130217_105952.jpg
                            [size] => 1837129
                            [link] => images/20130512173802_20130217_105952.jpg
                        )

                )

        )

    [introtext] => 
    [created_by] => 42
    [created] => 2013-05-12 17:38:02
    [catid] => 8
    [sectionid] => 0
    [state] => 1
    [fulltext] => Yet again1
    [created_by_alias] => 
    [language] => *
    [alias] => here-we-go-again
    [id] => 
    [Article] => Array
        (
            [cf_uid] => aaa75c4a21549c6bcb1914f1754b5986
            [cf_created] => 2013-05-12 17:38:02
            [cf_created_by] => 42
            [cf_ipaddress] => 90.214.246.250
            [cf_user_id] => 42
            [chronoform] => Content
            [event] => submit
            [Itemid] => 167
            [option] => com_chronoforms
            [view] => form
            [title] => Here we go again
            [content1] => Yet again1
            [input_file_4] => 20130512173802_20130217_105952.jpg
            [input_submit_3] => Submit
            [7813f9254d25d9b8529738914b4e90dd] => 1
            [_PLUGINS_] => Array
                (
                    [upload_files] => Array
                        (
                            [input_file_4] => Array
                                (
                                    [name] => 20130512173802_20130217_105952.jpg
                                    [original_name] => 20130217_105952.jpg
                                    [path] => images/20130512173802_20130217_105952.jpg
                                    [size] => 1837129
                                    [link] => images/20130512173802_20130217_105952.jpg
                                )

                        )

                )

            [introtext] => 
            [created_by] => 42
            [created] => 2013-05-12 17:38:02
            [catid] => 8
            [sectionid] => 0
            [state] => 1
            [fulltext] => Yet again1
            [created_by_alias] => 
            [language] => *
            [alias] => here-we-go-again
            [id] => 277
        )

    [article_id] => 277
)
Validation Errors: 
Array
(
)
Debug Data
Upload routine started for file upload by : input_file_4
images/20130512173802_20130217_105952.jpg has been uploaded successfully.
GreyHead 13 May, 2013
Hi leon101noel,

Mostly this is just a question of being careful and checking through step by step.

The image input in your form is called text_input_4 - but in the Custom Code you have used attachment_5.

The custom code adds the image link to introtext but in the Submit Article action you have content1 for the Full Text field and the Intro Text field is empty.

So, as far as I can see the result you get is correct for the way you have set it up.

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