Questions

Minishop2: german umlauts (ä, ö, ü)

When saving a new contact/customer german umlauts (ä, ü, ö) are filtered out.
Can I change this?
Is it in the class
msorderhandler
, function
validate($key, $value)
?

case 'receiver':
                // Transforms string from "nikolaj -  coster--Waldau jr." to "Nikolaj Coster-Waldau Jr."
                $tmp = preg_replace(
                    array('/[^-a-zа-яёЁ\s\.]/iu', '/\s+/', '/\-+/', '/\.+/'),
                    array('', ' ', '-', '.'),
                    $value
                );
                $tmp = preg_split('/\s/', $tmp, -1, PREG_SPLIT_NO_EMPTY);
                $tmp = array_map(array($this, 'ucfirst'), $tmp);
                $value = preg_replace('/\s+/', ' ', implode(' ', $tmp));
                if (empty($value)) {
                    $value = false;
                }
                break;
Thank you for your help.
Fabian Christen
29 june 2018, 13:18
116
0

Extra Office: how to save a extended field?

Hi all,

The documentation here explains how to show a extended field of a user.

But how can I save it the first time a user is filling a form?

[[!Office?
            	&action=`Auth`
            	&groups=`Customers`
            	&loginResourceId=`3`
            	&logoutResourceId=`22`
            	&HybridAuth=`0`
            	&profileFields=`username:50,email:50,fullname:50,mobilephone:12,address:20,city,zip,extended[company]`
            	&tplLogin=`shop.Office.auth.login`
            	&tplRegister=`shop.Office.auth.register`
            	&tplLogout=`shop.Office.auth.logout`
            	&tplActivate=`shop.Office.auth.activate`
            	&loginResourceId=`45`
            	
            ]]
and in the form:

<input type="text" name="extended[company]" placeholder="" class="form-control" id="extended.company" value=""/>

does not work.

Do I have to write a plugin that save this extended field?
Fabian Christen
14 march 2018, 17:19
336
+1

Error in move_uploaded_file when file uploading

Hello
I am using formit to upload image to server and create resource.
In formit2resource, I checked image file was uploaded in formit temp folder.
But, when move file to destination by move_uploaded_file function, an error was occured and temp image in temp folder was not moved.
I am a beginner on MODx, so I hope if someone can help me.

here is my formit2resource 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'));
}
else{
    $doc->set('editedby', $modx->user->get('id'));
}
 
$allFormFields = $hook->getValues(); 

 $modx->log(MODx::LOG_LEVEL_ERROR, 'all form fields'.print_r($allFormFields,true));

foreach ($allFormFields as $field=>$value)
{
 
   if ($field !== 'spam' && $field !== 'resource_id'){
         $doc->set($field, $value);
    }
}
 
 
$doc->set('template', '1');
$doc->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);
        }   
        //$modx->log(MODx::LOG_LEVEL_ERROR, 'array value-'.$doc->get('id').'-'.$value);
        
        $tv->setValue($doc->get('id'), $value);
        $tv->save();
    }
}
 

//$modx->log(modX::LOG_LEVEL_ERROR,'Start of script-');
// initialize output;
$output = true;
// get the current user name to for dicroty placement
$userName = $modx->user->get('username');
 
// valid extensions
$ext_array = array('jpg', 'jpeg', 'gif', 'png');
 
// create unique path for this form submission
$uploadpath = 'assets/userfiles/trash/';
//$uploadpath = 'idt-mdv1-y/assets/images/trash/' . $userName .'/';

// get full path to unique folder
$target_path = $modx->config['base_path'] . $uploadpath;
 
// get uploaded file names:
$submittedfiles = array_keys($_FILES);

//get exsisting user profile data for Profile_Photos
//$fields = $modx->user->getOne('Profile')->get('extended');
//$Photo_fields = $fields['trashimage'];
 
