Assign Values to Drop-Down Menus in PayPal Third-Party Carts - drop-down-menu

I am trying to implement a PayPal cart on a third-party site. Customers are first asked to select a product ("Product") from a drop-down menu and then, optionally, to enter a specific amount ("Additional Costs") into a text field. Both values should finally be sent to PayPal upon submitting.
While everything works fine with two text fields, where amount_1 and amount_2 are clearly defined, I struggle with assigning different values (/amounts, say 10.00 and 5.00) to the options of the drop down and to make the value of the selected option my value amount_1. Here is the code I figured out so far:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="whatever#gmail.com">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="item_name_1" value="Product">
<input type="hidden" name="on0_1" value="Product">
<select name="os0_1">
<option value="product1">Product 1</option>
<option value="product2">Product 2</option>
</select>
<input type="hidden" name="item_name_2" value="Additional Costs">
<input type="text" name="amount_2" value="0.00">GBP
<br>
<br>
<input type="hidden" name="currency_code" value="GBP">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
option_select and option_amount do not seem to work with this kind of form. Any help would be greatly appreciated!

I'm assuming this is the select box that is used to select the product amount_1:
<select name="os0_1">
<option value="product1">Product 1</option>
<option value="product2">Product 2</option>
</select>
What you need to do is this:
<input type="hidden" name="item_name_1" value="Product" id="item_name_1">
<select name="amount_1" onchange="changeProductName()" id="amount_1">
<option value="5.00">Product that is a fiver</option>
<option value="10.00">Product that is a tenner</option>
</select>
<script>
function changeProductName() {
var e = document.getElementById('amount_1');
var h = document.getElementById('item_name_1');
h.value = e.options[e.selectedIndex].text;
}
</script>
That will change the item_name_1 to the friendly value of the price option.

Related

How to save multiple inputs to the database when the input is in loop laraval 8

I am working on a Laravel 8 project. I have a row with 3 inputs and a button which can add more line of row. Doesn't matter how many lines I add only the first row is submitted in the database. Please help me with that. Thank you!
index.blade.php:
<h4>Add Products</h4>
<form action="{{ url('insert-products') }}" method="POST" enctype="multipart/form-data">
#csrf
<select class="form-select" name="cateId">
<option value="">Select a Category</option>
#foreach ($category as $item)
<option value="{{ $item->id }}">{{ $item->name }}</option>
#endforeach
</select>
<br>
<label for="">Product Name</label><br>
<input type="text" name="productName" id="quantity2" required><br>
<br>
<input type="checkbox" name="status" required>
<br>
<div class="customer_records">
<input type="text" name="productName" id="quantity_img2" required>
<input type="text" name="productVariant" required>
<input type="text" name="productValue" required>
<a class="extra-fields-customer" href="#">Add More Customer</a>
</div>
<div class="customer_records_dynamic"></div>
<button type="submit" class="btn btn-outline-success waves-effect" id="type-success">Add Product</button>
</form>
controller:
public function insert(Request $request){
$products = new Products();
$products->cateId = $request->input('cateId');
$products->productName = $request->input('productName');
$products->status = $request->input('status') == TRUE ? '1':'0';
$products->productVariant = $request->input('productVariant');
$products->productValue = $request->input('productValue');
if($products->save()){
return redirect('/categories')->with('status',"Products Added Succesfully");
}
else{
return redirect('/categories')->with('status',"Something went wrong");
}
}
You have several transmissions involved:
The request
First of all, you need to make sure that the values are sent at all. Seeing your code, I presuppose that on the request level a single value is being sent. You will need to indicate that there will be multiple values involved, such as
<label for="">Product Name</label><br>
<input type="text" name="productName[]" id="quantity2" required><br>
<br>
<input type="checkbox" name="status[]" required>
<br>
<div class="customer_records">
<input type="text" name="productName[]" id="quantity_img2" required>
<input type="text" name="productVariant[]" required>
<input type="text" name="productValue[]" required>
<a class="extra-fields-customer" href="#">Add More Customer</a>
</div>
Notice the [] indicating multiplicity.
Sidenote: I would strongly discourage you from hard-coding ids into repeated templates, as they will end up being duplicated, which makes your HTML invalid.
The application
While the previous section should fix an issue, it's not guaranteed that it's the only issue. It makes sense to debug and see what you have on application-side sent by the request. If you have all the values, then all is well and good. If not, then investigate the reason and fix it.
The database
You need to make sure that your code attempts to store everything. If so, then a further question is whether it's done successfully. If not, then you will need to debug your code to see what's wrong.

