0

Trying to make a simple form but i keep getting "Variable "subscriptionForm" does not exist."

enter image description here

Here is Controller method:

public function subscriptionForm(Request $request):             \Symfony\Component\HttpFoundation\RedirectResponse|array
{
    $subscriptionForm = $this
        ->getFactory()
        ->createSubscriptionForm()
        ->handleRequest($request);

    if ($subscriptionForm->isSubmitted() && $subscriptionForm->isValid()) {
        // Call the client for e.g. to save the subscriber.
    
        // Redirect to home page after successful subscription
        return $this->redirectResponseInternal('home');
    }
    
    return $this->viewResponse([
        'subscriptionForm' => $subscriptionForm->createView(),
    ]);
}

Twig file:

{% block body %}
    {{ form_start(subscriptionForm) }}
    {{ form_widget(subscriptionForm.email) }}
    {{ form_errors(subscriptionForm.email) }}
    <input type="submit" value="Subscribe" />
    {{ form_end(subscriptionForm) }}
{% endblock %}
Ricky
  • 3
  • 1
  • Maybe try using `$this->render('', ['subscriptionForm' => $subscriptionForm->createView()]);`? And remove ``, it's not necessary, it'll be rendered automatically. – msrumon Feb 05 '23 at 05:33
  • I don't see any errors. Two suggestions, first: Delete the cache, second: check if the template that you think is rendered matches your expected – Jim Panse Feb 06 '23 at 14:20

1 Answers1

0

Spryker assigns all twig variables within a _view object. Try adding these code on top of the twig file:

{% define data = {
    subscriptionForm: _view.subscriptionForm
} %}