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.
Related
I am wondering if it's possible to make a script in Python that parses the authencity token from a fom and get its correspondent link.
What would be the best approach to do so?
I am attaching a piece of the HTML source code as reference.
<form id="take_file_form" class="edit_document ng-pristine no-valid" data-dynamic-pricing-activated="true" data-dynamic-pricing-url="https://
api.textmaster.com/privateldocuments/Sd9208496831676601735397/
dynamic _pricing- data-dynamic-pricing.refresh-interval-in-sec="128"
action="/authors/tasksJ5d920849683I6700e1735397/start" accept-charset="UTF-8" method="post">
<input name="utf8" type="hidden" value="✓">
<input type="hidden" name="_method" value="patch">
<input type="hidden" name="authenticity_token" value="Sall2FcgxufyNBTFw4sUlliallY09+EljvfKEFdgzijsullgv+2Q811aggs7BovNytlFShGxjincdOrga78=="> <input id="document_dynamic_author_word_count" type="hidden" name="document[dynamic_author_word_count]" value="8"> <input type="submit" name="commit" value="Pegue essa tarefa" class=
"anim btn blue-hg action-btn"> == $0
Thanks!
I am using PayPal Standard HTML form, and after the user has completed the transaction he/she is taken to the return url. I want to be able to identify the user email, the order number, and other information that may be available using php. In other words, I want to use the GET method to retrieve the variables in the URL
This is a recurring payment (subscription), and below is the html code.
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="info#merchant.com">
<input type="hidden" name="return" value="test">
<!-- Specify a Subscribe button. -->
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<!-- Identify the subscription. -->
<input id="paymentName" type="hidden" name="item_name" value="test">
<input type="hidden" name="item_number" value="1234">
<!-- Set the terms of the regular subscription. -->
<input type="hidden" name="currency_code" value="CAD">
<input id="paymentPrice" type="hidden" name="a3" value="0.01">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<!-- Set recurring payments until canceled. -->
<input type="hidden" name="src" value="1">
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" style="width:240px; border: none; height:50px"
src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-large.png"
alt="PayPal - The safer, easier way to pay online">
</form>
As others already commented. You should use Instant Payment Notification (IPN).
documentation
Basically you need to set in your html form a field called "notifyurl", something like this:
<input type="hidden" name="notifyurl"alue="http://www.example.com/ipn_listener.php">
For the ipn_listener.php you have sample code here (if PHP):
Sample code for PHP
If you need to attach some specif information to the payment you can also use the paremeter "custom", and read it back in you ipn listener.
I am having problems with my submit button. It's supposed to take them to the Paypals payment page once clicked on but absolutely nothing happens when I click on it.
You can see it live here: http://cashski.com/buy-instagram-followers.php
Click on "View Pack" for the first pack and then on the green "Checkout" button.
Here is my HTML code for the button:
<form name="_xclick" action="https://www.paypal.com/us/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="kottish94#hotmail.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="2 000 Instagram Followers">
<input type="hidden" name="amount" value="9.00">
<input type="hidden" name="on1" value="Instagram Username" maxlength="200">
<input type="text" name="os1" placeholder="Example: http://instagram.com/YOURUSERNAME" required>
<input type="button" border="0" name="submit" value="Checkout" alt="Buy Instagram Followers">
</form>
Use
input type="submit"
instead of
input type="button"
and Replace CSS TO Submit button instead of button. Your Problem will solve
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'] ?>">
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