Closed motammem closed 10 years ago
Can you send a piece of code ?
namespace BlueTree\AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class PageController extends Controller
{
public function indexAction()
{
$form = $this->createFormBuilder()
->add('date', 'mohebifar_datetime',
array(
'years' => range(1300, 1400)
))
->add('submit', 'submit')
->getForm();
$form->handleRequest($this->get('request'));
if ($form->isValid()) {
// This line prints wrong date.
var_dump($form->getData()['date']);
}
return $this->render('@BlueTreeApp/Pages/index.html.twig', array('form' => $form->createView()));
}
}
I got the solution, values displayed in form begin from zero, how ever they should be same as the month, day and year numbers.
following code solves problem:
->add('date', 'mohebifar_datetime',
array(
'years' => array_combine(range(1300, 1400),range(1300, 1400)),
'months' => array_combine(range(1,12),range(1,12)),
'days' => array_combine(range(1,31),range(1,31))
))
Yes exactly ! Thank you.
Instead of converting '19-azar-1370' to '1991-12-10' it converts to '1921-11-09'.