ASP.NET MVC 2 Input ID - asp.net-mvc-2

Adding the following to my view:
<input type="text" runat="server" id="newBookingRef" name="newBookingRef" />
Results in the following HTML:
<input type="text" id="MainContent_newBookingRef" name="ctl00$MainContent$newBookingRef">
If I use the helper method Html.Textbox, the ID is generated as I would expect "newBookingRef".
How can I stop it prefixing the ID on standard input controls with the content placeholder id? I tried playing with the ClientIdMode of the content placeholder but this didn't seem to help.
Thanks,
Ben

Remove the runat="server" attribute.

Related

What is the best locator for the below tag?

Below is the tag for a password field in Login form.
Our guys used the same class name for EMail field also. Hence I cannot use className for password to locate it in protractor, since xpath and css(id design changes) are not reliable, what is the best option for me?
Tag for Email field:
<input class="native-input sc-ion-input-md" aria-labelledby="ion-input-0-lbl" autocapitalize="off" autocomplete="off" autocorrect="off" name="ion-input-0" placeholder="" required="" type="email">
Tag for password field:
<input class="native-input sc-ion-input-md" aria-labelledby="ion-input-5-lbl" autocapitalize="off" autocomplete="off" autocorrect="off" name="ion-input-5" placeholder="" required="" type="password">
For submit button:
<ion-button _ngcontent-rbh-c129="" type="submit" color="loginbutton ion-margin" class="ion-color ion-color-loginbutton ion-margin md button button-solid ion-activatable ion-focusable hydrated">Login</ion-button>
I don’t suggest you to go with ion-input properties since it’s Ionic related properties generated during the build process and it can be dynamic.
Use type instead since it is:
Obvious
Static
input[type="email"]
And
input[type="password"]
After some time you will have hard time understanding your own code and trying to recall what ion-input-0
refers to.
By css:
element(By.css('input[name="ion-input-0"][type="email"]')),
and:
element(By.css('input[name="ion-input-5"][type="password"]')),

Inserting data into a database using forms in web2py

I want to store my data in a database using forms.
How can I do it without using SQLFORM
like in php we use $var = $_POST['var_form']
I created a table in modul file called Produit
db.define_table('Produit',`enter code here`
Field('Nom', requires = IS_NOT_EMPTY()),
Field('Poid', 'float', requires = IS_NOT_EMPTY()),
Field('Prix', 'float', requires = IS_NOT_EMPTY()),
Field('Expiration', 'datetime'),
auth.signature)
And created a form like
{{extend 'layout.html'}}
<form action="create" method=post>
<fieldset>
<legend><h1><center><em>Ajouter un produit</em></center></h1></legend>
Nom:<br>
<input type="text" name="nom" required/>
<br>
Poid:<br>
<input type="text" name="poid" required/>
<br>
Prix:<br>
<input type="text" name="prix" required/>
<br>
Date d'expiration:<br>
<input type="date" name="exp" required/>
<br>
<br><br>
<input type="submit" value="Ajouter">
Use URL helper to specify action of the form.
<form action="{{=URL('create')}}" method=post>
...
</form>
Then in create controller, you can access submitted values using request.vars
db.Produit.insert(Nom=request.vars.nom, Poid=request.vars.poid,
Prix=request.vars.prix, Expiration=request.vars.exp)
This answer has the right idea, but to make things a little easier, you should use HTML field names that exactly match the database table field names. In that case, you can simplify the insert to:
db.Produit.insert(**db.Produit._filter_fields(request.post_vars))
Beware, though, that your manual approach lacks any protection against CSRF attacks (which the web2py form system would provide). As an alternative, note that you can still use SQLFORM even if you want to generate a custom form layout in the view. This approach is covered in the documentation here and here.

How to render input inside label - using zend form

As title says, how can i generate a form using zend form having input inside label?
Something like
<label class="checkbox" for="persistent">
<input type="checkbox" value="" id="persistent" data-toggle="checkbox">
Remember Me
</label>
Thanks!
You can likely add a decorator to your input field.

How to handle Zend SubForms when the number of each is unknown

I have a 'customer' form which has a section called 'contacts'. To start with this contacts section will contain the following elements..
<input type="text" name="contacts[0][fname]" />
<input type="text" name="contacts[0][sname]" />
But the user may want to add another contact which will duplicate the elements with javascript to produce the following:
<input type="text" name="contacts[0][fname]" />
<input type="text" name="contacts[0][sname]" />
<br />
<input type="text" name="contacts[1][fname]" />
<input type="text" name="contacts[1][sname]" />
I know how to produce the first set of elements, however if the form gets submitted and there are errors, how can i ensure that the correct number of 'contacts' elements get rendered?
Ive never had to do this with Zend_Form but i have done it with Symfony 1.4's sfForm which has a similar API and theory of operation. Based on that the basic process is:
In the parent forms constructor intialize some default number of subforms. Youll want to separate out the logic for actually creating and embedding n subforms into a separate method(s). Ill refer to this as the method emebedContacts($count = 1)
Override the isValid and setDefaults methods on the parent form so that they detect the number of subforms in the $data arguments passed to them and then call embedContacts before calling parent::isValid() or parent::setDefaults().
Hope that helps.

Submit a JSF form using GET

How do I submit a form to the same page and use GET parameters?
JSF page contents:
<f:metadata>
<f:viewParam name="item1" value="#{bean.item1}"/>
<f:viewParam name="item2" value="#{bean.item2}"/>
</f:metadata>
...
<h:form>
<h:inputText value="#{bean.item1}"/>
<h:inputText value="#{bean.item2}"/>
<h:button value="Submit" >
<f:param name="item1" value="#{bean.item1}"/>
<f:param name="item2" value="#{bean.item2}"/>
</h:button>
</h:form>
If I request the page: form.jsf?item1=foo&item2=bar, it will populate the text fields, but the form submission to itself doesn't seem to work.
Replace <h:button> by
<h:commandButton value="Submit" action="form?faces-redirect=true&includeViewParams=true"/>
It effectively fires a PRG (Post-Redirect-Get) which will include the <f:viewParam> params in the query string. Noted should be that the target page must have exactly same <f:viewParam>.
Another solution is to use a plain HTML <form> instead of <h:form>, give the input elements an id matching the parameter name and use a plain <input type="submit">. You can of course also use plain HTML <input type="text"> here.
<form>
<h:inputText id="item1" value="#{bean.item1}"/>
<h:inputText id="item2" value="#{bean.item2}"/>
<input type="submit" value="Submit" />
</form>
You should still keep the <f:viewParam> in both sides. You only need to realize that conversion/validation couldn't be done in this form, they have to be performed via the <f:viewParam> on the target page.
See also:
What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?
You could also register a NavigationHandler that handles a keyword like 'self' and redirects to the the current view and adds the necessary query parameters.