Answer the question
In order to leave comments, you need to log in
Why does the ModX Revo FormIt snippet not let me set the value to zero when editing the TV parameter?
Good afternoon, please tell me, I created a resource with a certain number of TV parameters through FormIt, so when editing this resource, you can also change these parameters using FormIt, but if you delete one of the previously filled fields, the resource does not take the value and gives the previous value. What could be the reason?
Chunk code
///////////
Notes
////// formit2resource
snippet code
<?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'));
// Publish
$doc->set('published', 1);
//DO NOT display in the menu
$doc->set('hidemenu', 1);
}
else{
$doc->set('editedby', $modx->user->get('id'));
foreach ($allFormFields as $field=>$value)
{
if ($field !== 'spam' && $field !== 'resource_id'){
$doc->set($field, $value);
}
}
$doc->set('template', $template);
$doc->save();
foreach ($allFormFields as $field=>$value)
{
if (!empty($value) && $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();
}
}
$response = $modx->runProcessor('gettags',
array(
'update' => 1,
'update_cache' => 1,
'category_id' => $page_parent
),
array('processors_path' => $modx- >getOption( 'core_path' ) . 'components/tag_manager/processors/')
);
if ($response->isError()) {
return $response->getMessage();
}
$modx->cacheManager->refresh();
return true;
resource2formit snippet code
<?php
if (isset($_GET['resId'])){
if ($doc=$modx->getObject('modResource',array('id'=>$_GET['resId']) )){
$docarray=$doc->toArray();
$fields = explode(',',$scriptProperties['resource2formitfields']);
$fields[] = 'id';
foreach ($fields as $field){
if ($doc->getFieldName($field) === null) {
/* if field isnt defined, look for TV value */
$tvValue = $doc->getTVValue($field );
if ($tvValue !== null) {
$hook->setValue($field,$tvValue);
/* otherwise get field value */
$hook->setValue($field,$docarray[$field]);
}
}
}
//$errorMsg = ''.print_r($docarray,true).'';
//$hook->addError('error_message',$errorMsg);
}
return true;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question