0
votes

So one of my pages consists of a quiz form that has several questions of type multiple choice, the choices are specified as radio buttons. I have been scanning the Symfony documentation to find out how to access form field values inputted by the user. Thing is, this isn;t a doctrine or propel based form, and neither do I require the values to be stored in the database, hence executing a $form->save() makes little sense to me. But I do require access to specific values of my form in my backend once the user hits submit.

Most of Symfony documentation that i have run into doesn't necessarily explain how this can be done. I would assume it would be something to the effect of : $request->getParameter( 'radio_choices_id selected value ').

Thanks to all who read this and Cheers to the ones who respond to it :)

Parijat

1

1 Answers

1
votes

Hm, it is very simple if I understand your question right) For widget:

$this->widgetSchema['name'] = new sfWidgetFormChoice(array('choices' => array('ch_1', 'ch_2')));

Ok,in action:

$this->form = new FaqContactForm();

        if ($request->isMethod('post')) {
            $this->form->bind($request->getParameter($this->form->getName()));

            if ($this->form->isValid()) {

                $your_val=$this->form->getValue('name');

                 //or

                 $your_val=$this->form['name']->getValue());
             }
         }

In backend in protected function processForm(sfWebRequest $request, sfForm $form) you have

$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';

      try {
        $product = $form->save();
      } catch (Doctrine_Validator_Exception $e) {

        $errorStack = $form->getObject()->getErrorStack();

        $message = get_class($form->getObject()) . ' has ' . count($errorStack) . " field" . (count($errorStack) > 1 ?  's' : null) . " with validation errors: ";
        foreach ($errorStack as $field => $errors) {
            $message .= "$field (" . implode(", ", $errors) . "), ";
        }
        $message = trim($message, ', ');

        $this->getUser()->setFlash('error', $message);
        return sfView::SUCCESS;
      }

Before $product = $form->save(); try

$your_val=$form->getValue('name');
//or
$your_val=$form['name']->getValue());