How to insert multiple checkbox data to database using Codeigniter

Can somebody help me? I have question. I have view, name is pascasarjana.php
<div class="form-group">
<label>Program studi dan konsentrasi yang diminati</label><br/>
<input name="prodis" type="checkbox" value="p1">Program Studi Magister Manajemen<br/>
</div>
<div class="form-group">
<input name="prodis" type="checkbox" value="p2">Program Studi Magister Teknik Sipil
<select name="konsentrasi" class="form-control" id="konsentrasi1">
<option value="">Pilih Konsentrasi</option>
<option value="k1">Manajemen Konstruksi</option>
<option value="k2">Transportasi</option>
<option value="k3">Struktur</option>
</select>
</div>
<div class="form-group">
<input name="prodis" type="checkbox" value="p3">Program Studi Magister Ilmu Hukum
<select name="konsentrasi" class="form-control" id="konsentrasi2">
<option value="">Pilih Konsentrasi</option>
<option value="k4">Hukum Bisnis</option>
<option value="k5">Hukum Ketatanegaraan</option>
<option value="k6">Hukum Agraria</option>
<option value="k7">Litigasi</option>
</select>
</div>
<div class="form-group">
<input name="prodis" type="checkbox" value="p4">Program Studi Magister Teknik Informatika
<select name="konsentrasi" class="form-control" id="konsentrasi3">
<option value="">Pilih Konsentrasi</option>
<option value="k8">Soft Computing</option>
<option value="k9">Enterprise Information System</option>
<option value="k10">Mobile Computing</option>
</select>
</div>
<div class="form-group">
<input name="prodis" type="checkbox" value="p5">Program Studi Magister Teknik Arsitektur
<select name="konsentrasi" class="form-control" id="konsentrasi4">
<option value="">Pilih Konsentrasi</option>
<option value="k11">Arsitektur Digital</option>
</select>
</div>
AND I confused, how to insert multiple checkbox and select option data to database in my controller and model.
Try renaming your HTML entities as arrays
Eg.
input name="prodis" to input name="prodis[]"
select name="konsentrasi" to select name="konsentrasi[]"
Then print $_POST in your controller.
I guess you need to get data from select box on the basis of ticked checkbox.
For getting values from checkbox you need to define checkbox name as an array. In my code I am using exact indexes so we can get select box values accordingly.
I guess below first checkbox there should be another select box. Ignoring this select box (Which is actually not here), I am giving custom indexes here. Instead, we also can use like profis[] which actually auto generate indexes by incrementing it one on each occurrence in HTML
You can implement validation too. Here are modified code:
<div class="form-group">
<label>Program studi dan konsentrasi yang diminati</label><br/>
<input name="prodis[1]" type="checkbox" value="p1">Program Studi Magister Manajemen<br/>
</div>
<div class="form-group">
<input name="prodis[2]" type="checkbox" value="p2">Program Studi Magister Teknik Sipil
<select name="konsentrasi[2]" class="form-control" id="konsentrasi1">
<option value="">Pilih Konsentrasi</option>
<option value="k1">Manajemen Konstruksi</option>
<option value="k2">Transportasi</option>
<option value="k3">Struktur</option>
</select>
</div>
<div class="form-group">
<input name="prodis[3]" type="checkbox" value="p3">Program Studi Magister Ilmu Hukum
<select name="konsentrasi[3]" class="form-control" id="konsentrasi2">
<option value="">Pilih Konsentrasi</option>
<option value="k4">Hukum Bisnis</option>
<option value="k5">Hukum Ketatanegaraan</option>
<option value="k6">Hukum Agraria</option>
<option value="k7">Litigasi</option>
</select>
</div>
<div class="form-group">
<input name="prodis[4]" type="checkbox" value="p4">Program Studi Magister Teknik Informatika
<select name="konsentrasi[4]" class="form-control" id="konsentrasi3">
<option value="">Pilih Konsentrasi</option>
<option value="k8">Soft Computing</option>
<option value="k9">Enterprise Information System</option>
<option value="k10">Mobile Computing</option>
</select>
</div>
<div class="form-group">
<input name="prodis[5]" type="checkbox" value="p5">Program Studi Magister Teknik Arsitektur
<select name="konsentrasi[5]" class="form-control" id="konsentrasi4">
<option value="">Pilih Konsentrasi</option>
<option value="k11">Arsitektur Digital</option>
</select>
At controller end you can just check if index 2 $this->input->post('prodis[2]') then get the value of select box with index 2 $this->input->post('konsentrasi[2]'
You can check it dynamically by keeping code redundancy in your mind. Let me know if you face any issue.
Insert Multiple data using check box or anything on HTML.Just use array "[]".
<input name="checkbox[]" type="checkbox" value="checkbox">
<select name="select[]"></select>
Can also array values like [2],[4],[5] anythings
Thank You
public function insert()
{
//Insert second stage details for employer into database.
$Specilized_category = $this->input->post('spec_cat');
$data=array(
'Specilized_category'=>json_encode(implode(",", $Specilized_category)),
);
$this->db->insert('tbl_employer', $data);

PayPal buttons with versatile functions for Joomla

I have been doing some testing on my organization's donation page (https://www.livingmiraclescenter.org/donations.html). Currently the service that provides us the payment options is First Data; this company is changing the way they work and in order for us to continue using it, we would need to completely overhaul our donations pages across our websites. So, we're investigating how versatile and customizable PayPal buttons are. If you check the link, you see that our current options through First Data are multifaceted. In one simple transaction people may choose a preset amount to donate, pick their own amount, AND choose recurring payment options with the donation amount they chose or choose not to use that option. So, in one payment form we’re able to offer one-time donations as well as recurring ones.
I would like to know if there is any way that PayPal buttons may provide the same versatility. We've been thinking to switch over entirely to PayPal and do away with First Data, but the one thing that's held us back is the little customization that has been offered when making PayPal buttons.
I've played with different code for payment buttons, however been getting error messages ("Invalid Regular period. You must specify valid values for the A3, P3, and T3 parameters for a subscription") each time I actually try out the newly created buttons on the website. The codes I've used are, one:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="SACSLVL35UTAS">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="Donate to My Organization">
<input type="hidden" name="item_number" value="1234">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="src" value="1">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-SubscriptionsBF:btn_subscribeCC_LG.gif:NonHosted">
<table>
<tr><td>When would you like this to Recur?</td></tr><tr><td><select name="t3">
<option value="D">Daily</option>
<option value="M">Monthly</option>
<option value="Y">Yearly</option>
</select> </td></tr>
<tr><td>How many times would you like this to recur? (including this payment)</td></tr><tr><td><select name="srt">
<option value="0">Never End</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select> </td></tr>
<tr><td>Enter Your Donation Amount</td></tr>
<tr><td><input type="text" name="a3" size="4" maxlength="60"></td></tr>
</table>
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to
pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
and two:
<form target="_self" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- If using a Business or Company Logo Graphic, include the "cpp_header_image" variable. -->
<input type="hidden" name="cpp_header_image" value="https://yourwebsite.com/logo.jpg">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<!-- <input type="hidden" name="redirect_cmd" value="_xclick-subscriptions"> -->
<!-- Replace "business" value with your PayPal Email Address or your Merchant Account ID -->
<input type="hidden" name="business" value="your email address">
<input type="hidden" name="item_name" value="Widget Fund Donation">
<input type="hidden" name="item_number" value="WFD-1002">
<input type="hidden" name="no_note" value="1">
<!-- no_shipping value 2 needed to send the free gift -->
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="tax" value="0">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="Add special instructions to the seller:">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHosted">
<!-- Replace value with the web page you want the customer to return to after a successful transaction -->
<input type="hidden" name="return" value="http://www.yourwebsite.com/ThankYou.html">
<!-- Replace value with the web page you want the customer to return to after item cancellation -->
<input type="hidden" name="cancel_return" value="http://www.yourwebsite.com/Cancel.html">
<!-- -->
Enter the amount you would like to donate:
<!-- a3, Required, Regular Subscription Price -->
<input type="text" name="a3" size="4" maxlength="7">
<br><br>
<!-- src, Optional, Recurring Payments, 0 no recur, 1 payments recur -->
<input type="hidden" name="src" value="1">
<!-- -->
Select the length of the desired Billing Cycle:
<!-- p3, Required, Duration based on the value of t3 -->
<select name="p3">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="15">15</option>
<option value="30">30</option>
</select>
<br><br>
<!-- -->
Select how often you would like to Donate:
<!-- t3, Required, Subscription Units D W M Y, -->
<select name="t3">
<option value="D">Day(s)</option>
<option value="W">Week(s)</option>
<option value="M">Month(s)</option>
<option value="Y">Year(s)</option>
</select>
<br><br>
<!-- -->
Select the number of Donation Payments you would like to make:
<br><br>
<!-- srt, Optional, Recurring Times, must be used with src -->
<select name="srt">
<option value="">Until Canceled</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="6">6</option>
<option value="12">12</option>
<option value="18">18</option>
<option value="24">24</option>
<option value="36">36</option>
</select>
<!-- sra, Optional, Reattempt on failure 2 more time, value 0 or 1, if 0 no reattempt -->
<input type="hidden" name="sra" value="1">
<br><br><br>
Thank you for your Donation,
<br><br>
Please Select your Free Gift:
<input type="hidden" name="on0" value="Free Gift Choice">
<select name="os0">
<option value="Solar Calculator">Solar Calculator</option>
<option value="Key Chain Light">Key Chain Light</option>
</select>
<br><br><br>
<!-- -->
<input type="hidden" name="bn" value="PP-SubscriptionsBF:btn_donateCC_LG.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Thank you for any insight, technical help, and wisdom you can provide.
Thanks,
Jutta

Submit two forms sequentially with AJAX

I'm trying to implement the answer from this thread, however I've never used AJAX.
The first form sets a variable required in the second form, once this has been set I'd like it to then redirect as per the second form (so I'm guessing the alert wants to come out of the AJAX?)
After updating with charles babbage's answer the first form Submits.
Thanks for any help, it's greatly appreciated!
<script>
$(document).ready(function() {
$("#subbut").click(function() {
$.post($("#priceselect").attr("action"), $("#priceselect").serialize(),
function() {
$.post($("#globaliris").attr("action"), $("#globaliris").serialize(),
function() {
alert('Both forms submitted');
});
});
});
});
</script>
I've put this in the head with the aim of first submitting
<form name="priceselect" id="priceselect" method="post">
<select name="price" id="mySelect" onchange="document.getElementById('selectedValue').innerHTML = this.value;">
<option value="100">Option 1</option>
<option value="120">Option 2</option>
<option value="115">Option 3</option>
<option value="135">Option 4</option>
<option value="80" >Option 5</option>
</select>
<input value="Continue" id="subbut" type="Submit" />
</form>
which should then
(isset($_POST['price']));
$price = $_POST['price'];
in the same page before redirecting to a 3rd party with the submission of
<form id="globaliris" action="https://redirect.globaliris.com/epage.cgi" method="post" class="select">
<input type=hidden name="MERCHANT_ID" value="<?=$merchantid?>">
<input type=hidden name="ORDER_ID" value="<?=$orderid?>">
<input type=hidden name="CURRENCY" value="<?=$curr?>">
<input type=hidden name="AMOUNT" value="<?=$amount?>">
<input type=hidden name="TIMESTAMP" value="<?=$timestamp?>">
<input type=hidden name="MD5HASH" value="<?=$md5hash?>">
<input type=hidden name="AUTO_SETTLE_FLAG" value="1">
<br />
<br />
</form>
In order to trigger the action that you have specified in the Form tag on click of a button, the button should be of type Submit and also it should be inside your form. The position of Submit button is important.
<input type="submit" value="something" id="something">
Edit(as per your new question)
If you want two form's content to be submitted to one action, just add the serialises as below:
$.post($("#priceselect").attr("action"),$("#priceselect").serialize()+$("#globaliris").serialize() ,
function() {
alert('Both forms submitted');
});
});

Paypal form submission - mobile

Im using below code to submit values in to Paypal and its working.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick" />
<h2 style="font-family:Segoe UI;">Your Email :</h2>
<input type="text" name="business" value="youremailaddress#yourdomain.com" style="width:1000px; height:50px; margin-left:30px;"/>
<br />
<h2 style="font-family:Segoe UI;">Driveway Size :</h2>
<input type="hidden" name="item_name" value="" />
<select id="item_price" name="amount" style="width:1000px; height:50px; margin-left:30px;">
<option value="325">Single $325.00</option>
<option value="375">Double $375.00</option>
<option value="400">2.5 $400.00</option>
<option value="425">Triple $425.00</option>
<option value="450">3.5 $450.00</option>
<option value="475">Quad $475.00</option>
</select>
<br />
<input type="submit" value="Buy!" style="margin-top:30px"/>
</form>
But this is desktop version. is there anyway that I can do same thing for mobiles?
Yes you can. You could for example use System.Net.WebClient to make the post towards the URL you have in the action field of the form.
Or, you can have the above HTML code embedded inside a web-browser control in your application.

Resources