Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function buildForm(array $form, FormStateInterface $form_state) {
- $form['#attributes'] = array('enctype' => "multipart/form-data");
- $form['pdf_file'] = array(
- '#type' => 'file',
- '#title' => $this->t('PDF File'),
- '#description' => $this->t('PDF files only'),
- //'#multiple' => TRUE,
- '#required' => TRUE,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => $this->t('Save'),
- );
- return $form;
- }
- public function buildForm(array $form, FormStateInterface $form_state) {
- $form['#attributes'] = array('enctype' => "multipart/form-data");
- $form['pdf_file'] = array(
- '#type' => 'file',
- '#title' => $this->t('PDF File'),
- '#description' => $this->t('PDF files only'),
- //'#multiple' => TRUE,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => $this->t('Save'),
- );
- return $form;
- }
- $( "#target" ).submit(function( event ) {
- if( $(".pdf-file-field").files.length == 0 ){
- alert("Please add a file");
- event.preventDefault();
- }
- });
- namespace DrupalmymoduleForm;
- use DrupalCoreFormFormBase;
- use DrupalCoreFormFormStateInterface;
- /**
- * Class ExampleFileManagedForm.
- *
- * @package DrupalmymoduleForm
- */
- class ExampleFileManagedForm extends FormBase {
- /**
- * {@inheritdoc}
- */
- public function getFormId() {
- return 'example_file_managed_form';
- }
- /**
- * {@inheritdoc}
- */
- public function buildForm(array $form, FormStateInterface $form_state) {
- $form['pdf'] = array(
- '#type' => 'managed_file',
- '#title' => $this->t('Image'),
- '#upload_location' => 'public://pdf/',
- '#upload_validators' => array(
- 'file_validate_extensions' => array('pdf'),
- ),
- '#required' => TRUE,
- );
- $form['submit'] = [
- '#type' => 'submit',
- '#value' => t('Submit'),
- ];
- return $form;
- }
- /**
- * {@inheritdoc}
- */
- public function validateForm(array &$form, FormStateInterface $form_state) {
- parent::validateForm($form, $form_state);
- }
- /**
- * {@inheritdoc}
- */
- public function submitForm(array &$form, FormStateInterface $form_state) {
- dump($form_state->getValue('pdf')); die();
- }
- }
- array:1 [▼
- 0 => "467"
- ]
Add Comment
Please, Sign In to add comment