Different POST Options for form, then passing data - php

Currently, I am working on a site that uses PayPal to Checkout. I would like to enable stripe, as well, so there can be a "checkout with stripe" button at the bottom of the form.
<form method="POST" id="form1" >
<select id="udidSelect" onchange="udidPrice(this)">
<option value="invalid" disabled="disabled">Choose Package</option>
<option value="udid">UDID Registration</option>
<option value="profile">UDID Registration & Free Unlimited Apps (Provisioning Profile)</option>
</select><br />
<br />
<input type="text" placeholder="Name" /><br />
<br />
<input type="email" placeholder="Email" /><br />
<br />
<input type="text" placeholder="UDID (40 Characters Long)" name="os0" /> <br />
<input type="hidden" name="on0" value="UDID">
<br />
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" id="udidbuttonID" value="9PSTCESRS3FSG">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" value="PayPal" onclick="submitForm('https://www.paypal.com/cgi-bin/webscr')" style="float:right;">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Now I would like to have a PayPal Button at the bottom of the form and a Stripe button at the bottom of the form. And if the user clicked the stripe button, it would take them to the next page and PASS ALONG the information entered in this page. I am not sure how to do this, and I am also not sure how to have different post options for the form. (Sorry I am kind of new to this.)
On the stripe checkout page, also, how would I request that information that was passed along, from the previous form. Would it just be something like this?
<input type="hidden" name="somedata" value="<?php echo $_POST['somedata']; ?>" />
<input type="hidden" name="otherdata" value="<?php echo $_POST['otherdata']; ?>" />

