1. Go to this page and download the library: Download elao/json-http-form-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
elao / json-http-form-bundle example snippets
namespace AppBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
// ...
class RocketType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class)
->add('colors', ChoiceType::class, [
'multiple' => true,
'choices' => [
'White' => 'white',
'Orange' => 'orange',
'Blonde' => 'blonde',
'Pink' => 'pink',
'Blue' => 'blue',
'Brown' => 'brown',
]
])
;
}
// ...
}
namespace AppBundle\Controller;
// ...
class RocketController extends Controller
{
public function newAction(Request $request)
{
$rocket = new Rocket();
$form = $this->createForm(new RocketType(), $rocket)->getForm();
if ($form->handleRequest($request)->isSubmitted() && $form->isValid()) {
// The $rocket object is now correctly hydrated with the data from the form.
// Whether the request is a classic GET/POST request or a JSON one.
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.