HTML params as array - gaelyk

I use Gaelyk framework on Google AppEngine.
from HTML form I need to get params in exact sequence.
Order of params is very important from my application.
I have HTML Form contans:
<input type="hidden" name="coins" value="50" />
<input type="hidden" name="coins" value="40" />
<input type="hidden" name="coins" value="30" />
<input type="hidden" name="coins" value="20" />
<input type="hidden" name="coins" value="10" />
After form submiting I got array:
// [50,40,30,20,10]
print params.coins
The array is in correct order, but can I depend on this behavior?
or if I need exact order, I need to write:
<input type="hidden" name="coins[0]" value="50" />
<input type="hidden" name="coins[1]" value="40" />
<input type="hidden" name="coins[2]" value="30" />
<input type="hidden" name="coins[3]" value="20" />
<input type="hidden" name="coins[4]" value="10" />
In servlet I got map:
// ['coins[3]':20,'coins[0]':50,'coins[1]':40,'coins[2]':30,'coins[4]':10]
print params
What is the correct solution?
If the second solution is correct, what is the best solution for obtaining Array from Maps?
Thanks a lot
Tom

According to this similar question, so long s the browser sticks to the specification, then the order can be relied upon.
If the browser doesn't stick to the specification obviously, you'll need to go with option[2]

Related

Grails ajax radio buttons

I'm looking to have two radio groups within a single form. When you select a radio button (product type) form the first group, I'd like to update the second group (quantity) and adjust the price using Ajax. Does Grails offer an Ajax radio solution?
<form>
<div>
Product Type
<input type="radio" name="q1" value="1"/>
<input type="radio" name="q1" value="2"/>
<input type="radio" name="q1" value="3"/>
</div>
<div>
Quantity
<input type="radio" name="q2" value="1"/> ${price}
<input type="radio" name="q2" value="2"/> ${price}
<input type="radio" name="q2" value="3"/> ${price}
<input type="radio" name="q2" value="4"/> ${price}
<input type="radio" name="q2" value="5"/> ${price}
</div>
<input type="submit" name="submit" id="submit" />
</form>
Take a look at the g:formRemote tag:
http://grails.github.io/grails-doc/2.1.0/ref/Tags/formRemote.html

Conditional Statement Hacks - IE8 and none IE8

Is anyone able to assist me before I smash my head on the wall?
I am trying to get this form to work:
<form action="" method="post" name="login_form">
<!--[if !IE]>-->
<input type="text" id="emailcust" name="username" class="custbox" value="Email Address" />
<input type="text" id="passcust" name="password" class="custbox" value="Password" />
<p>NON INTERNET EXPLORER!</p>
<!--<[endif]-->
<!--[if IE 8]>
<input type="text" id="emailcust2" name="username" class="custbox" value="" />
<input type="password" id="passcust2" name="password" class="custbox" value="" />
<p>INTERNET EXPLORER!</p>
<![endif]-->
I OFFICIALLY HATE IE!
Modern browsers appear to be picking up the first IF section and ignoring the latter (as per my want), but IE8 is ignoring both IF sections.
SOLUTION
It seems that the entire form has to be included for each if statement. Therefore within the following works:
<!--[if !IE]>-->
<div id="whatever">
<form action="" method="post" name="login_form">
<input type="text" id="emailcust" name="username" class="custbox" value="Email Address" />
<input type="text" id="passcust" name="password" class="custbox" value="Password" />
<p>NON INTERNET EXPLORER!</p>
<input type="submit" class="cust_submit" value="Login" />
</form>
</div>
<!--<[endif]-->
<!--[if IE 8]>
<div id="whatever">
<form action="" method="post" name="login_form">
<input type="text" id="emailcust2" name="username" class="custbox" value="" />
<input type="password" id="passcust2" name="password" class="custbox" value="" />
<p>INTERNET EXPLORER!</p>
<input type="submit" class="cust_submit" value="Login" />
</form>
</div>
<![endif]-->

How can I validate that a radio button was selected using cfform built-in validation?

Say I have a simple cfform that looks like this:
<cfform id="fruitForm" method="post" action="">
<cfinput type="radio" name="fruit" id="fruit_apple" value="Apple" /><label for="fruit_apple">Apple</label><br />
<cfinput type="radio" name="fruit" id="fruit_orange" value="Orange" /><label for="fruit_orange">Orange</label><br />
<cfinput type="radio" name="fruit" id="fruit_pear" value="Pear" /><label for="fruit_pear">Pear</label><br />
<cfinput type="submit" name="submitFruit" id="submitFruit" value="Submit" />
</cfform>
How can I use the built-in cfform validation to ensure that at least one radio button in this group is selected? I've tried adding a validate="required" to each of the radio buttons but it doesn't work. Is there any simple way to "require" one of the buttons to be selected using cfform validation?
Do yourself a favor and don't use cfform for validation. Write your own server and client side validation, but according to the cfinput documentation if you add a required="true" attribute to each radio button ColdFusion will do the client side validation for you.
Note: The user can bypass this validation and still submit a form without checking a radio button. You need to have server side validation as well.
<cfform id="fruitForm" method="post" action="">
<cfinput type="radio" name="fruit" id="fruit_apple" value="Apple" required="true" /><label for="fruit_apple">Apple</label><br />
<cfinput type="radio" name="fruit" id="fruit_orange" value="Orange" required="true" /><label for="fruit_orange">Orange</label><br />
<cfinput type="radio" name="fruit" id="fruit_pear" value="Pear" required="true" /><label for="fruit_pear">Pear</label><br />
<cfinput type="submit" name="submitFruit" id="submitFruit" value="Submit" />
</cfform>
This works for me:
<cfform action="abc.cfm" method="post">
<cfinput type="radio" required="yes" message="pick something" name="x" value="1">radio 1
<cfinput type="radio" required="yes" message="pick something" name="x" value="">radio 2
<input type="submit" />
</cfform>
In fact, you don't even need the message attribute. It will still validate.

