1

I'm making a donate feature in my laravel project where user can donate with paypal and credit card.I made the form with basic input and it works but now i have to do it with an select dropdown where you can select the value or a specific amount and that value i have to send it to controller

This is the form and i have to send the amount to controller but it only works with the select input and when i select other to type the specific value the form is returning value 0

<form  method="POST" id="payment-form"  action="{!! URL::to('paypal') !!}">
{{ csrf_field() }}
<div class="form-group form-group-s">
    <select class="form-control" id="amount" name="amount">
        <option value="50">CHF 50</option>
        <option value="200">CHF 200</option>
        <option value="500">CHF 500</option>
        <option value="2000">CHF 2000</option>
        <option id="other">Other</option>
    </select>
    <div class="form-group otherName" id="amount">
        <label for=""></label>
        <input type="number" id="amount" name="amount" class="form-control" placeholder="CHF" />
    </div>
</div>
        <div class=" form-group">
            <button class="form-control btn btn-subscribe"><i class="fab fa-paypal"></i> Pay with PayPal</button>
        </div>

So here needs to come the amount but it does not recognize 2 amount ids so i dont know what to do..

$item1->setName('Amount')
      ->setCurrency('EUR')
      ->setQuantity(1)
      ->setPrice($request->get('amount'));
  • When you choose other, you need to input behind the dropdown list, but why your input hhas the same name ? – Saromase Jan 29 '19 at 12:31
  • https://stackoverflow.com/a/31016229/9344853 Possible with this? – Lim Kean Phang Jan 29 '19 at 12:46
  • 1
    Use **javascript** for this. When the user selects _others_, show the input type _named others_, on the controller side check if the amount == _others_ assign amount value to _others_ value. – Ishaan Jan 29 '19 at 12:58
  • @Ishaan thank you but i dont have enough knowledge in javascript if you can suggest something i would appreciated and if not its not a problem thank you anyway – Ardit Imeri Jan 29 '19 at 13:04
  • @ArditImeri you can go for the Lim Kean Phang's suggestion or try [this](https://stackoverflow.com/a/23902304/8677188) example. – Ishaan Jan 29 '19 at 14:46
  • @Ishaan thank you that was very helpful :) have a nice day – Ardit Imeri Jan 29 '19 at 15:21

0 Answers0