I am new to symfony, after going through several online tutorials and blogs, i am trying to create a simple project. I created some modules with command console. and now i have created a form using simple html and now i need to store the form values in database. I am trying to do it in a simple way, like i am getting an array of sfWebRequest $request and then i did something like:-
$name = $request->getPostParameters()['name'];
$email = $request->getPostParameters()['email'];
$password = $request->getPostParameters()['password'];
however I am perfectly able to store fields in database, but i am a bit confused about the way i am doing. is there any other better way to do the same. and if i have a single form with ten fields, and i want to store them in 2 tables, how can do that.
HERE GOES MY HTML CODE
<form id="formElem" name="formElem" action="/register/register" method="post">
<fieldset class="step">
<legend>Account</legend>
<p>
<label for="username">User name</label>
<input id="username" name="username" />
</p>
<p>
<label for="email">Email</label>
<input id="email" name="email" placeholder="info@tympanus.net" type="email" AUTOCOMPLETE=OFF />
</p>
<p>
<label for="password">Password</label>
<input id="password" name="password" type="password" AUTOCOMPLETE=OFF />
</p>
......
......
And here is my Action Function:-
public function executeRegister(sfWebRequest $request)
{
if ($request->isMethod('post'))
echo $request->getParameter('password');exit;
$this->redirect('user/login');
}
You should use
sfFormto handle form validation. If you use Doctrine for your models then it will be even easier because you can generate all the basics based on the schema definition.Regardless when using
sfFormyour action would look something like the following: