<![CDATA[ Editing modResource from the Front End? - My Forums]]> https://forums.modx.com/thread/?thread=97788 <![CDATA[Editing modResource from the Front End?]]> https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end?page=2#dis-post-528804
Now, I'm trying to determine how to add a form to the front end of the site to allow users to add a new resource including the additional fields. I've toyed with formit2resource and it does just that. It will add a new resource, however how do I get it to create the pagetitle, alias, content, etc. and also my new extended fields which are in a different table?

I've considered a two part form. Using formit2resource to add the initial new resource and then formit retriever to get the ID of the new resource and continue on with something like formit2db on the second part of the form. The problem is retrieving the ID from the new resource doesn't really work as expected.

Anyone have experience with this? Any thoughts on where to look for more info?]]>
ctownsend23 Jul 23, 2015, 11:36 AM https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end?page=2#dis-post-528804
<![CDATA[Re: Editing modResource from the Front End?]]> https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528830
Extending mod resource seemed like a solid option to gain the extra fields and functionality I was hoping for. Also, by creating new resources I figured modx's native friendly urls could be used and I wouldn't have to hack that up for it to work.]]>
ctownsend23 Jul 23, 2015, 06:42 PM https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528830
<![CDATA[Re: Editing modResource from the Front End?]]> https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528828
It might be easier yet to use one or more File TVs if that would work for you. NP should handle those fine.]]>
BobRay Jul 23, 2015, 06:34 PM https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528828
<![CDATA[Re: Editing modResource from the Front End?]]> https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528826 No I've never worked with newspublisher. My concern is going to be in attaching files in a future update of my current project. I'm not adverse to using it as long as it has capabilities for future expansion. I'll look at it.]]> ctownsend23 Jul 23, 2015, 06:28 PM https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528826 <![CDATA[Re: Editing modResource from the Front End?]]> https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528824 BobRay Jul 23, 2015, 06:24 PM https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528824 <![CDATA[Re: Editing modResource from the Front End?]]> https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528815 I'm assuming additional extended fields are added as so?

 $ext_object = $modx->newObject($classname);
    $ext_object->set('resource_id', $id);// set the relation-field here
    $ext_object->set('yourField1', $hook->getValue('yourField1'));
$ext_object->set('yourField2', $hook->getValue('yourField2'));
$ext_object->set('yourField3', $hook->getValue('yourField3'));
$ext_object->set('yourField4', $hook->getValue('yourField4'));
    $ext_object->save();
]]>
ctownsend23 Jul 23, 2015, 03:31 PM https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528815
<![CDATA[Re: Editing modResource from the Front End?]]> https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528811 I'll give this a try. So it seems from my limited programming knowledge that the snippet saves the resource, retrieves the id and then does a second save?]]> ctownsend23 Jul 23, 2015, 02:09 PM https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528811 <![CDATA[Re: Editing modResource from the Front End?]]> https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528810
<?php

$doc = $modx->getObject('modResource', array('id' => $hook->getValue('resource_id')));

if (empty($doc)) {
    $doc = $modx->newObject('modResource');
    $doc->set('createdby', $modx->user->get('id'));
} else {
    $doc->set('editedby', $modx->user->get('id'));
}

$allFormFields = $hook->getValues();
foreach ($allFormFields as $field => $value) {

    if ($field !== 'spam' && $field !== 'resource_id') {
        $doc->set($field, $value);
    }
}

$doc->set('template', '1');
//set other doc-fields here

if ($doc->save()) {

    $id = $doc->get('id');
    // set fields of extented table here
    $classname = 'yourExtClass';

    $ext_object = $modx->newObject($classname);
    $ext_object->set('resource_id', $id);// set the relation-field here
    $ext_object->set('yourField', $hook->getValue('yourField'));
    $ext_object->save();

}

/*
foreach ($allFormFields as $field=>$value)
{
if ($tv = $modx->getObject('modTemplateVar', array ('name'=>$field)))
{
// handles checkboxes & multiple selects elements 
if (is_array($value)) {
$featureInsert = array();
while (list($featureValue, $featureItem) = each($value)) {
$featureInsert[count($featureInsert)] = $featureItem;
}
$value = implode('||',$featureInsert);
}   
$tv->setValue($doc->get('id'), $value);
$tv->save();
}
}
*/

return true;

]]>
Bruno17 Jul 23, 2015, 01:57 PM https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528810
<![CDATA[Re: Editing modResource from the Front End?]]> https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528809 I do not currently have a link to the formit2resource code. I actually just pulled it from here:

http://forums.modx.com/thread/69981/formit-formit2resource

I just need to add a couple of additional fields that are in a separate table. I'm not sure how to go about adding the pagetitle, content, etc. and then also adding the extended fields along with the ID from the newly created resource in order for it to link the two different tables.

Quote from: Bruno17 at Jul 23, 2015, 05:50 PM
you just need to extend formit2resource a bit, if you want to save everything at once

do you have a link to the formit2resource - code, which you are using currently?

maybe the hook-snippet could also be modified to use runProcessor('resource/create') instaed of xpdo directly

]]>
ctownsend23 Jul 23, 2015, 01:35 PM https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528809
<![CDATA[Re: Editing modResource from the Front End?]]> https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528807
do you have a link to the formit2resource - code, which you are using currently?

maybe the hook-snippet could also be modified to use runProcessor('resource/create') instaed of xpdo directly

]]>
Bruno17 Jul 23, 2015, 12:50 PM https://forums.modx.com/thread/97788/editing-modresource-from-the-front-end#dis-post-528807