Skip to content

Instantly share code, notes, and snippets.

View craigrodway's full-sized avatar

Craig A Rodway craigrodway

View GitHub Profile
@somatonic
somatonic / RandomImages.module
Last active December 17, 2015 06:49
get random images across pages optimized
<?php
/**
* Example use:
*
* $helper = $modules->get("RandomImages");
* $image = $helper->getRandomImages(1,"images");
* echo "<img src='{$image->size(150,0)->url}'>";
*/
@somatonic
somatonic / form_with_fields_in_table.php
Last active August 29, 2016 13:52
form with fields rendered in a table example
<?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 / form-process.php
Last active May 24, 2023 18:26
ProcessWire example front-end form with file upload and fields
<?php
// ------------------------------ FORM Processing ---------------------------------------
$errors = null;
$success = false;
// helper function to format form errors
function showError($e){
return "<p class='error'>$e</p>";
@somatonic
somatonic / upload_images_to_page_form.php
Created November 26, 2012 22:08
Upload Images to new created Page Form Example
<?php
// front-end form example with multiple images upload
// add new page created on the fly and adding images
$message = '';
if($input->post->submit){
// tmp upload folder for additional security
@somatonic
somatonic / form-example.php
Last active September 14, 2021 01:46
PW simple form via API
<?php
$out = '';
// create a new form field (also field wrapper)
$form = $modules->get("InputfieldForm");
$form->action = "./";
$form->method = "post";
$form->attr("id+name",'subscribe-form');
@sandfox
sandfox / Cat.php
Created May 16, 2012 15:31
Simple Model - Mapper abstract pair for PHP
<?php
namespace Sandfox\Model;
use \Sandfox\Model\ModelAbstract;
class Cat extends ModelAbstract
{
/**
* Define data names and defaults here
@neilj
neilj / gist:1532562
Created December 29, 2011 07:22
Sugared DOM: Better Than Templates
var el = ( function () {
var doc = document;
var directProperties = {
'class': 'className',
className: 'className',
defaultValue: 'defaultValue',
'for': 'htmlFor',
html: 'innerHTML',
// an immediate function
(function(){
// code goes here
})();
// a module with a public API returned
var MyModule = (function(){
// this variable is private
var privateVariable = "I'm scoped to the module's internals!";
@max-mapper
max-mapper / using-couch-with-node.txt
Created July 15, 2011 00:14
using couchdb with node.js
There are three essential components for most flexibly interacting with CouchDB from node:
couch API documentation:
http://jpmens.net/2010/04/20/the-antepenultimate-couchdb-reference-card/
http://www.couchbase.org/sites/default/files/uploads/all/documentation/couchbase-api.pdf
javascript HTTP library:
http://github.com/mikeal/request
javascript _changes feed consuming libaries (pick one):
@jchris
jchris / index.html
Created April 27, 2011 16:54
jQuery CouchDB Hello World - to use this script, create the map view in futon and click Save As, then upload index.html as an attachment to _design document created with the view. browse to index.html to run the app.
<!DOCTYPE html>
<html>
<head><title>Tiny CouchApp</title></head>
<body>
<h1>Tiny CouchApp</h1>
<form id="new_message">
<label for="message">Message:</label>
<input type="text" name="message" value="">
<p><input type="submit" value="Save &rarr;"></p>
</form>