// loop through files
foreach ($submittedfiles as $sf) {
 
    // Get Filename and make sure its good.
    $filename = basename( $_FILES[$sf]['name'] );
    
    // Get file's extension
    $ext = pathinfo($filename, PATHINFO_EXTENSION);
    $ext = mb_strtolower($ext); // case insensitive
    
    if($filename != '') {
      
        // is this the right type of file?
        if(in_array($ext, $ext_array)) {
        
            //create file called the filename that has been sanitized
            $filename = strtolower(preg_replace("/[^A-Za-z0-9.]+/i", "-", $filename));
            
            // full path to new file
            $myTarget = $target_path . $filename;
            
            // temp file name
            $tempname = $_FILES[$sf]['tmp_name'];
            $modx->log(MODx::LOG_LEVEL_ERROR, 'temp name-'.$tempname);
            $modx->log(MODx::LOG_LEVEL_ERROR, 'target path-'.$myTarget);
            
			//URL path
			$urlPath = $uploadpath . $filename;
            $modx->log(MODx::LOG_LEVEL_ERROR, 'url path-'.$urlPath);
            
            // create directory to move file into if it doesn't exist
            if(!is_dir($target_path)){
                mkdir($target_path, 0755, true);
                $modx->log(MODx::LOG_LEVEL_ERROR, 'folder create');
            }
            
            if(file_exists($myTarget)) {
                chmod($myTarget,0755); //Change the file permissions if allowed
                unlink($myTarget); //remove the file
                $modx->log(MODx::LOG_LEVEL_ERROR, 'file delete');
            }
            
            // is the file moved to the proper folder successfully?
            if(move_uploaded_file($tempname, $myTarget)) {
        
                 $modx->log(MODx::LOG_LEVEL_ERROR, 'file moved');
                
                // $hook->setValue($sf, $uploadpath . $filename);
                // $modx->setPlaceholder($sf, $urlPath);
                
                // place file path to TV
                // if (!$doc->setTVValue($sf, $urlPath)) $modx->log(MODx::LOG_LEVEL_ERROR, 'Upload:Saving TV error');
                
                $tv = $modx->getObject('modTemplateVar', array ('name'=>'trashimage'));
                $tv->setValue($doc->get('id'), $urlPath);
                $tv->save();
                
                // set the permissions on the file
                if (!chmod($myTarget, 0644)) { /*some debug function*/ }  
                
            } else {
                // File not uploaded
                $errorMsg = 'There was a problem uploading the file.';
                $hook->addError($sf, $errorMsg);
                $output = false; // generate submission error
            }
        } 
        else {
            // File type not allowed
            $errorMsg = 'Type of file not allowed.';
            $hook->addError($sf, $errorMsg);
            $output = false; // generate submission error
        }
    
    } // if no file, don't error, but return blank
    else {
    
        // is the file name empty (no file uploaded) and exsiting photofields empty
        $hook->setValue($sf, '');
        $hook->addError($sf, 'no file uploaded');
        $doc->setTVValue($sf, '');      // insert empty value to TV
    }
}

$doc->save();

return $output;
dfXie
10 june 2017, 08:42
1 050
0

Line break or new line in snippet template?

Hello, maybe it is a strange question, but is there a way to make:

&tpl=`@INLINE <li[[+classes]]><a href="[[+link]]">[[+menutitle]]</a>[[+wrapper]]</li>`
display in html not in one line
<li></li><li></li><li></li>
but in new lines:
<li></li>
<li></li>
?

Thanks!
Trying
07 march 2016, 16:07
1 452
0

Modx Multidomain when domains are not aliases

Hello,

I will write in english, because I don't have russian keyboard, but feel free to reply in russian.

I have domains on one server with the same IP address, but in different directories (virtual domains?):

/same/same/domains/maindomain.com/public_html/ — modx install here
/same/same/domains/domain2.com/public_html/ — copies of .htaccess, index.php and config.core.php here
etc

Trying
05 march 2016, 10:14
925
0

Ajaxupload edit - Queue problem

I use a Formit call with some snippets (hooks and prehooks), to give users the ability to upload and edit resources.

Everything working properly except the files upload part. There I use AjaxUpload. The problem is that Ajaxupload when the user logs out, flashes the queue. So, when the user logout and login and try to edit resource, can't see the thumbnails. Data in the field is there but queue is blank.

[[!FormIt? 
    &hooks=`AjaxUpload2Formit, formit2resource, redirect`
    &preHooks=`resource2formit,Formit2AjaxUpload`
 &resource2formitfields=`template,resource_id,parent,Paratiriseis,pagetitle,Sex,Race,Age,Weight,Pedigree,Microchip,Passport,Area,Phone,Email,refnum,IMAGE`
    &redirectTo=`106`
    &ajaxuploadFieldname=`IMAGE`
    &ajaxuploadTarget=`images/uploads/`
    &ajaxuploadUid=`image_[[unique]]`
    &submitVar=`dog_input`
]]
Poko Loko
17 february 2016, 15:08
780
0

Unique number with strtotime

Hi, I would like to create a unique number for each resource I create via a Formit call.

I think the best way is to use a snippet that retrieves current time (with seconds, which is a unique number), that will run as a prehook when the form is loading. Also make a placeholder to use this number in several places inside form.

I am not sure if the code below will give results.

<?php
$unique = date('ymdHis',strtotime('NOW'));
$modx->setPlaceholder('time', $unique);
return '';
Poko Loko
16 february 2016, 08:35
1 269
0

getResources not working properly with snippet

I use getResources along a tpl that includes a snippet. Problem is that getresources gives mixed/wrong results.