If I'm reading your question correctly, you want the form to go to different pages depending on whether the user clicked on Stripe or Paypal.
You can use JavaScript/jQuery to change the action attribute of the form:
<!--HTML-->
<button onClick="setFormAction('stripe')">Stripe</button>
<button onClick="setFormAction('paypal')">Paypal</button>
//Javascript
function setFormAction(which) {
if (which == 'stripe') {
//Change 'stripe.php' to the proper URL
document.getElementById('form1').action = 'stripe.php';
} else {
document.getElementById('form1').action = 'paypal.php'; //Change this also
}
//Finally, submit the form
document.getElementById('form1').submit();
}
Or, more understandably, the jQuery solution:
<!--HTML-->
<button id="stripe">Stripe</button>
<button id="paypal">Paypal</button>
//Javascript
$('button#stripe').click(function() {
$('form#form1')
.attr('action', 'stripe.php') //Change to proper stripe URL
.submit();
});
$('button#paypal').click(function() {
$('form#form1')
.attr('action', 'paypal.php') //Change to paypal URL
.submit();
});
On the next page, you do exactly what you said previously:
<input type="hidden" name="somedata" val="<?php echo $somedata; ?>" />
Always sanitize user-inputted values before echoing them on the page (therefore the variable $somedata rather than $_POST['somedata'].
An alternative to hidden input fields is sessions. Much easier to handle once you get the hang of it.

Add another line as:
test.php is the page where you want to post this form
<input type="button" border="0" value="Pay with Stripe" onclick="submitForm('test.php')">
in test.php you can get the values like this:
<input type="hidden" name="test" value="<?php echo $_REQUEST['test'] ?>">

Related

Hide url parameters in php

I am not getting the way to hide the values that are passing through url in php. Clicking over a link , page redirects plus parameters are also shown on url .For eg:-
/localhost/oops/edit.php?id='1'
but I want to hide the data after ? while redirecting.
Your only option is to use a form and POST if the page your are logging into is controlled by a 3rd party. Try to use hidden input type while login. Maybe that'll work for you. For example:
<form action="http://mywebsite.com/login.aspx" method="post">
<input type="hidden" name="check" value="uid" />
<input type="hidden" name="user" value="adam" />
<input type="hidden" name="pass" value="pass1234" />
<input type="hidden" name="profile" value="profile" />
<input type="hidden" name="defaultdatabaseb" value="database" />
<input type="submit" value="submit" />
</form>

Form validation - Minimum number value

Could someone offer me some advice as to form validation that restricts entry of a number below 5. I have got a donation form, simply an amount input field and a submit button to paypal.
What form validation shall I use to restrict submission of the form if the amount value is below 5 (for £5.00).
The form is below:
<form target="paypal" id="donate" action="https://www.paypal.com/cgi-bin/webscr" method="post" >
<div class="span6 text-center">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="SECRET-ID">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="item_name" value="General">
<input type="hidden" name="item_number" value="GEN">
<div class="input-prepend input-append">
<span class="add-on">£</span>
<input class="span12" name="amount" value="5" placeholder="Enter Donation Amount" id="appendedPrependedInput" size="20" type="text">
<input type="hidden" name="currency_code" value="GBP">
<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="no_shipping" value="2">
<input type="hidden" name="add" value="1">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest">
</div>
</div>
<div class="span6 text-center">
<div class="controls">
<a id="buynow" class="btn btn-danger" href="#" rel="nofollow" onclick="document.getElementById('donate').submit(); return false;">
<span style="">Donate via PayPal!</span></a>
<noscript>
<style>#buynow { display: none; } #page_theme #donate input { display: inline; }</style>
<input type="submit" class="btn btn-danger" value="Donate via PayPal!">
</noscript>
</div>
</div>
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
In your case I would use parsley.js
So to use parsley on your form (after you install it), add this data attribute to your form:
data-validate="parsley"
It should look like this:
<form target="paypal" id="donate" action="https://www.paypal.com/cgi-bin/webscr" data-validate="parsley" method="post" >
And for your input add the following data attribute (read the documentation for more validation rules):
data-min="6"
So it should look like:
<input class="span12" name="amount" value="5" placeholder="Enter Donation Amount" data-min="6" id="appendedPrependedInput" size="20" type="text">
And that's it.
There's a lot of them, but since most people are already using JQuery and they want to use client-side validations, I would use Jquery Validation. Remember for back-end, you have to use your own PHP, C# or whatever validation that you need. If you aren't using JQuery, I would use this
If you want a very simple frontend solution, you can use a Javascript function attached to the onblur event for the input element to test the value of the input:
<input type="text" name="amount" onblur="checkValue(this)" />
In the attached function, you pass the element and check the value of that element:
function checkValue(element){
if(element.value < 5){
alert('The minimum donation is 5.00!');
// clear value, display message, etc.
}
}
This function will be triggered whenever the cursor leaves the input field. A simple alert may be all you need. You may also want to add additional check to make sure the element input is actually a number and not a string. It's best to assume the end-user will not know how to use the form.
Please note that this is only a frontend solution and all submitted forms should be validated on the server-side language of choice (e.g. PHP). You should not accept this Javascript validation as a reliable validator when saving data.

Button onClick not redirecting

SO..i have this project that is totally backwards, but basically i have to give a working form that adds a quantity of some item_ID and then redirects to the cart page of a framework i use.
Of course rather than me just skin my framework, and customize its functionality for him. This guy has some hacked up php pages that he "wrote himself" that he insists on hard coding forms into.
anyways, i have a form that submits to my cart.php in the action
<form name="orderform" method="post" action="http://s429036015.onlinehome.us/cart.php" id="orderform">
<input type="hidden" name="mode" value="add" />
<input type="hidden" name="productid" value="140" />
<input type="hidden" name="cat" value="" />
<input type="hidden" name="page" value="" />
Qty <input type="text" id="product_avail" name="amount" />
<button class="button main-button list-button add-to-cart-button" type="submit" title="" onClick="location.href='cart.php'">
<span class="button-right"><span class="button-left">Add to cart</span></span>
</button>
</form>
The above form submits properly, with the quantity entered, session stores the data and the items are in the cart just fine....however, that onclick event on the <button> doesn't work!
I've even tried this
<button class="button main-button list-button add-to-cart-button" type="submit" title="" onClick="GotoPage(); return:true;">
with this script ahead of the form
<script type="text/javascript">
function GotoPage() {
window.location = "http://s429036015.onlinehome.us/cart.php";
}
</script>
anyone have any ideas? driving me nuts...
In PHP, after you process data from form, try this:
header('location: http://s429036015.onlinehome.us/cart.php');

Returning custom input data from PayPal

I created a basic purchase script where a user enters their desired username and password, then they can purchase the membership on my website. But, when it goes to the return page, the values Username and Password don't show in the url. Here is the code:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="CKQH4CYEMYLWW">
<center>
<span id="msgbox" style="display:none;"></span>
<br><br>
<input type="text" id="rusername" name="rusername" placeholder="Desired Username" class="usernamelogin">
<br><br>
<input type="password" id="rpassword" name="rpassword" placeholder="Desired Password" class="passwordlogin">
<br><br>
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_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_GB/i/scr/pixel.gif" width="1" height="1">
</form>
set cookie variable for each input variable and pass the data accordingly . . and on return from paypal you can simply check the cookie variable and pass the data in the individual input accordingly ..
Paypal Standard gives one variable 'custom' for passing custom data
so you can have a way to pass those values using this variable and getting back.
eg. you can seperate the values using | and get back
<input type="hidden" id="custom" name="custom" value="username|password"/>
you can set the values when your form is going to be submitted
when success page comes you can get the values
list($username,$password) = explode('|',$_POST['custom']);

Include results of a Paypal button generator in post without copy/paste

I own a locally exclusive trade form for people to sell items to others locally. I want to have an option to include a Paypal "Buy Now" button in new posts but I'm stuck at how to include the button in a new post without having the user manually copy/past the HTML. I have made a simple Paypal button generator with a checkbox and jQuery to display form fields if checkbox is checked. Here it is on jsfiddle
HTML
<form>
<input type="checkbox" id="checkme" /> Add a "Buy Now" Paypal button
</form>
<div id="extra">
<form action="includes/paypal_button.php" method="post">
Paypal account email: <input type="text" name="email" /><br />
Short item description: <input type="text" name="item" /><br />
Price for item (all amounts are in USD): <input type="text" name="amount" /><br />
Tax amout: <input type="text" name="tax" /><br />
Shipping and handling: <input type="text" name="shipping" />
<input type=submit value="Create Paypal button!">
</form>
</div>
jQuery
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//Hide div w/id extra
$("#extra").css("display","none");
// Add onclick handler to checkbox w/id checkme
$("#checkme").click(function(){
// If checked
if ($("#checkme").is(":checked"))
{
//show the hidden div
$("#extra").show("fast");
}
else
{
//otherwise, hide it
$("#extra").hide("fast");
}
});
});
</script>
The controller form is in a separate php script, paypal_button.php
HTML
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo htmlspecialchars(($_POST["email"]))?>" >
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="<?php echo htmlspecialchars(($_POST["item"]))?>">
<input type="hidden" name="amount" value="<?php echo htmlspecialchars(($_POST["amount"]))?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="tax_rate" value="<?php echo htmlspecialchars(($_POST["tax"]))?>">
<input type="hidden" name="shipping" value="<?php echo htmlspecialchars(($_POST["shipping"]))?>">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_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>
So should I include the controller(the button to print) in a php if statement that will print the button in new form posts? It would be highly appreciative if someone could point me in the right direction.
Thanks in advance

Categories