Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8752049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:09:29+00:00 2026-06-13T13:09:29+00:00

I am using CraueFormFlowBundle to have a multiple page form, and am trying to

  • 0

I am using CraueFormFlowBundle to have a multiple page form, and am trying to do some validation on some of the fields but can’t figure out how to do this. The object that needs to be validated isn’t an Entity, which is causing me trouble.

I tried adding a collectionConstraint in the getDefaultOption function of my form type class, but this doesn’t work as I get the “Expected argument of type array or Traversable and ArrayAccess” error.
I tried with annotations in my object class, but they don’t seem to be taken into account. Are annotations taken into account if the class isn’t an entity? (i set enable_annotations to true)

Anyway, what is the proper way to do this? Basically, I just want to validate that “age” is an integer…

class PoemDataCollectorFormType extends AbstractType {
    public function buildForm(FormBuilder $builder, array $options) {
        switch ($options['flowStep']) {
            case 6:
            $builder->add('msgCategory', 'hidden', array(
                ));
            $builder->add('msgFIB','text', array(
                'required' => false,
            ));
            $builder->add('age', 'integer', array(
                'required' => false,
                ));
            break;
        }
    }
    public function getDefaultOptions(array $options)
    {
        $options = parent::getDefaultOptions($options);
        $options['flowStep'] = 1;
        $options['data_class'] = 'YOP\YourOwnPoetBundle\PoemBuilder\PoemDataCollector';
        $options['intention'] = 'my_secret_key';

        return $options;
    }
}

EDIT: add code, handle validation with annotations

As Cyprian, I was pretty sure that using annotations should work, however it doesn’t…
Here is how I try:

In my Controller:

public function collectPoemDataAction() {
    $collector = $this->get('yop.poem.datacollector');
    $flow = $this->get('yop.form.flow.poemDataCollector');
    $flow->bind($collector);
    $form = $flow->createForm($collector);
    if ($flow->isValid($form)) {
        ....
    }
}

In my PoemDataCollector class, which is my data class (service yop.poem.datacollector):

class PoemDataCollector
{
     /**
     * @Assert\Type(type="integer", message="Age should be a number")
     */

    private $age;
}

EDIT2:

Here is the services implementation:
The data class (PoemDataCollector) seems to be linked to the flow class and not to the form.. Is that why there is no validation?

    <service id="yop.poem.datacollector" class="YOP\YourOwnPoetBundle\PoemBuilder\PoemDataCollector">
    </service>
    <service id="yop.form.poemDataCollector"
            class="YOP\YourOwnPoetBundle\Form\Type\PoemDataCollectorFormType">
        <tag name="form.type" alias="poemDataCollector" />
    </service>
    <service id="yop.form.flow.poemDataCollector"
            class="YOP\YourOwnPoetBundle\Form\PoemDataCollectorFlow"
            parent="craue.form.flow"
            scope="request">
        <call method="setFormType">
            <argument type="service" id="yop.form.poemDataCollector" />
        </call>
    </service>

How can I do the validation while respecting the craueFormFlowBundle guidelines?

The guidelines state:

Validation groups
To validate the form data class a step-based validation group is passed to the form type. By default, if getName() of the form type returns registerUser, such a group is named flow_registerUser_step1 for the first step.

Where should I state my constraint to use those validation groups..?

I tried:

YOP\YourOwnPoetBundle\PoemBuilder\Form\Type\PoemDataCollectorFormType:
    properties:
        name:
          - MinLength: { limit: 5, message: "Your name must have at least {{ limit }} characters.", groups: [flow_poemDataCollector_step1] }
        age:
          - Type:
               type: integer
               message: Please input a number
               groups: [flow_poemDataCollector_step6]

But it is not taken into acount.

EDIT3:

OK, much better, validation on name seems to be working with:

/**
 * @Assert\MinLength(limit=5, groups={"flow_poemDataCollector_step1"}, message="Your name must have at least {{ limit }} characters.")
 */
private $name;

Although the message doesn’t appear…
I have put {{ form_errors(form.name) }} and {{ form_errors(form) }} in my template… Why doesn’t it show?

But:

/**
 * @Assert\Type(type="integer", groups={"flow_poemDataCollector_step6"}, message="Age should be a number")
 */

private $age;

isn’t working at all…

EDIT4:

Allright, I managed to have my validation working now.. But I can’t find a way to display the error messages. Aren’t they supposed to show when using:

{{ form_errors(form.name) }}

or

{{ form_errors(form) }}

in my template?
In my case, when validation fails, i return to the same step in my form but no error message is shown. Besides, $form->getErrors() returns an empty array! How to handle errors?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:09:30+00:00Added an answer on June 13, 2026 at 1:09 pm

    So here is what was happening: i wasn’t rendering the same instance of the form as the one being validated…

    I was rendering my page with 'form' => $flow->createForm($collector)->createView(), changing it to 'form' => $form->createView() solved my issue: error messages are now rendered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using C# .NET 3.5 and WCF, I'm trying to write out some of the
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using Matlab, I have to transform the intensity of an image using this given
Using Java: I didn't want to waste peoples time and post this here, but
Using MVC2 I have an AJAX form which is posting to a bound model.
Using WebViewBrush I can render web page content (it's screen shot) to e.g. Rectangle
Using Java,I have to fetch multiple sets of values from an XML file to
Using EF Code First I have an model object that has multiple properties that
I'm using Symfony2 and CraueFormFlowBundle to create a multi-step form. Everything is going well
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.