My getResource call:
[[!getPage?
&elementClass=`modSnippet`
&element=`getResources`
&parents=`219`
&cache=`false`
&tpl=`MATCH_INDEX_FREE_TPL`
&showUnpublished=`0`
&showHidden=`1`
&includeContent=`1`
&limit=`5`
&processTVs=`1`
&includeTVs=`1`
&depth=`25`
&sortby=`createdon`
&sortdir=`DESC`
&pageNavVar=`page.nav`
]]
The TPL:
[[!IMAGE_PATH? &docid=`[[+id]]`]]
<div class="dog_cont">
<div class="data_title_new">[[+tv.Race]]</div>
<div class="dog_photo2">
<div id="ad_image_big"><a href="[[!+path1:phpthumbof=`w=900&zc=t`]]" rel="lightbox"><img src="[[!+path1:phpthumbof=`w=200&h=160&zc=t`]]" /></a></div>
<div id="ad_image_small" ><a href="[[!+path2:phpthumbof=`w=900&zc=t`]]" rel="lightbox"><img src="[[!+path2:phpthumbof=`w=95&h=80&zc=t`]]" /></a></div>
<div id="ad_image_small2"><a href="[[!+path3:phpthumbof=`w=900&zc=t`]]" rel="lightbox"><img src="[[!+path3:phpthumbof=`w=95&h=80&zc=t`]]" /></a></div>
</div>
The SNIPPET:
<?php
$docid = $modx->getOption('docid',$scriptProperties,$modx->resource->get('id'));
if ($resource = $modx->getObject('modResource',$docid)){
    $values = explode(',',$resource->getTVValue('IMAGE'));
    $i = 1;
    foreach ($values as $value){
        $modx->setPlaceholder('path'.$i,$value);
        $i++;
    }    
}
return '';
Poko Loko
11 february 2016, 23:00
1 180
0

Ajaxupload - Upload to new resource and edit

Hi,

I am trying to use Ajaxupload together with two formit snippets which are giving to the user the ability to create and edit resources from frontend.

With the code I attach bellow, I can upload photos to a new resource but I can't retrieve them when I edit the resource.

Formit call for new resource:
[[!FormIt? 
    &preHooks=`resource2formit, Formit2AjaxUpload`
    &hooks=`AjaxUpload2Formit, formit2resource, redirect` 
    &resource2formitfields=`template,resource_id,parent,Paratiriseis,Name,Sex,Race,Age,Weight,Pedigree,Microchip,Passport,Area,Phone,Email,pagetitle,photo`
    &redirectTo=`106`
    &ajaxuploadUid=`image`
    &ajaxuploadFieldname=`photo`
    &ajaxuploadTarget=`images/uploads/`
    &validate=`
     pagetitle:required,
     Sex:required,
     Race:required,
     Age:required,
     Phone:required,
     Email:required,
     Pedigree:required,
     Area:required`
    &vTextRequired=`*Απαραίτητο πεδίο`
    &submitVar=`dog_input`
]]
Formit call to edit resource:
[[!FormIt? 
    &preHooks=`resource2formit,Formit2AjaxUpload`
    &hooks=`AjaxUpload2Formit,formit2resource,redirect` 
    &resource2formitfields=`template,resource_id,Active,pagetitle,Paratiriseis,Sex,Race,Age,Weight,Pedigree,Microchip,Passport,Area,Phone,Email,content,photo`
    &resId=`[[~[[*id]]]]`
    &redirectTo=`106`
    &ajaxuploadUid=`image`
    &ajaxuploadFieldname=`photo`
    &ajaxuploadTarget=`images/uploads/`
    &validate=`
     pagetitle:required,
     Sex:required,
     Race:required,
     Age:required,
     Phone:required,
     Email:required,
     Pedigree:required,
     Area:required`
    &vTextRequired=`*Απαραίτητο πεδίο`
    &submitVar=`dog_input`
]]
Poko Loko
30 november 2015, 07:40
1 385
0

File input problem

Hi,

I am using a snippet to give the ability to logged users to post and edit specific type resources via formit.

One of the fields of the formit form is a file input that is uploading as a tv field.

The problem is that when a user updates the resource and leave the file input field blank, when it saves, the blank input overwrite any previous inputs.

All I want is to make the snippet to ignore blank inputs only at the file input field.

If anynone can help. I am really stuck here.

Below is the code I use.

<?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);
                }
            } else {
                /* otherwise get field value */
                $hook->setValue($field,$docarray[$field]);
            }    
        }
    }
  
    //$errorMsg = '<pre>'.print_r($docarray,true).'</pre>';  
    //$hook->addError('error_message',$errorMsg);  
}
  
  
return true;
Poko Loko
24 november 2015, 19:40
903
0