Simple ASP Textbox Call - forms

i am a front-end coder, so i don't know much about ASP
one of my clients called me for a simple help and i didn't refuse him.
What he wants is a simple text box with a submit button, and when he submits a text, lets say "Sample", he wants the server to call http://example.com/Sample.pdf after submission.
Simply, that is what i have at the moment:
<form action="form_action.asp">
<input type="text" name="pdf" value="enter pdf id" />
<input type="submit" value="Submit" />
</form>
It would be better if i can get a working answer as i don't have asp server on my computer, i will not be able to test it.
Any help will be appreciated. Thanks.

This is a very bad idea, especially when the implementer doesn't have an understanding of back-end coding. You are opening up the server to a whole heap of security issues.
If you allow anything to be put in this box, what would stop me entering ../includes/dbsettings.asp for example and getting access to files I really shouldn't have access to?
How will you handle if the file doesn't exist?
Actual Answer: This is a Q&A site, so here is the answer you requested, be careful what you do with it!
The following in it's own ASP page should do what you want:
<%
Response.Redirect("/" & Request.Form("pdf") & ".pdf")
%>
You can (and should) get more complex by setting mime type, designating it as an attachment (so a download box is spawned), streaming the file and above all adding security and error checking.

Related

How do I add a comment into an IIS Log file?

I have a simple html file on an IIS server that asks a user to enter a code:
<form action="educational_page.html" onsubmit="myFunction()">
Enter CODE: <input type="text" CODEVal="CODEVal">
<input type="submit" value="Submit">
</form>
<script>
function myFunction() {
alert("The form was submitted");
}
</script>
I specifically DON'T want to log what they enter, rather, I just want to know that they clicked the submit button.
This can be easily inferred by reviewing the IIS Logs, but the people I will be providing the logs to may not find it that easy.
What would be helpful is if there was a way for me to add a comment into the IIS Log that said something like:
"User clicked the 'submit' button."
Preferably on the same line the associated line in the log, so they can easily associate the user who clicked.
Is this possible without running code on the server?
I've read some posts doing something similar (Writing to a text file on the server) which appeared to require my running code on the server. I'd rather leave the solution as simple as possible, and not server side.
The rest of the page does what I want. (Loading the educational_page.html)
I just want to have an easy to parse file that the end user can search for usernames that clicked on the submit button thereby indicating they possibly entered the code.
I agree with the suggestion given by Lex Li.
Client-side JS code could not help writing the logs to the Server side. You need to use Server side code in your app to write logs on the Server-side.
Further, you will not be able to edit/modify IIS logs to append some information in it from your app code.
To achieve your requirement, you could try to write Server-side code that could create/write custom logs files and write data to them.
What you are trying to achieve is not possible using JS code and IIS logs.

Form Variables are not showing up after form submit. ColdFusion

<form name="abc" id="abc" method="post" action="/test.cfm" enctype="multipart/form-data">
<input type="submit" name="btnSubmit" id="btnSubmit" value="OK" />
</form>
for some reason when I hit submit the "btnSubmit" is not showing up in the cfdump.
<cfdump var="#form#">
There aren't a lot of things that could cause it to simply not appear in your form. My short-list of culprits are:
Looking at the wrong file / server.
The page is being redirected via cflocation or otherwise (javascript location.replace() or location.href=x) -- this would cause that problem even if the redirection is returning the browser to the same page.
Form variables being stripped out somewhere further up, I would guess in onRequestStart
A local variable named "variables.form" was created and set to a structure further up - not very likely, but I suppose it's possible someone could accidentally write something like <cfset form = url />, which might cause that
Usually, when something like this has happened to me in the past, I've found that I've been viewing the wrong file in the browser. Usually it's come down to me looking at the same file on the wrong domain name, e.g. looking at the production server instead of the development server.
If you combine your code segments above into a single file like this (test.cfm):
<cfdump var="#form#" />
<form name="abc" id="abc" method="post" action="test.cfm" enctype="multipart/form-data">
<input type="submit" name="btnSubmit" id="btnSubmit" value="OK" />
</form>
That ought to give you some insight into your problem. Note that I removed the leading-slash / in the form action, so that this form will post to itself. When I first view this template, I see an empty struct (followed by the button), because I haven't put anything in the form scope yet. When I submit the form I then see two elements in the structure, fieldnames and btnSubmit. That's another good indicator, if you don't see fieldnames in the form structure, then your CFML page may not have received a form submission. If you know you're looking at the right page and you've submitted the form and you still don't have the fieldnames entry, then I'd start looking for potential browser redirection.
You might also want to add an empty Application.cfc in the same directory just to be sure that there's not an application interfering with it. It's possible that something in the onRequestStart might be stripping out form variables with the name "btnSubmit" or even any form variable with the string "submit" anywhere in the name. I wouldn't expect it though -- I'd look for other causes like cflocation tags first.

Using ASP to redirect user to new folder

