Skip to content

Instantly share code, notes, and snippets.

View Da-Fecto's full-sized avatar

Martijn Geerts Da-Fecto

View GitHub Profile
// Stolen code, thanks Soma !
public function init() {
$this->addHookAfter("ProcessPageView::pageNotFound", $this, "hook404Page");
}
public function hook404Page($event){
header("HTTP/1.1 404 Page Not Found");
$page = wire("pages")->get("/404/"); // get your 404 page
$this->wire('page', $page);
$event->return = $page->render(); // render and return that page
@Da-Fecto
Da-Fecto / gist:c7c3f236f83e6690e0af
Last active August 29, 2015 14:24
Formbuilder Handler.php
<?php
$config->form = array(
// Name of the formbuilder form
'formName' => $form_name,
// Redirect to here after successful submit.
'successUrl' => $success_url,
// Global error message after faulty submit.
'errorMessage' => $error_message,
);
@Da-Fecto
Da-Fecto / gist:53b68d309fe98f3a15df
Last active August 29, 2015 14:22
Work in progress
<?php
/**
* JSON response with a “standardized” structure
*
* @author ©2015 Martijn Geerts
*
* ---------------------------------------------------------------------------------------
*
* 4 types: success, redirect, fail, error
@Da-Fecto
Da-Fecto / bidirectional
Last active August 29, 2015 14:18
Bidirectional save & remove of products & groups (Fieltype pages)
<?php
/**
* Groups & Products references guard.
*
* Bidirectional save & remove of products & groups
*
* templates:
* - 'group', pagefield: page_products
* - 'product', pagefield: page_groups
@Da-Fecto
Da-Fecto / templates-folder-switch.php
Last active May 6, 2016 05:23
Templates folder switch for ProcessWire
<?php
/**
* Switch ProcessWire templates directory on $_SERVER['HTTP_HOST']. Type the
* Hostname as key and the name of the new templates folder as value.
*
*/
$config->templates = array(
'mobile.domain.dev' => 'templates-mobile', // domain => templates folder name
@Da-Fecto
Da-Fecto / fractural-grid.php
Last active August 29, 2015 14:15
Build a CSS fractural grid.
<?php
/**
* Build a CSS fractural grid.
*
* @var (int) $columns, Amount of columns, 10 columns means 10 columns of 10% width
* @var (string) $prefix, Classname prefix
*/
@Da-Fecto
Da-Fecto / HideUneditablePages.module
Last active August 29, 2015 14:13
Module to hide pages that are not editable by the logged in user.
<?php
/**
* This module is build by Adrian, tnx Adrian.
*
*
* Module to hide pages that are not editable by the logged in user.
*
* ProcessWire 2.x
* Copyright (C) 2010 by Ryan Cramer
@Da-Fecto
Da-Fecto / clear_errors.php
Last active August 29, 2015 14:01
clear error ProcessWire
<?php
wire()->addHookAfter('InputfieldForm::processInput', function($event) {
$form = $event->object;
if($form->name != 'your-form-name') return;
$email = $form->getChildByName('email');
if($email) foreach($f->getErrors(true) as $error) { // true clears existing errors
if($error == 'Missing required value') {
$f->error('Please enter a valid email address'); // replace error message
@Da-Fecto
Da-Fecto / TextformatterEmail.module
Last active August 29, 2015 13:56
Emailaddress to mailto link
<?php
/**
* ProcessWire Emailaddress mailto link
*
* ProcessWire 2.x
* Copyright (C) 2010 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
*
* http://www.processwire.com
@Da-Fecto
Da-Fecto / FieldtypeFolder.module
Last active January 1, 2016 09:49
ProcessWire files in folder Fieldtype & Inputfield.
<?php
/**
* ProcessWire files in folder Fieldtype
*
* ©2013 Martijn Geerts
*
* ProcessWire 2.x
* Copyright (C) 2010 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT