Skip to content

Submitting

Piotr Kierzniewski edited this page Nov 9, 2017 · 3 revisions

To submit form you have to pass request to form using handleRequest

// Get request object
$request = mf_get_request();

// Handle request
$form->handleRequest( $request );

handleRequest will automatically detect if form was sent. You can check it using isSubmitted method.

// Get request object
$request = mf_get_request();

// Handle request
$form->handleRequest( $request );

if( $form->isSubmitted() ) {
    // Get form data
    $data = $form->getData();

    // Perform action with form data e.g. send an e-mail
}

Do not execute handleRequest before createView. Otherwise built in Symfony framework events will not be properly applied to the view.

Best place to submit form are some early WordPress hooks like wp. Try to handle form submissions as early as possible to have a chance to redirect the user. When part of the template will be displayed and you will try redirect user you will get an error message about headers already outputed.

Read Symfony handling form submissions documentation to learn more.

Clone this wiki locally