Redirect users on specific text - anchor

I have a project and I have a little error like:
I have a form and above and mysql query and if I had errors I will redirect users on an specific text like that:
redirect("comunitate.php?c=".$_GET['c']."&forum=".$_GET['forum']."&topic=".$_GET['topic']."&pagina=".$_GET['pagina']."#greseala");
*redirect is my own function who do an redirect on specific page
For example: The script should to redirect on comunitate.php?c=1&forum=1&topic=1&pagina=1#greseala , and on the page i have
<a name="greseala">bla bla bla</a>
The big problem is that I see the error mesage(greseala) when I run the form and when I redirect the user on the error part text it disappears.
Why? Where is my fault?

Related

Grails redirect while keeping form values

I have a Grails action that does some custom validation by calling some services. I have the messaging setup to work properly, but when I redirect back to the page I came from, all of my previously entered data is gone. I don't want my users to have to fill out the whole form again because validation failed.
Here's what I have
if(addressValidationErrors){
flash.message = "Invalid address entered"
redirect (action:'checkout', params: params)
}
and while the message shows on the GSP and the redirect works as intended, but when I end up back on the page all the values are gone.
chain(action:"checkout", model:[key:domainObjectWithError])
Your view must check the errors and display messages accordingly then.

Rails Devise "You need to sign in or sign up before continuing"

everybody.
I was using Devise for authentication in Rails 4 and got some troubles with Devise. When I enter the link: http://yourdomain.com:3000/users/edit.535db919486f611779000000 , it just render the text "You need to sign in or sign up before continuing." without rendering layout, instead of redirect to login page (see attachment)
I guess Rails understand the numeric after "edit." is format and it didn't know how to render it.
What I want is when user enter any link without logged in, it will redirect to login page. Could anyone help me?
With this link, it throw an unknown format exception.
Your problem is to do with the passing of a value after . - EG edit.234234324 or login.23424234
As you can see from your screenshot, you're receiving the error because Rails is treating the number as a format (in the same way it would treat .html, .js or .json as formats)
I don't know why it works for edit, but it looks like it's rendering json to me, probably because it's confused with the type of format you've sent
The way to fix this is to get your config/routes.rb & URLs fixed
You've not detailed how you're sending the numbered requests to your URL helper, but if you're requesting pure URLS, you need to remove the number from the end:
localhost:3000/users/login
localhost:3000/users/edit
These are the URLs which should load (with no numbers)
I would imagine you are getting the error because you're calling the devise url helpers like this:
<%= link_to "login", user_new_session_path(some_value) %>
You just need to use user_new_session_path

Asp.Net Mvc remote validation textbox focus issue

I have a single textbox on a form - basically to allow users to change the URL of their site in our mini CMS. We use remote validation to check that the URL is not already taken.
They enter their desired URL and hit the save button. If they do just that and the focus goes from the textbox straight to the submit button - the validation does not happen and the form doesn't submit properly. If they tap into an area of whitespace then the form does.
The issue with the form submitting is that if they tap whitespace we get the name of the submit button posted along with the desired URL - we use the (AcceptParameterAttribute) to allow us to route form submits to the right Action. This uses the submit buttons name attribute to do this. If they don't click whitespace to lose focus on the text box then only the desired URL is posted.
This is a really odd one and it is very annoying. Has anyone seen anything like this before? Is there a way to overcome the problem?
Try adding the following script to the page:
$(":input").live("blur", function () {
$(this.form).validate().element(this);
});
This should cause validation to occur when you click on the submit button. If not, try changing the first line to:
$(":submit").live("click", function () {

how to reset page text boxes data after page post back?

my question seems simple and stupid
but first read this,
suppose you have a login form which take username and password and post back to controller
if login successful then return Homepage(return View("HomePage")) View (not Redirect) then suppose i am Logged off
and return Login (return View("Login")) View (again not Redirect) and now if i press Back button and Refresh the page then it will automatically get logged IN by using those username and password which i entered before.
So can i make those password Null from Browser's Memory or where ever it is i don't know.
"i know that not redirecting (RedirectToAction("ViewName")) is causing the problem" But Why or May be i don't know any important concept
Some browsers, especially Firefox try to be helpful and 'remember' values you have input into text fields and checkboxes. in order to switch this off in a particular input add the following attribute
autocomplete="off"
Alternatively, using jQuery you can switch it off for a whole form:
$("form").attr("autocomplete", "off");
ModelState.Remove("key");
or
ModelState.Clear()

How to implement a search page which shows results on the same page?

I'm using ASP.NET MVC 2 for the first time on a project at work and am feeling like a bit of a noob.
I have a page with a customer search control/partial view. The control is a textbox and a button. You enter a customer id into the textbox and hit search. The page then "refreshes" and shows the customer details on the same page. In other words, the customer details appear below the customer search control.
This is so that if the customer isn't the right one, the user can search again without hitting back in the browser. Or, perhaps they mistyped the customer id and need to try again.
I want the URL to look like this:
/Customer/Search/1
Obviously, this follows the default route in the project.
Now, if I type the URL above directly into my browser, it works fine. However, when I then use the search control on that page to search for say customer 2, the page refreshes with the correct customer details but the URL does not change! It stays as
/Customer/Search/1
When I want it to be
/Customer/Search/2
How can I get it to change to the correct URL?
I am only using the default route in Global.asax.
My Search method looks like this:
<AcceptVerbs(HttpVerbs.Get)> _
Function Search(ByVal id As String) As ActionResult
Dim customer As Customer = New CustomerRepository().GetById(id)
Return View("SearchResult", customer)
End Function
A good place to start might be NerdDinner if you havn't already.
In the mean time though The approach I'd use is to have a page that has my search box on it.
Then I'd have a <div> that I name "SearchResults". This will ultimately hold my results to the search.
I then have a PartialView which takes a model that has all the search results and renders them.
So when I click the button I do a call out to a jQuery action that takes the search parameter, performs the search and then returns my PartialView as rendered HTML.
Back in the client side I take that rendered HTML and replace the contents of my div with the HTML.
The keywords to google, or SO, are RenderPartial. This is back end code to render a partial view and give you html.
Also jQuery postbacks so that you can call an action in your controller.
use RedirectToRoute action result
link

Resources