Page MenuHomePhabricator
Paste P770

Multiple HTMLforms in single page
ActivePublic

Authored by 01tonythomas on Jun 11 2015, 1:28 PM.
<?php
/**
* Special page for creating newsletters and announcing issues
*
*/
class SpecialNewsletterPublishers extends SpecialPage {
function __construct()
{
parent::__construct('NewsletterPublishers');
}
public function execute($par)
{
$this->setHeaders();
$array1 = $this->getAnnounceFormFields();
$array2 = $this->getCreateFormFields();
# Do stuff
# ...
$htmlFormNewIssue = new HTMLForm( $array1, $this->getContext() );
$htmlFormNewIssue->setSubmitText( 'Create a new Issue' );
$htmlFormNewIssue->setSubmitCallback( array( 'SpecialNewsLetterPublishers', 'onSubmitNewIssue') );
$htmlFormNewIssue->show();
$htmlFormNewNewsLetter = new HTMLForm( $array2, $this->getContext() );
$htmlFormNewNewsLetter->setSubmitText( 'Create a new Newsletter');
$htmlFormNewNewsLetter->setSubmitCallback( array( 'SpecialNewsLetterPublishers', 'onSubmitNewsLetter') );
$htmlFormNewNewsLetter->show();
}
function getCreateFormFields() {
return array(
'name' => array(
'section' => 'newslettersection2',
'type' => 'text',
'label' => 'Name of newsletter'
),
'description' => array(
'section' => 'newslettersection2',
'type' => 'textarea',
'label' => 'Description',
'rows' => 15,
'cols' => 50,
),
'mainpage' => array(
'section' => 'newslettersection2',
'type' => 'text',
'label' => 'Title of Main Page'
),
);
}
function getAnnounceFormFields() {
return array(
'name1' => array(
'section' => 'newslettersection1',
'type' => 'text',
'label' => 'Name of newsletter'
),
'mainpage1' => array(
'section' => 'newslettersection1',
'type' => 'text',
'label' => 'Title of Main Page'
),
);
}
static function onSubmitNewsLetter( $formData ) {
echo "submitted new newsletter";
print_r( $formData );
return true;
}
static function onSubmitNewIssue( $formData ) {
echo "submitted new issue ";
print_r( $formData );
return true;
}
}

Event Timeline

01tonythomas edited the content of this paste. (Show Details)Jun 11 2015, 1:28 PM
01tonythomas changed the title of this paste from untitled to Multiple HTMLforms in single page.
01tonythomas updated the paste's language from autodetect to autodetect.