How to write Response.redirect with Query_string server variables in ASP - redirect

I'm trying to redirect users to my mobile page equivalent of a desktop page. Right now I can only get them to the home page.
If b.test(u) or v.test(Left(u,4)) then response.redirect("/mobile.asp") End If
I'd like to redirect to the mobile page with the additional correct variables. So the redirect response should be to "/mobile.asp?m=here" from the "/home.asp?m=here" page and "/mobile.asp?m=there" from the "/home.asp?m=there" etc.
I can get the variables with <% Response.Write(Request.ServerVariables("QUERY_STRING")) %> but my syntax must be off when I try to concat the redirect
If b.test(u) or v.test(Left(u,4)) then response.redirect("/mobile.asp?&Response.Write(Request.ServerVariables("QUERY_STRING"))&""") End If
Little help. Thanks.

You don't need the response.write in there. Something like this (not tested it though)
response.redirect("/mobile.asp?" & Request.ServerVariables("QUERY_STRING"))

In order to put something dynamic into your string it has to be determinated first, then use a & to concatenate other strings / variables. So you want your code to look like this:
If b.test(u) or v.test(Left(u,4)) then response.redirect("/mobile.asp?" & Response.Write(Request.ServerVariables("QUERY_STRING"))) End If
also, you should check for any query strings to know weather to put the ? or not.

Related

HTML form POST method with querystring in action URL

