0

I'm wondering why my form doesn't redirect to the chosen link using POST request and how to fix that?

In general what i'm planing to do is to prevent to access those links directly so i'm planing to check for the Request method if it wasn't POST then i will do a redirect, but my only problem at the moment is to access those links via that form using POST.

<div class="marketplace_div">
<form id="dropdownredirect" name="dropdownredirect" method="post">
<select class="marketplace_list" id="dropdownredirectselect">
      <option value="geschenkformular/">Amazon Germany</option>
      <option value="gift-form/">Amazon UK</option>
      <option value="gift-form/">Amazon France</option>
      <option value="gift-form/">Amazon Italy</option>
      <option value="gift-form/">Amazon Spain</option>
</select>

  <br>
<input class="marketplace_submit" name="submit" type="submit" value="Weiter  /  Submit" />
</form>
</div>


<script type="text/javascript">
jQuery(document).ready(function() {
    jQuery('#dropdownredirect').submit(function (event) {
        event.preventDefault();
        window.location = jQuery('#dropdownredirectselect').val();
    });
});
</script>

Thanks

Omkar C.
  • 755
  • 8
  • 21
arabtornado
  • 63
  • 2
  • 9
  • window.location just changes the URL, which is the same as manually typing it into the address bar which is considered GET. So in summary, you're canceling the default behaviour which is POST, and doing your own GET instead. – Royal Wares Feb 11 '19 at 08:04
  • @AlexanderDeSousa Thank you, that post exactly answers my question – arabtornado Feb 11 '19 at 08:20

1 Answers1

0

Do not use javascript use the the method attribute like this

<form action="/your-url" method="post">

</form> 
Makhele Sabata
  • 582
  • 6
  • 16