How can I validate that a radio button was selected using cfform built-in validation? - 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.

Related

C# Launching Yodlee FastLink

I'm doing a project to launch yodlee fastlink. I was able to get the token and userSession and trying the below codes. I'm only getting "Cannot POST resource". I'm trying to find a more detailed/simpler documentation. Any help would be appreciated.
<form action="https://node.developer.yodlee.com/authenticate/restserver" method="post" name="rsessionPost" id="rsessionPost" target="yodleeIframe">
<input style="visibility: hidden" type="text" name="rsession" placeholder="rsession" value="08312016_0:149676f79ace306255a2c7827f9db590ccabd7350ad5d952f31fc503675bba9ec522728c213a9e5c3e98bd8ceff795c88f9a6f80040a68ce325ae54759f6e504" id="rsession" /><br />
<input style="visibility: hidden" type="text" name="app" placeholder="FinappId" value="10003600" id="finappId" /><br />
<input style="visibility: hidden" type="text" name="redirectReq" placeholder="true/false" value="true" /><br />
<input style="visibility: hidden" type="text" name="token" placeholder="token" value="e59f51a169f52925cd715a945630686e59667d2d1fae511fd50b4e292a8e7342" id="token" /><br />
<input type="submit" name="submit" />
</form>
It seems like there is a forward slash '/' missing at the end of the URL.
Please put it there and submit the form you should be able to access Fastlink.
"https://node.developer.yodlee.com/authenticate/restserver/"

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

bind radiobutton in mvc

Radio Button checked item should be true based on entry.isalbum value. Below is my View code..
#foreach(abc.Models.ddt entry in entrydetails)
{
#if(entry.isAlbum=="Album")
{
<input type="radio" id="c" name="isAlbum" checked="checked" value="Album" />
<label style="margin-right:10px" for="c"><span></span>Album</label>
}
<input type="radio" id="c1" name="isAlbum" value="Movies" />
<label style="margin-right:10px" for="c1"><span></span>Movies</label>
<input type="radio" id="c2" name="isAlbum" value="Single" />
<label style="margin-right:10px" for="c2"><span></span>Single</label>
</div>
}
}
foreach loop contain value stroed in database corresponding to Album, Movies or Single.
radio button checked should be true based on entry.isAlbum vale. How can we do this, please help to us? I have three radiobutton mention in above code. Radio Button checked will be true based on entry.Isalbum vale. Please help me
Try this:
<input type="radio" id="c" name="isAlbum" #if(entry.isAlbum=="Album"){<text>checked="checked"</text>} value="Album" />
<input type="radio" id="c1" name="isAlbum" #if(entry.isAlbum=="Movies"){<text>checked="checked"</text>} value="Movies" />
<input type="radio" id="c2" name="isAlbum" #if(entry.isAlbum=="Single"){<text>checked="checked"</text>} value="Single" />

Validation of prefilled contact form fields in Magento fails

My Magento contact form has the field names prefilled, not labelled.
<input name="name" id="name" value="Name" class="required-entry input-text" type="text" />
Since the field is prefilled, the validation "required-entry" fails.
Is there a not-so-dirty way to get the validation working with prefilled values?
just try to use. Placeholder to make prefilled text
<form action="demo_form.asp">
<input type="text" name="fname" placeholder="First name"><br>
<input type="text" name="lname" placeholder="Last name"><br>
<input type="submit" value="Submit">
</form>
that would sure help you.

radio button auto check based on condition using jstl

i need to set the radio button as checked based on the value present in the request. below is the code i used in my JSP
<input type="radio" name="status" id="status" value="Active" checked="<c:if test="${posting.postingStatus eq 'Active'}">checked</c:if>">
Active
<input type="radio" name="status" id="status" value="Closed" checked="<c:if test="${posting.postingStatus eq 'Closed'}">checked</c:if>">
Closed
I am getting the radiobutton along with the text 'checked/>Active' and another radio button with text 'checked/>Closed'
i tried using another set of code
<c:choose>
<c:when test="${posting.postingStatus eq 'Active'}">
<input type="radio" name="status" id="status" value="Active" checked="checked"/>
Active
<input type="radio" name="status" id="status" value="Closed"/>
Closed
</c:when>
<c:otherwise>
<input type="radio" name="status" id="status" value="Active" />
Active
<input type="radio" name="status" id="status" value="Closed" checked="checked"/>
Closed
</c:otherwise>
i am getting double times with improper result.
can anyone help me with this?
Try this way:
<input type="radio" name="status" id="status"
value="Active" ${posting.postingStatus=='Active'?'checked':''}>

Resources