Programmatically pass a url to an anonymous proxy like http://www.trycatchme.com

I'm using .net httpwebrequest &/or webclient class
How can i Progamatically pass a url to an anonymous proxy like http://www.trycatchme.com and get back a result
<form method="post" action="/index.php">
<input id="address_bar" type="text" name="q" value="http://www." onfocus="this.select()" />
<input id="surf_button" type="image" value="Surf Now" src="images/surfnowbtn.gif" />
<input type="hidden" name="hl[include_form]" value="1" />
<input type="hidden" name="hl[remove_scripts]" value="1" />
<input type="hidden" name="hl[accept_cookies]" value="1" />
<input type="hidden" name="hl[show_images]" value="1" />
<input type="hidden" name="hl[show_referer]" value="1" />
<input type="hidden" name="hl[base64_encode]" value="1" />
<input type="hidden" name="hl[strip_meta]" value="1" />
<input type="hidden" name="hl[session_cookies]" value="1" />
</form>
The HttpWebRequest.Proxy Property might be what you want.

PayPal discount can't make it work

I'm trying to setup a discount for a the whole cart using PayPal + Codeigniter, I got this working withouth the discounts.
As far as I've read the only thing that I would need to do is set a hidden field discount_amount_cart as I saw here
Here is my form:
<form method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr" name="paypal_form">
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="currency_code" value="EUR" />
<input type="hidden" name="business" value="biz_1271300483_biz#xxxx.xx" />
<input type="hidden" name="return" value="http://xxxxxx.com/website/pt/paypal/success/8/4c237a03897e0" />
<input type="hidden" name="cancel_return" value="http://xxxxxxx.com/website/pt/paypal/cancel/8/4c237a03897e0" />
<input type="hidden" name="notify_url" value="http://xxxxxx.com/website/pt/paypal/ipn" />
<input type="hidden" name="custom" value="" />
<input type="hidden" name="no_shipping" value="1" />
<input type="hidden" name="cpp_header_image" value="http://xxxxxxxxx.com/images/logo.png" />
<input type="hidden" name="image_url" value="http://xxxxxxxxx.com/images/logo.png" />
<input type="hidden" name="invoice" value="4c237a03897e0" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="discount_rate_cart" value="10.00" />
<input type="hidden" name="first_name" value="Foo Bar" />
<input type="hidden" name="city" value="xxxx" />
<input type="hidden" name="address1" value="xxxxxx" />
<input type="hidden" name="zip" value="xxxxxx" />
<input type="hidden" name="lc" value="pt" />
<input type="hidden" name="email" value="xxxxx#xxx.pt" />
<input type="hidden" name="country" value="PT" />
<input type="hidden" name="item_name_1" value="Cloud Hosting WIN Business 25GB" />
<input type="hidden" name="item_number_1" value="200.00000003" />
<input type="hidden" name="amount_1" value="156" />
<input type="hidden" name="quantity_1" value="1" />
<input type="hidden" name="tax_rate_1" value="20" />
<p><input type="submit" name="pp_submit" value="Pagar" class="submit" /></p>
</form>
But when I "post" the fields the discount line won't appear, do I need to activate something in the merchant account, am I doing something wrong?
Cheers
Got it,
From the PayPal documentation:
When you use consolidated discount amounts, you should specify a consolidated tax value in tax_cart. If you do not specify a tax value and your profile specifies a tax rate, your profile tax rate is applied after the consolidated discount value is applied.
So I need to define my "global" tax amount for the cart with tax_cart.
The name of your discount input appears to be wrong:
<input type="hidden" name="discount_rate_cart" value="10.00" />
should be:
<input type="hidden" name="discount_amount_cart" value="10" />
Use discount_amount_cart to charge a
single discount amount for the entire
cart.
Use discount_amount_x to set a
discount amount associated with item x
Use discount_rate_cart to charge a
single discount percentage for the
entire cart.
discount_rate_cart - Applies to
entire cart however, this variable
will only work with the "Upload"
Method. Not the standard Add to Cart
variables.
This variable will be ignored if you
are including any individual sales tax
amount or rate in your upload method
code. This is because the sales tax
needs to be calculated after the
discount is applied to your items
therefore, the discount is applied to
the item Subtotal, not the Total.
Note, If you just using the standard
Add to Cart buttons, there no Discount
variables for the entire cart. as
they "only" apply a Discount to an
individual item.

Resources