ngrmm
Members-
Posts
480 -
Joined
-
Last visited
-
Days Won
3
Everything posted by ngrmm
-
I'm not an expert ? but this sounds good. And another issue I had was this: I generate a page with the values of the submitted form. The filenames get sanitized after submitting. An uploaded Image.jpg is saved as image.jpg. So in order to save add the files uploaded to a page, you have to sanitize them. Because the values-array has the original filenames I did it this way: if($form->isValid()){ $p = new Page(); // create new page object $p->template = 'template_name'; // set template $p->parent = $pages->get(1111); // set the parent $p->name = $sanitizer->pageName($form->getValue('surname'), true); // give it a name used in the url for the page $p->title = $form->getValue('textField'); // set page title $p->save(); $p->addStatus('unpublished'); foreach($form->getValue('fileuploads') as $fileItem) { // // sanitizing // $sanitizer->fileName() did not work for me :( // $sFile = $sanitizer->pageName($fileItem, true); $p->images->add("https://domain.com/site/assets/files/{$page->id}/{$sFile}"); } $p->save(); } Maybe it be an option in the future to output the url of the image inside the values fieldarray?
-
Thanks @Juergen it worked! My other question is, if there is an option for unique filenames. I would like to use the form for submission. If someone uploads a file with the image.jpg, this file would be overwritten if someone else uploads another image with the same filename (image.jpg). Maybe something like this would help? $base = $pathinfo["filename"]; $filename = $base . "." . $pathinfo["extension"]; $destination = __DIR__ . "/uploads/" . $filename; $i = 1; while(file_exists($destination)) { $filename = $base . "($i)." . $pathinfo["extension"]; $destination = __DIR__ . "/uploads/" . $filename; $i++; }
-
@Juergen thanks for the module. I tried this: $form = new \FrontendForms\Form('myForm'); … $file1 = new \FrontendForms\InputFile('fileupload1'); $file1->setLabel('Multiple files upload'); $file1->setMultiple(true); $file1->setRule('allowedFileSize', '100000'); $file1->setRule('allowedFileExt', ['jpg','jpeg','png']); $form->add($file1); $button = new \FrontendForms\Button('submit'); $button->setAttribute('value', 'Send'); $form->add($button); if($form->isValid()){ print_r($form->getValues()); } echo $form->render(); But it renders this for the fileupload: <form method="post" action="/path/" id="myForm" name="myForm-1705439668" novalidate="" autocomplete="off" class="form" enctype="multipart/form-data"> … <div class="fieldwrapper" id="myForm-fileupload1-fieldwrapper"> <label class="label" for="myForm-fileupload1">Multiple files upload</label> <div class="inputwrapper" id="myForm-fileupload1-inputwrapper"> <input id="myForm-fileupload1" name="myForm-fileupload1[]" type="file" class="input input-file" multiple="" onchange="showClearLink(event)" accept=".jpg,.jpeg,.png" max-size="2048"> <div id="myForm-fileupload1-clearlink-wrapper" class="clear-link-wrapper" style="display:none;"> <a id="myForm-fileupload1-clear" href="#" class="clear-link" onclick="event.preventDefault();clearInputfield(this); return false;">Clear the input field</a> </div> </div> <p class="notes">Please do not upload files larger than 2,0 kB<br>Allowed file types: jpg, jpeg, png</p> </div> … </form> Do I have set the attribute allowedFileSize in another way, so that it allows larger files?
-
Need help for setup my Processwire MAMP ( beginner)
ngrmm replied to antoine.ctrs's topic in Getting Started
Could you tell a little bit more? Any Errors? At which step are you stuck? -
Just FYI for those pages you would need to loop through $championship->winner_name. So you better loop always
-
@JerryDi you already tried this?
-
What is the output for this: echo gettype($championship->winner_name);
-
that's right ?
-
@da² yes, but user IDs have normally only two digits
-
How to display page while images are getting resized?
ngrmm replied to Jozsef's topic in General Support
I'm curious and would like to know how the Drupal way handles the problem of layout shifts if images and image dimensions are not available on load? -
Then maybe winner_name is a multipagefield and you try this: $playerChampionships = $pages->find("template=Championship_results, winner_home_club={$page->id}"); foreach($playerChampionships as $championship) { echo "<li><a href='$championship->url'> $championship->title - {$championship->winner_name->first->title}</a></li>"; }
-
as @da² mentioned you missed adding the "->title" $playerChampionships = $pages->find("template=Championship_results, winner_home_club={$page->id}"); foreach($playerChampionships as $championship) { echo "<li><a href='$championship->url'> $championship->title - {$championship->winner_name->title}</a></li>"; }
-
@JerryDi could you paste in here the latest version of your code.
-
@neophron you could to set your settings here Setup > Templates > your-template > Advanced > List of fields to display in the admin Page List And maybe you look into a css solution to hide it for non-superusers. But I don't know if that is possible
-
@neophron why is code bad? Do you get an error or any output?
-
@JerryDi you can access fields and variables of your page (in this case champrionship pages) echo "<a href='$championship->url'>$championship->title</a>; have a look here: https://processwire.com/api/ref/page/
-
try this $playerChampionships = $pages->find("template=championship_results, winner_name=$page->id"); // or $playerChampionships = $pages->find("template=championship_results, winner_name={$page->id}");
-
I guess, it's this typo winner_name=§page->id' Should be winner_name=$page->id' You could also try winner_name=$page'
-
Display additional field next to title on tree list.
ngrmm replied to lenoir's topic in General Support
@lenoir you could also use the builtin option in the backend here: setup > templates > your-template > advanced > List of fields to display in the admin Page List -
assuming your other template name is championship you could do this in your player.php template $playerChampionships = $pages->find('template=championship, winner_name=$page->id'); foreach($playerChampionships as $championship) { // … }
-
How to structure Blog Posts, Categories, and Tags
ngrmm replied to ryangorley's topic in Getting Started
@ryangorley there is also the option to separate tags and categories from your blog tree structure and use URL segments. This way you could create URLs like /blog/tag-A/ and /blog/category-A/ at the same time -
@Jhin AFAIK there is fixed number of status options (locked, unique, hidden, unpublished, …) which you can set or check. Therefore you could add a checkbox field to your template. Then you could set the status in the backend or via API.
-
Making unpublished changes to pages that require approval?
ngrmm replied to mpdude's topic in Getting Started
@mpdude try this hook – Create a role for user, who should not be able to publish pages – Put this in ready.php file in the site directory $wire->addHookBefore('Pages::save', function(HookEvent $event) { $page = $event->arguments(0); $userRole = wire('user')->role; $page->of(false); if($userRole == "your_user_role_which_can_not_publish_pages") { $page->status('unpublished'); } }); -
Making unpublished changes to pages that require approval?
ngrmm replied to mpdude's topic in Getting Started
@BitPoet I've not tried it yet, but would this be not possible with a hook on page save out of the box?