Skip to content

Instantly share code, notes, and snippets.

Avatar

Philipp Urlich somatonic

View GitHub Profile
@somatonic
somatonic / HiddenAdminPages.module
Last active Jun 18, 2018
Hide page in the admin per user per page/branch
View HiddenAdminPages.module
<?php
/**
* UserWorkspaces
*
* Example module to hide page in the admin per user per page.
*
* ProcessWire 2.x
* Copyright (C) 2010 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
@somatonic
somatonic / RandomImages.module
Last active Dec 17, 2015
get random images across pages optimized
View RandomImages.module
<?php
/**
* Example use:
*
* $helper = $modules->get("RandomImages");
* $image = $helper->getRandomImages(1,"images");
* echo "<img src='{$image->size(150,0)->url}'>";
*/
@somatonic
somatonic / form-builder-html5off.php
Last active Dec 16, 2015
turn off html5 validation in form builder
View form-builder-html5off.php
<?php
// in form-builder.inc
$forms->addHookBefore('FormBuilderProcessor::render', null, 'hookRenderForm');
function hookRenderForm(HookEvent $event) {
$processor = $event->object;
$form = $processor->getInputfieldsForm();
$form->attr('novalidate', '1');
}
@somatonic
somatonic / paginator.php
Last active Mar 22, 2016
manual pagination example for in memory page arrays
View paginator.php
<?php
/**
* include paginator class from ProcessWire core, $config->paths->Modulename can
* be used to get the path of any module in PW.
*/
require_once($config->paths->MarkupPagerNav . "PagerNav.php");
/**
@somatonic
somatonic / form_with_fields_in_table.php
Last active Aug 29, 2016
form with fields rendered in a table example
View form_with_fields_in_table.php
<?php
/**
* Example form using PW API
*
* A workaround to get fields display in a table
* Those fields are marked with a property added to the fields $field->tablerow
*
* Approach is to grab those fields after form is put together and maybe processed,
* loop each row and render out the fields along with possible errors and add it to a string variable $table
* while we remove the field from the form at the same time.
@somatonic
somatonic / repeater_example.php
Last active Nov 23, 2019
example repeater creation and save front-end form
View repeater_example.php
<?php
$mypage = $pages->get("/about/");
if($input->post->submit){
$n = 1;
$title = "element_title_$n";
$url = "external_url_$n";
$mypage->setOutputFormatting(false);
@somatonic
somatonic / inputfieldfile-form.php
Last active Feb 13, 2020
ProcessWire front-end upload form example using ProcessWire Inputfields and form processing.
View inputfieldfile-form.php
<?php
/**
* ProcessWire (2.5) InputfieldFile front-end upload form example
* Various workarounds to get it working with Errors for WireUpload
* and removing files upload after error
*/
$sent = false;
$upload_path = $config->uploadTmpDir;
@somatonic
somatonic / form-process.php
Last active Nov 18, 2020
ProcessWire example front-end form with file upload and fields
View form-process.php
<?php
// ------------------------------ FORM Processing ---------------------------------------
$errors = null;
$success = false;
// helper function to format form errors
function showError($e){
return "<p class='error'>$e</p>";
@somatonic
somatonic / AddPageFieldProperty.module
Last active Dec 14, 2015
add page field as property to page example
View AddPageFieldProperty.module
<?php
/**
* ProcessWire AddPageFieldProperty demonstration module
*
*
* ProcessWire 2.x
* Copyright (C) 2010 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
*
@somatonic
somatonic / language_switch.php
Last active Dec 14, 2015
language switch for LanguageLocalizedURL module example
View language_switch.php
<?php
/* somehwere in the top of your template code */
// save current user language
$user_lang = $user->language;
// get the language name example
$curr_langname = $user_lang->name == 'default' ? 'en' : $user_lang->name;
You can’t perform that action at this time.