Page MenuHomePhabricator

Cannot handle multiple HTMLForms in single SpecialPage
Closed, ResolvedPublic

Description

[ originally posted in http://www.gossamer-threads.com/lists/wiki/wikitech/454703 ]

Creating two HTMLForms in single Special page with code:

public function execute($par) {
		$this->setHeaders();
                $array1 = $this->getAnnounceFormFields();
		$array2 = $this->getCreateFormFields();

	        $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();
}

Shows up the multiple forms, but clicking 'Submit' on one form submits both 'Forms'. ie it is not possible to submit only one form. The complete code is over here : https://phabricator.wikimedia.org/P770

Event Timeline

01tonythomas raised the priority of this task from to Needs Triage.
01tonythomas updated the task description. (Show Details)
01tonythomas subscribed.

Something like this might work?

if ( $this->getRequest()->wasPosted() ) {
	$action = $this->getRequest()->getVal( 'action' );
	switch ( $action ) {
		case 'form1':
			$form = $this->getForm1();
			break;
		case 'form2':
			$from = $this->getForm2();
			break;
		default:
			throw new Exception(...);
	}
	$form->show(); // Handle submission, etc.
} else {
	// hidden action=form1 field
	$this->getForm1()->displayForm();
	// hidden action=form2 field
	$this->getForm2()->displayForm();
}
Jdforrester-WMF moved this task from Blocked to Accepted on the Front-end-Standards-Group board.

Change 291837 had a related patch set uploaded (by Bartosz Dziewoński):
HTMLForm: Allow distinguishing between form views and submission attempts

https://gerrit.wikimedia.org/r/291837

matmarex lowered the priority of this task from Medium to Low.Jul 18 2016, 7:03 PM

Change 291837 merged by jenkins-bot:
HTMLForm: Allow distinguishing between form views and submission attempts

https://gerrit.wikimedia.org/r/291837

matmarex removed a project: Patch-For-Review.

It will now work as expected for forms that have an identifier set (call $form->setFormIdentifier( 'foo' ) when setting up the form). The identifier must be different for every form on the page.