0

I'm trying to create a basic form by referring the guide from tutorial

This is my version of form

class UsersForm extends BaseUsersForm
{
  public function configure()
  {
      $this->useFields(["name,email"]);

      $this->setWidgetSchema("email") = new sfWidgetFormInputText();
      $this->setWidgetSchema("name") = new sfWidgetFormInputText();

      $this->validatorSchema["email"] = new sfValidatorEmail();
      $this->validatorSchema["name"] =new sfValidatorString(["max_length" => "30"]);

      $this->widgetSchema->setLabels([

          "email" => "Email Address",
          "name" => "User name"

      ]);

  }
}

And I got this error

Fatal error: Can't use method return value in write context

Please tell me if I did wrong any part of the code.

5
  • dont use symfony1, its almost as old as me. Commented Mar 2, 2017 at 9:14
  • Symfony 1.4 is not maintained anymore, you should not waste your time learning it, learn Symfony2 instead Commented Mar 2, 2017 at 9:15
  • Which version of PHP are you using? Commented Mar 3, 2017 at 23:09
  • my version of php is 5.5 Commented Mar 6, 2017 at 2:33
  • Do the error says in which line is the problem? Commented Mar 7, 2017 at 15:54

1 Answer 1

8

There are several errors in your code, beginning with:

$this->useFields(["name,email"]);

where you probably wanted to write:

$this->useFields(["name", "email"]);

The fatal error you're getting is because of this snippet (you're trying to assign a value to function return value):

$this->setWidgetSchema("email") = new sfWidgetFormInputText();
$this->setWidgetSchema("name") = new sfWidgetFormInputText();

a better version would be:

$arWidgets = [
   "email" => new sfWidgetFormInputText(),
   "name" => new sfWidgetFormInputText(),
];

$arValidators = [
   "email" => new sfValidatorEmail(),
   "name" => new sfValidatorString(["max_length" => "30"]),
];

$this->setWidgets($arWidgets);
$this->setValidators($arValidators);

After applying these changes your problem should be solved.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.