title: Convert two button functionalities in one button
body: <pre><code>&lt;form id=&quot;new&quot; action=&quot;{{ path('aff_new') }}&quot; method=&quot;post&quot; name=&quot;aff&quot;&gt;
      &lt;input name=&quot;affId&quot; id=&quot;affCode&quot; type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;{{ 'aff.code' | trans | capitalize }}&quot; required&gt; 
      &lt;button id=&quot;createAff&quot; type=&quot;submit&quot;&gt;Create&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  <p>The path aff_new is a route PHP that creates a new data :</p>
  <pre><code>#[Route('/aff/new', name: 'aff_new', methods: ['POST'])]
      public function new(Request $request): Response
      {
          if ($request-&gt;isMethod('POST')) {
          $code = $request-&gt;request-&gt;get('aff');
          //some data
          $aff = $this-&gt;affRepo-&gt;findOneBy([&quot;code&quot; =&gt; $aff-&gt;getCode()]);
          return $this-&gt;redirectToRoute('aff_edit', ['id' =&gt; $aff-&gt;getId()]);
      }
  </code></pre>
  <p>The second form imports data from JSON.</p>
  <pre><code>&lt;form id=&quot;import&quot; action=&quot;{{ path('aff_import') }}&quot; method=&quot;post&quot; name=&quot;aff&quot;&gt;
      &lt;input type=&quot;hidden&quot; data-action=&quot;{{ path('aff_json') }}&quot; id=&quot;aff_json&quot;&gt;
      &lt;select name=&quot;aff[code]&quot; data-placeholder=&quot;{{ 'affaire' | trans | capitalize }}&quot; required&gt;&lt;/select&gt;
      &lt;button id=&quot;importAff&quot; type=&quot;submit&quot;&gt;{{ 'import' | trans | capitalize }}&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  <p>The path aff_json and aff_import is a route PHP.</p>
  <pre><code>#[Route('/aff/json', name: 'aff_json')]
      public function findAll(Request $request): Response
      {
          // some datas
          return $this-&gt;json($aff);
      }
  
  
  #[Route('/aff/import', name: 'aff_import', methods: ['POST'])]
  public function store(Request $request): Response
  {
      //some datas
              return $this-&gt;redirectToRoute('aff_edit', ['id' =&gt; $aff_importee-&gt;getId()]);
          }
      }
  }
  </code></pre>
  <p>And finally I have a js file for execute this two functionalities :</p>
  <pre><code>const onClickImport = function () {
          let url = $('#aff').attr('data-action');
          $(&quot;#import .select2-ajax&quot;).select2({
              dropdownParent: $('#import'),
              // some datas
                  processResults: function (data) {
                      return {
                          results: $.map(data, function (item) {
                              return {
                                  text: item.code,
                              }
                          }),
                      }
                  }
              }
          }).trigger('change');
  
          modalImportAffaire.show();
      }
  
      const onClickNew = function () {
          modalNewAffaire.show();
      }
  </code></pre>
  <p>What I want, it's to do only one form using these two functionalities (two buttons), that means, I can write a value into a type, if the value exists in dropdown I can click on import and if doesn't exist I can click on create, how can I do that?</p>