Page MenuHomePhabricator

Cannot handle multiple HTMLForms in single SpecialPage
Closed, ResolvedPublic


[ originally posted in ]

Creating two HTMLForms in single Special page with code:

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

	        $htmlFormNewIssue = new HTMLForm(  $array1, $this->getContext() );
		$htmlFormNewIssue->setSubmitText( 'Create a new Issue' );
		$htmlFormNewIssue->setSubmitCallback( array( 'SpecialNewsLetterPublishers', 'onSubmitNewIssue') );

		$htmlFormNewNewsLetter = new HTMLForm( $array2, $this->getContext()  );
		$htmlFormNewNewsLetter->setSubmitText( 'Create a new Newsletter');
		$htmlFormNewNewsLetter->setSubmitCallback( array( 'SpecialNewsLetterPublishers', 'onSubmitNewsLetter') );

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 :

Event Timeline

01tonythomas raised the priority of this task from to Needs Triage.
01tonythomas updated the task description. (Show Details)
01tonythomas added a subscriber: 01tonythomas.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJun 11 2015, 1:26 PM

Any update on this ?

Something like this might work?

if ( $this->getRequest()->wasPosted() ) {
	$action = $this->getRequest()->getVal( 'action' );
	switch ( $action ) {
		case 'form1':
			$form = $this->getForm1();
		case 'form2':
			$from = $this->getForm2();
			throw new Exception(...);
	$form->show(); // Handle submission, etc.
} else {
	// hidden action=form1 field
	// hidden action=form2 field
TTO added a subscriber: TTO.Aug 13 2015, 9:25 AM
Jdforrester-WMF triaged this task as Medium priority.May 11 2016, 6:37 PM
Jdforrester-WMF moved this task from Blocked to Accepted on the Front-end-Standards-Group board.
matmarex claimed this task.May 25 2016, 1:40 PM

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

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

matmarex closed this task as Resolved.Jul 22 2016, 6:52 PM
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.