EzDevInfo.com

forms interview questions

Top forms frequently asked interview questions

Google Chrome form autofill and its yellow background

I have design problem with Google Chrome and its form autofill function. If Chrome remembers some login/password it changes a background color to a yellow one.

Here are some screenshots:

alt text alt text

How to remove that background or just disable this autofill ?


Source: (StackOverflow)

What is the _snowman param in Ruby on Rails 3 forms for?

In Ruby on Rails 3 (currently using Beta 4), I see that when using the form_tag or form_for helpers there is a hidden field named _snowman with the value of ☃ (Unicode \x9731) showing up.

So, what is this for?


Source: (StackOverflow)

Advertisements

Prevent Users from submitting form by hitting enter

I have a survey on a website, and there seems to be some issues with the users hitting enter (I don't know why) and accidentally submitting the survey (form) without clicking the submit button. Is there a way to prevent this? I'm using html, php 5.2.9, and jquery on the survey.


Source: (StackOverflow)

Twitter Bootstrap Form File Element upload button

Why isn't there a fancy file element upload button for twitter bootstrap? it would be sweet if the blue primary button was implemented for the upload button. Is it even possible to finesse the upload button using CSS (seems like a native browser element that cant be manipulated)


Source: (StackOverflow)

CSS selector for text input fields?

How can I target input fields of type 'text' using CSS selectors?


Source: (StackOverflow)

Get checkbox value in jQuery

How can I get a checkbox's value in jQuery?


Source: (StackOverflow)

Check if option is selected with jQuery, if not select a default

Using jQuery, how do you check if there is an option selected in a select menu, and if not, assign one of the options as selected.

(The select is generated with a maze of PHP functions in an app I just inherited, so this is a quick fix while I get my head around those :)


Source: (StackOverflow)

When should I use GET or POST method? What's the difference between them?

I think the title is my question. I would like to know what's the difference when using GET or POST method. Which one is more secure? What are dis/advantages of each of them?

I also found similar question to this one here...


Source: (StackOverflow)

Disabled form inputs do not appear in the request

I have some disabled inputs in a form and I want to send them to a server, but Chrome excludes them from the request.

Is there any workaround for this without adding a hidden field?

<form action="/Media/Add">
    <input type="hidden" name="Id" value="123" />

    <!-- this does not appear in request -->
    <input type="textbox" name="Percentage" value="100" disabled="disabled" /> 

</form>

Source: (StackOverflow)

Submitting a form by pressing enter without a submit button

Well I am trying to submit a form by pressing enter but not displaying a submit button. I don't want to get into JavaScript if possible since I want everything to work on all browsers (the only JS way I know is with events).

Right now the form looks like this:

<form name="loginBox" target="#here" method="post">
    <input name="username" type="text" /><br />
    <input name="password" type="password" />
    <input type="submit" style="height: 0px; width: 0px; border: none; padding: 0px;" hidefocus="true" />
</form>

Which works pretty well. The submit button works when the user presses enter, and the button doesn't show in Firefox, IE, Safari, Opera and Chrome. However, I still don't like the solution since it is hard to know whether it will work on all platforms with all browsers.

Can anyone suggest a better method? Or is this about as good as it gets?


Source: (StackOverflow)

In a django form, How to make a field readonly (or disabled) so that it cannot be edited?

In a django form, how do I make a field read-only (or disabled)?

When the form is being used to create a new entry, all fields should be enabled - but when the record is in update mode some fields need to be read-only.

For example, when creating a new Item model, all fields must be editable, but while updating the record, is there a way to disable sku field so that it is visible but cannot be edited?

class Item(models.Model):
    sku = models.CharField(max_length=50)
    description = models.CharField(max_length=200)    
    added_by = models.ForeignKey(User)    


class ItemForm(ModelForm):
    class Meta:
        model = Item
        exclude = ('added_by')      

def new_item_view(request):     
    if request.method == 'POST':
        form = ItemForm(request.POST)
        #validate and save
    else:
            form = ItemForm()       
    #render the view

Can class ItemForm be reused? What changes would be required in ItemForm or Item model class? Would I need to write another class, "ItemUpdateForm", for updating the item?

def update_item_view(request):      
    if request.method == 'POST':
        form = ItemUpdateForm(request.POST)
        #validate and save
    else:
        form = ItemUpdateForm()

Source: (StackOverflow)

Is it a good practice to use an empty URL for a HTML form's action attribute? (action="")

I am wondering if anyone can give a "best practices" response to using blank HTML form actions to post back to the current page.

There is a post asking what a blank HTML form action does here and some pages like this one suggest it is fine but I'd like to know what people think.


Source: (StackOverflow)

Jquery - Create hidden form element on the fly

What is the simplest way to dynamically create a hidden input form field using jquery?


Source: (StackOverflow)

What characters are allowed in email address?

I'm not asking about full email validation.

I just want to know what are allowed characters in user-name and server parts of email address. This may be oversimplified, maybe email adresses can take other forms, but I don't care. I'm asking about only this simple form: user-name@server (e.g. wild.wezyr@best-server-ever.com) and allowed characters in both parts.


Source: (StackOverflow)

How to handle checkboxes in ASP.NET MVC forms?

Caution: This question is over five years old!

Your best option is to search for newer questions, or to search the answers below looking for your specific version of MVC, as many answers here are obsolete now.

If you do find an answer that works for your version, please make sure the answer contains the version of MVC you are using.
(The original question starts below)


This seems a bit bizarre to me, but as far as I can tell, this is how you do it.

I have a collection of objects, and I want users to select one or more of them. This says to me "form with checkboxes." My objects don't have any concept of "selected" (they're rudimentary POCO's formed by deserializing a wcf call). So, I do the following:

public class SampleObject{
  public Guid Id {get;set;}
  public string Name {get;set;}
}

In the view:

<%
    using (Html.BeginForm())
    {
%>
  <%foreach (var o in ViewData.Model) {%>
    <%=Html.CheckBox(o.Id)%>&nbsp;<%= o.Name %>
  <%}%>
  <input type="submit" value="Submit" />
<%}%>

And, in the controller, this is the only way I can see to figure out what objects the user checked:

public ActionResult ThisLooksWeird(FormCollection result)
{
  var winnars = from x in result.AllKeys
          where result[x] != "false"
          select x;
  // yadda
}

Its freaky in the first place, and secondly, for those items the user checked, the FormCollection lists its value as "true false" rather than just true.

Obviously, I'm missing something. I think this is built with the idea in mind that the objects in the collection that are acted upon within the html form are updated using UpdateModel() or through a ModelBinder.

But my objects aren't set up for this; does that mean that this is the only way? Is there another way to do it?


Source: (StackOverflow)