Lets say I have a form with method=POST on my page.
Now this form has some basic form elements like textbox, checkbox, etc
It has action URL as http://example.com/someAction.do?param=value
I do understand that this is actually a contradictory thing to do, but my question is will it work in practice.
So my questions are;
Since the form method is POST and I have a querystring as well in my URL (?param=value)
Will it work correctly? i.e. will I be able to retrieve param=value on my receiving page (someAction.do)
Lets say I use Java/JSP to access the values on server side. So what is the way to get the values on server side ? Is the syntax same to access value of param=value as well as for the form elements like textbox/radio button/checkbox, etc ?
1) YES, you will have access to POST and GET variables since your request will contain both. So you can use $_GET["param_name"] and $_POST["param_name"] accordingly.
2) Using JSP you can use the following code for both:
<%= request.getParameter("param_name") %>
If you're using EL (JSP Expression Language), you can also get them in the following way:
${param.param_name}
EDIT: if the param_name is present in both the request QueryString and POST data, both of them will be returned as an array of values, the first one being the QueryString.
In such scenarios, getParameter("param_name) would return the first one of them (as explained here), however both of them can be read using the getParameterValues("param_name") method in the following way:
String[] values = request.getParameterValues("param_name");
For further info, read here.
Yes. You can retrieve these parameters in your action class.
Just you have to make property of same name (param in your case) with there getters and setters.
Sample Code
private String param;
{... getters and setters ...}
when you will do this, the parameters value (passed via URL) will get saved into the getters of that particular property. and through this, you can do whatever you want with that value.
The POST method just hide the submitted form data from the user. He/she can't see what data has been sent to the server, unless a special tool is used.
The GET method allows anybody to see what data it has. You can easily see the data from the URL (ex. By seeing the key-value pairs in the query string).
In other words it is up to you to show the (maybe unimportant) data to the user by using query string in the form action. For example in a data table filter. To keep the current pagination state, you can use domain.com/path.do?page=3 as an action. And you can hide the other data within the form components, like input, textarea, etc.
Both methods can be catched in the server with the same way. For example in Java, by using request.getParameter("page").

Add Page Tab redirect to invalid location

When I've user Add Page Tab Dialog, I've passed redirect_uri like this
http://MYSITE/?r=c/action&token=123456789
when the dialog come back, it strips the token variable, so the url looks like
http://MYSITE/?r=c%2Faction&&tabs_added%5B176281002470701%5D=1#_=_
the token variable lost,
any body have any idea why this happen?
Might be a bug or the forward-slash. Try adding an extra param at the end that you don't care about or removing the forward-slash
http://MYSITE/?r=c/action&token=123456789&t=1
http://MYSITE/?r=caction&token=123456789
One option is to put all your needed variables in a single base64 string and pass that guy over as your single querystring parameter.
Pseudo-code would be:
data = toBase64String("action&token=123456789")
redirect_uri = "http://MYSITE/?data=" + data;
Then you decode it wherever you redirect to.

How to get parameter come after '#' in Perl CGI?

How can we fetch the value of folders from below mentioned url:
http://my.indiamart.com/cgi/​my-enquiries.mp#folders=1
I've tried CGI object, %ENV variable and so many things, but still not been able to get it.
Please suggest..
You can't, the browser interprets the fragment (#folders=1) without sending it to the server. So if http://my.indiamart.com/cgi/​my-enquiries.mp is your script, then it will never see the #folders=1 part of the URL as the browser won't send it. If you need the fragment on the server then you'll have to change it to a CGI parameter:
http://my.indiamart.com/cgi/​my-enquiries.mp?folders=1
or embed it in the URL path, something like one of these:
http://my.indiamart.com/cgi/​my-enquiries.mp/1
http://my.indiamart.com/cgi/​my-enquiries.mp/folders=1
You can't, # is recognized by JavaScript only,
apache will ignore this, that's the reason it does not contains any value in ENV variable.
You can use JavaScript: window.location.hash to capture this hash value.
Only with javascript.
You can use something like that to redirect to another script
<script>
if(window.location.hash) {
var str = window.location.hash.substring(1);
window.location.href = 'http://other_script.pl?param=' + str;
}
</script>

How can I check my post data in Zend?

I am a beginner and I am creating some forms to be posted into MySQL using Zend, and I am in the process of debugging but I don't really know how to debug anything using Zend. I want to submit the form and see if my custom forms are concatenating the data properly before it goes into MySQL, so I want to catch the post data to see a few things. How can I do this?
The Default route for zend framework application looks like the following
http://www.name.tld/$controller/$action/$param1/$value1/.../$paramX/$valueX
So all $_GET-Parameters simply get contenated onto the url in the above manner /param/value
Let's say you are within IndexController and indexAction() in here you call a form. Now there's possible two things happening:
You do not define a Form-Action, then you will send the form back to IndexController:indexAction()
You define a Form action via $form->setAction('/index/process') in that case you would end up at IndexController:processAction()
The way to access the Params is already defined above. Whereas $this->_getParam() equals $this->getRequest()->getParam() and $this->_getAllParams() equals $this->getRequest->getParams()
The right way yo check data of Zend Stuff is using Zend_Debug as #vascowhite has pointed out. If you want to see the final Query-String (in case you're manually building queries), then you can simply put in the insert variable into Zend_Debug::dump()
you can use $this->_getAllParams();.
For example: var_dump($this->_getAllParams()); die; will output all the parameters ZF received and halt the execution of the script. To be used in your receiving Action.
Also, $this->_getParam("param name"); will get a specific parameter from the request.
The easiest way to check variables in Zend Framework is to use Zend_Debug::dump($variable); so you can do this:-
Zend_Debug::dump($_POST);
Zend framework is built on the top of the PHP . so you can use var_dump($_POST) to check the post variables.
ZF has provided its own functions to get all the post variables.. Zend_Debug::dump($this->getRequest()->getPost())
or specifically for one variable.. you can use Zend_Debug::dump($this->getRequest()->getPost($key))
You can check post data by using zend
$request->isPost()
and for retrieving post data
$request->getPost()
For example
if ($request->isPost()) {
$postData = $request->getPost();
Zend_Debug::dump($postData );
}

zend framework urls and get method

I am developing a website using zend framework.
i have a search form with get method. when the user clicks submit button the query string appears in the url after ? mark. but i want it to be zend like url.
is it possible?
As well as the JS approach you can do a redirect back to the preferred URL you want. I.e. let the form submit via GET, then redirect to the ZF routing style.
This is, however, overkill unless you have a really good reason to want to create neat URLs for your search queries. Generally speaking a search form should send a GET query that can be bookmarked. And there's nothing wrong with ?param=val style parameters in a URL :-)
ZF URLs are a little odd in that they force URL parameters to be part of the main URL. I.e. domain.com/controller/action/param/val/param2/val rather than domain.com/controller/action?param=val&param2=val
This isn't always what you want, but seems to be the way frameworks are going with URL parameters
There is no obvious solution. The form generated by zf will be a standard html one. When submitted from the browser using GET it will result in a request like
/action/specified/in/form?var1=val1&var2=var2
Only solution to get a "zendlike url" (one with / instead of ? or &), would be to hack the form submission using javascript. For example you can listen for onSubmit, abort the submission and instead redirect browser to a translated url. I personally don't believe this solution is worth the added complexity, but it should perform what you're looking for.
After raging against this for a day-and-a-half, and doing my best to figure out the right way to do this fairly simple this, I gave up and did the following. I still can't believe there's not a better way.
The use case that necessitates this is a simple record listing, with a form up top for adding some filters (via GET), maybe some column sorting, and Zend_Paginate thrown in for good measure. I ran into issues using the Url view helper in my pagination partial, but I suspect with even just sorting and a filter-form, Zend_View_Helper_Url would still fall down.
But I digress. My solution was to add a method to my base controller class that merges any raw query-string parameters with the existing zend-style slashy-params, and redirects (but only if necessary). The method can be called in any action that doesn't have to handle POSTs.
Hopefully someone will find this useful. Or even better, find a better way:
/**
* Translate standard URL parameters (?foo=bar&baz=bork) to zend-style
* param (foo/bar/baz/bork). Query-string style
* values override existing route-params.
*/
public function mergeQueryString(){
if ($this->getRequest()->isPost()){
throw new Exception("mergeQueryString only works on GET requests.");
}
$q = $this->getRequest()->getQuery();
$p = $this->getRequest()->getParams();
if (empty($q)) {
//there's nothing to do.
return;
}
$action = $p['action'];
$controller = $p['controller'];
$module = $p['module'];
unset($p['action'],$p['controller'],$p['module']);
$params = array_merge($p,$q);
$this->_helper->getHelper('Redirector')
->setCode(301)
->gotoSimple(
$action,
$controller,
$module,
$params);
}