I know the heading sounds simple and I hope the answer is but I am new to ASP and cannot figure this one out. I am makeing a form which submits a user name to access.asp
<form name="input" action="access.asp" user="" method="get">
Username: <input name="user" type="text" />
<input value="Submit" type="submit" /></form>
What I want to actually achieve is when someone types a user name into the form and clicks submit, I want the form to move them to the next subdirectory with that user name.
ie. username=thomas then they are redirected to a folder http://www.whatever.com/thomas/
ie. username=samantha then they are redirected to a folder http://www.whatever.com/samantha/
and so forth. the folder would default for an index.html file or a 404 file if the entered username directory does not exist. I am trying not to create a database file unless this is required. I will only have 5-10 username directories when I am done.
Any help would be appreciated.
Thanks,
Erik
While this can be done in JavaScript. I'd continue to do it in ASP. Doing it on the server will allow you to check to make sure the username is valid, and if not then do something else.
With ASP.Net you'd want to use Response.Redirect
There are several Examples on different languages at Microsoft's MSDN http://msdn.microsoft.com/en-us/library/ms524309%28v=VS.90%29.aspx
Basicallys you'd just need
<% Response.Redirect "/" + Request.QueryString("username") %>

jQuery form processing

Does anybody know of a simple jQuery form processing tutorial that actually works?
I have a form I want to process via jQuery/Ajax nothing difficult in PHP but in jQuery and AJAX can I get it to work - no, all the tutorials are based round sending e-mails (or just lists of more lists of more lists of tutorials - hate those)
All I want to do is learn how to send a form via jQuery and AJAX to another page, save the data in a DB without having to leave the first page. I have tried all sorts but nothing works properly. Here is my form:
<form id="form">
<input type="text" name="abc" />
<input type="text" name="def"/>
<input type="text" name="ghi"/>
<input type="submit" name="try" id="try" />
</form>
Now what do I actually do? Sounds silly I know (and I guess I'll get another -1 star for this question) but I will be honest a GOOD simple tutorial would be really useful not just to me but to the others. I know php but jQuery/Ajax - just don't know/understand. I will not be alone
This is one of the good tutorials on how to submit forms using ajax and php.
This link is a reference teaching how to submit forms via jQuery/AJAX. Have the form post to a PHP page to handle the form data.
In short, your jQuery code would look similar to this:
$("#form").submit( function()
{
// Handle validation or any extra data here.
// Return true if validation passed and the data should be posted
// Return false if the form should not be submitted
// You can also do any extra work here that you like before returning,
// including changing something on the page or showing the user a message.
}
There's a cracking plugin for this:
http://plugins.jquery.com/project/form/
It's as easy as:
$('#myForm').ajaxForm(function() {
alert("Thank you for your comment!");
});

Is it possible to implement cross-browser username/password autocomplete in GXT?

Last night, I did a quick spike to try and implement username/password autocomplete in my GXT application. By "autocomplete", I don't mean Ajax-style autocomplete, but rather browser-based autocomplete. The best information I found on this via google is in the following post:
http://osdir.com/ml/GoogleWebToolkit/2009-04/msg01838.html
I didn't use this technique because I'm using GXT and didn't want to lose the look-and-feel of my login form.
I was successful in getting everything to work in Firefox (it populates both the username and password). In IE, it only populates the username, not the password. In Safari/Chrome, it doesn't work at all.
Here's how I did it:
Created a hidden HTML form on my HTML page that embeds GWT.
<form method="post" action="javascript:void(0)" style="display: none">
<input type="text" id="username" name="username" value=""/>
<input type="password" id="password" name="password" value=""/>
<input type="submit" value="Login" id="login"/>
</form>
When a user clicks on the "Login" button in my GWT application, populate the fields in this hidden form and "click" on the Login button (which will do nothing since the action="javascript:void(0)".
// Set the hidden fields to trigger the browser to remember
DOM.getElementById("username").setAttribute("value", username.getValue());
DOM.getElementById("password").setAttribute("value", password.getValue());
clickFormLogin();
...
public static native void clickFormLogin() /*-{
$doc.getElementById("login").click();
}-*/;
This works in Firefox 3.5 and prompts me to save the user/pass at the top of the screen. I believe I know why this doesn't work in Safari/Chrome and that's because the form's action doesn't go anywhere and the form is not submitted. If I change the action to be an actual URL and show the form, clicking on the form's Login button will save it in those browsers.
After typing this up as a question here, I got to thinking this might make a good blog post. Therefore, I copied everything and added a bit to my blog:
http://raibledesigns.com/rd/entry/browser_based_username_password_autocomplete
Summary and Question
While I'm glad I got it working in Firefox, I'm disappointed with IE's lack of password autocompletion. More than anything, I can't help but think there's a way to make this work in WebKit-based browsers.
Anyone know how to implement cross-browser username/password autocomplete in GWT (specifically GXT)?
Use persistent Cookies instead.
IE do save passwords, if user chooses to, but it works different. You need to type at least the username so it will autocomplete the password.
You need a plain vanilla html submit button. I think that will fix it.
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/2b2ce0b6aaa82461