What I want to do is pretty simple:
1) A single input box with a submit button 2) I want to take whatever input and redirect the user based on the input, so if my site is www.example.com and the user submits 'test' then I want to redirect to www.example.com/test
However, the symfony2 docs are lacking in examples. I have been able to build my form with this:
class VariantType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('urlId', 'text', array('label' => 'tiny.cc/'))
->add('Go', 'submit')
->getForm();
}
public function getName()
{
return 'index';
}
}
This generates things fine, but I realize I have no submission handler. I assume I need a 'newAction function which takes the request as explained in different parts of the documentation:
http://symfony.com/doc/current/book/forms.html
So I tried this....
public function newAction(Request $request){
$form->handleRequest($request);
if($form->isValid()){
return $this->redirect($this->generateUrl('homepage_id'));
}
}
My 'homepage_id' route handles the route with the 'test' input on the end of the url. I think I can just forward to the url I want and my routing system will handle everything, which shows you how basic my needs are. But the above doesn't seem to work. I also have a validation.yml, but I don't think this is my real hurdle. Even if anyone can point to any docs which explain something like this I would appreciate it. (The symfony2 docs are just not helpful: it tells me creating a formbuilder is recommended, but doesn't say how to submit the form, so I go to the section where it talks about submitting the form, and try and put in the relevant function, but still doesn't work. I can't find any example which puts these pieces together.)
But the above doesn't seem to work- what errors did you get ?