Skip to content
Martin Zurowietz edited this page Feb 1, 2015 · 2 revisions

This guide shows all the steps for upgrading from v1 to v2.

  1. Replace site/plugins/sendform/ by the uniform/ directory of this repo.

  2. Rename the .sendform__potty honeypot CSS class to .uniform__potty in your CSS and in all of your forms. Change the name and id of the honeypot field from _potty to website (why?, and dont forget for of the label. If this produces a naming conflict, see how you can change the default honeypot name.

  3. Remove all sendform language variables from your site/languages/ files and replace them by the contents of the new language files of this repo. You can use the include_once method, too (see the "Linking" section of this blog post to see how).

  4. If you used email snippets, replace them by their new counterparts. Note the new naming convention uniform-<action>-<snippet>.php, so you have to change the names in the snippet option of the form. If you created custom snippets, rename the $data variable to $form.

  5. Move the $form = sendform(...) call from the page template to the page controller (if you haven't done this already).

Now we have to change the old sendform() call to the new uniform() call. Let's walk through the changes with the extended example:

old call:

$form = sendform(
    'registration-form',
    '[email protected]',
    array(
        'subject'   => 'Exhibition - New registration',
        'required'  => array(
            'name'  => ''
        ),
        'validate'  => array(
            'attendees' => 'num'
        ),
        'snippet'   => 'sendform-table',
        'copy'      => array(
            '[email protected]'
        )
    )
);

new call:

$form = uniform(
	'registration-form',
	array(
		'required' => array(
			'name'   => '',
			'_from'  => 'email'
		),
		'validate' => array(
			'attendees'	=> 'num'
		),
		'actions' => array(
			array(
				'_action' => 'email',
				'to'      => '[email protected]',
				'sender'  => '[email protected]',
				'subject' => 'Exhibition - New registration',
				'snippet' => 'uniform-email-table'
			),
			array(
				'_action' => 'email',
				'to'      => '[email protected]',
				'sender'  => '[email protected]',
				'subject' => 'Exhibition - New registration',
				'snippet' => 'uniform-email-table'
			)
		)
	)
);

There is one less argument in the function call, the receiver's email address. The Uniform plugin can now handle arbitrary form actions, so it is no longer restricted to sending emails. Because of this, subject, snippet and all the other options for sending an email are moved to the email action array in the actions option. The required and validate options remain the same in function and position but note, that the _from field now has to be explicitly declared as required.

The email action has two new arguments: to and sender. The first one contains the receiver's email address (previously the second argument of sendform()) and the second one will be used as the sender of the email (more on this).

If you are still not sure how to refactor your very own sendform() call, don't hesitate to open an issue and ask.

Clone this wiki locally