I don't do documenation well - here's the code to use jpgraphs stuff - someone else will need to write more details here about installing it, where to put files etc. etc.
action:
class profileActions extends sfActions
{
public function executeRegister()
{
if ($this->getRequest()->getMethod() == sfRequest::POST) {
// process form
}
require_once 'jpgraph/jpgraph_antispam.php';
$antispam = new AntiSpam();
$antispam_string = $antispam->rand(5);
$this->getUser()->setAttribute('antispam', $antispam_string);
}
public function executeAntispam() {
if (!$string = $this->getUser()->getAttribute('antispam')) {
return sfView::NONE;
}
require_once 'jpgraph/jpgraph_antispam.php';
$this->getResponse()->setContentType('image/jpeg');
$antispam = new AntiSpam($string);
echo $antispam->stroke();
return sfView::NONE;
}
}
view:
<label>Picture</label>
<img src="<?php echo url_for('profile/antispam'); ?>" />
<br />
validator: myCharactersValidator.class.php
class myCharactersValidator extends sfValidator
{
public function execute (&$value, &$error)
{
$string = sfContext::getInstance()->getUser()->getAttribute('antispam');
if ($value != $string) {
// generate a new image....
require_once 'jpgraph/jpgraph_antispam.php';
$antispam = new AntiSpam();
$antispam_string = $antispam->rand(5);
sfContext::getInstance()->getUser()->setAttribute('antispam', $antispam_string);
$error = $this->getParameter('characters_error');
return false;
}
return true;
}
}