I have umbraco v7.2.8
I have some template code like this
<input type="hidden" name="search" value=#Request.QueryString["search"]>
this works well to put the query string value for search string into the hidden field so when i click the submit on the surrounding form it requeries.
However, when there are spaces in the search string, Umbraco gets way to clever for itself and changes something like "red tree" to "red" tree=""
It is frustrating and seems to happen for fields as well - this must be a common enough problem. I can URLEncode it but then when I click the submit button it gets encoded again, which obviously isn't desirable, so I basically want the following to happen
QueryString?Search=red+tree
template: <input type="hidden" name="search" value=#Request.QueryString["search"]>
becomes: <input type="hidden" name="search" value="red tree">
NOT: <input type="hidden" name="search" value="red" tree="">
note that <input type="hidden" name="search" value=#HttpUtility.UrlEncode(Request.QueryString["search"])> gives <input type="hidden" name="search" value="red+tree"> which is again not what I need
This isn't Umbraco, it's the fact that you haven't enclosed your value in quotes. If you amend your code to:
<input type="hidden" name="search" value="#Request.QueryString["search"]">
It should work as you expect.
Related
I have a textbox which I would like bound with data from the logged in user, so that the user can't edit it. Would this need to be a label, or is there another way?
<p>Practice:
<input class="form-control" type="text" value="6666666 - Siya's Awesome world" readonly="readonly" id="txtName" />
</p>
Ps. I don't want the values entered as I did above. Your help is appreciated.
Use input like this :
<input readonly="readonly" disabled="disabled" class="text-box single-line readonly" id="field-id" name="field-name" />
Using #Html.CheckBoxFor generates a hidden field. Is there a way I can avoid generating that ?
Why I want to do that ? I was provided design, which has some script or library used in it for visual display. It works fine if Html is in below format (Checkbox with Label):
<div>
<input type="checkbox" value="resources" id="resources" class="cb">
<label for="resources">
I need an offset facility
</label>
<i class="tooltip-icon" data-icon="repayments"></i>
</div>
But it do not work if there is a hidden field between Checkbox and Label:
<div>
<input id="HomeLoanLead_Redraw_flexibility_Value" class="cb" type="checkbox" value="true" name="HomeLoanLead.Redraw_flexibility_Value" data-val-required="The Redraw_flexibility_Value field is required." data-val="true">
<input type="hidden" value="false" name="HomeLoanLead.Redraw_flexibility_Value">
<label for="HomeLoanLead_Redraw_flexibility_Value"> I want to make extra repayments </label>
<i class="tooltip-icon" data-icon="loan"></i>
</div>
If I try using <input type=checkbox> I m afraid I will not get out of box model binding in post action.
Please help.
I need to fill two forms on the same website, my issue is the field because they have the same name, e.g. the password field in both forms is passed, so how can I fill both?
<form action="post.php" method="post">
<input type="hidden" name="name" value="value" />
<input type="text" name="image" />
<input type="password" name="pass" size="10" tabindex="7" accesskey="Q" value="">
</form>
<form action="post2.php" method="post">
<input type="hidden" name="name" value="value" />
<input type="text" name="image" />
<input type="password" name="pass" size="10" tabindex="4" accesskey="P" value="">
</form>
the code to fill fields I'm using is this:
WebBrowser1.Document.GetElementById("pass").SetAttribute("value", stringpassword);
thanks
The id attribute specifies a unique id for an HTML element.
The id must be unique within the HTML document.
The id attribute can be used by a JavaScript (via the HTML DOM) or by CSS to make changes or style the element with the specified id.
And if your specified website is not following the standard Html practices then you should write your own custom
code to access those controls and fill them straight away. You can use Regex Or Xpath for accomplishing this purpose.
I have a form with four values. If any of them are empty I want to alert the user. Would the best way be to just have 4 separate if...then statements? or is there some sort of a fancy thing that I can do with C# to accomplish this?
thanks!
code
The form in question is a static HTML form:
<form id="form1" action="launch.aspx" method="post" target="_blank" name="form1">
<input type="hidden" name="ClientID" value="123456" />
<input type="hidden" name="Password" value="986574321" />
<input type="hidden" name="PracType" value="001" />
<input type="hidden" name="Encrypt" value="11258746345" />
</form>
Request.Form returns a NameValueCollection. You can loop through that collection and check if the value is set, if it's not then you can return the name of the missing field.
You can do this in C# on the .aspx.cs page, but I think Kev, is right. The RequiredFieldValidator is the quickest, simplest way to get the desired behavior you want.
By the way, why are all your form items hidden? Are we to assume you're using the control? If you can supply us with some more information, I think we can answer your question more accurately.
I tried to follow this but the default modelbinder let my array null on the server side.
HTML:
Question 1:
<input name="list[0]" type="radio" value="1000" />No
<input name="list[0]" type="radio" value="1001" />Yes
Question 2:
<input name="list[1]" type="radio" value="1002" />No
...
Controller action:
public ActionResult Anamnesis(string[] list)
{
If I choose only the second "No" (list[0] is missing) then the DefaultModelBinder is impossible to transform it into an array.
Thanx in advance!
Update#1
Reformatted based on the comment, thank you!
Update#2
Just a tought: created a hidden input after all list item, and in this way it works. But it's ugly, no doubt.
Question 1:
<input name="list[0]" type="radio" value="1000" />No
<input name="list[0]" type="radio" value="1001" />Yes
<input type="hidden" name="list[0]"/>
Question 2:
<input name="list[1]" type="radio" value="1002" />No
<input type="hidden" name="list[1]"/>
...
Order it's very important: the hidden value submits only when the radio is unchecked. The idea it's from the ASP.NET MVC helpers. (Btw I cannot use Html.RadioButton to archive this behavior.)
Your Update #2 seems like it solves your problem. Your Update #2 is also interesting in that you could also use this approach to supply a default value (such as 999) to be used whenever nothing is checked.
There is perhaps another similar way to do what you are asking, which is based on this article and which also uses hidden inputs. The idea is that you can create indexes for each of your radio sets, to avoid the situation where a missing selection earlier in the form causes all subsequent selections to be dropped:
Question 1:
<input name="list.Index" type="hidden" value="0" />
<input name="list[0]" type="radio" value="1000" />No
<input name="list[0]" type="radio" value="1001" />Yes
Question 2:
<input name="list.Index" type="hidden" value="1" />
<input name="list[1]" type="radio" value="1000" />No
<input name="list[1]" type="radio" value="1001" />Yes
The reason I suggest this, is in the case where you might like to associate your answers with a specific question by a unique ID, instead of just using 0, 1, 2 etc. The article I linked will show an example of how to do this.
Good luck!
-Mike
The name attribute of the radio button should be list, not list[n].