views:

97

answers:

3

Hi,

I am trying to submit a form to a handler page but nothing is working now, it doesn't even hit the handler...

Here is my code :

<form action="Unsubscription.ashx?actionmethod=subscribe" method="get" >
<div class="h1">
<input type="text" class="input" value="enter your e-mail" name="ekey"  />
<input type="submit" value="Submit" />
</div>
</form>

handler code :

public void ProcessRequest(HttpContext context)
{
    try
    {
        string email = context.Request.Params["ekey"];
        switch (context.Request.Params["actionmethod"])
        {

            case "subscribe":
                NewsLetter.Subscribe(email);
                break;
            case "unsubscribe":
                NewsLetter.Unsubscribe(email);
                context.Response.ContentType = "text/html";
                context.Response.Write("your subscription has been successfully canceled. thanks.<br/><a href='http://www.kayatax.com'&gt;&lt;b&gt;home page</b></a>");
                break;
        }


    }
    catch         {
        context.Response.ContentType = "text/html";
        context.Response.Write("This e-mail doesn't exist in our database. Thanks.<br/><a href='http://www.kayatax.com'&gt;&lt;b&gt;Home Page</b></a>");
    }
}
A: 

Your </<form> tag is malformed for a start. Make it </form>, as I'm sure you know.

Rafe Lavelle
Okay, I changed it but now I can't see form element after rendering. I don't know why and it's not quite interesting. Firebug doesn't show the form element wrapped around submit button.
Braveyard
Close the form tag, as in "</form>". Note the slash. You've just put another opening "<form>" tag
Rafe Lavelle
(facepalm)......
CRice
I did it yet not working. :(
Braveyard
In my actual code it is closed and now it totally matches my actual code in code file. Now it's not working and actually not rendering. What should I do ?
Braveyard
You're not giving us a lot to go on...is the 'Unsubscription.ashx' file definitely in the same folder as the calling page? I'm presuming that your calling page isn't an Asp.Net page because of the lack of 'runat="server"' in the form tag.
Rafe Lavelle
@Ralph : It's an aspx page but I didn't use runat=server because I want to try that way and yeah ashx file is in the same directory of aspx file.
Braveyard
Well, the chunk of html you give seems ok, but what's in the rest of the Html file?
Rafe Lavelle
A: 

If you have browser-side rendering problems, and you're not hitting your server-side handler, I'd investigate the browser side first. See what is getting transmitted over the wire: in Firebug, enable the Net panel, reload the page, submit the form and then look at the Request in the Net panel. Hover over the first node (the request to the form-handler page) and make sure the request URL is as you expect. Then expand the node and look at the Request headers.

The first thing I'm wondering, not seeing more of your web-app, is whether the target Unsubscription.ashx is in the same directory as the page with the form, or if there's a routing method of some sort that makes it look that way. You're using a document-relative URL; are you sure the target is where you think it is?

By the way, you should not use the GET method for form submissions that change data on the server; use POST for that. It's a bit more work, but much safer. GET requests should be idempotent. If you use GET to trigger an action that changes things on the server, you may find they're changed when you don't expect them to be. D'oh!

Val
I tried to use Firebug but it didn't show me anything,also I enabled it. I am feeling kinda stupid because it's the first time I've encountered such a problem and I don't know how to solve this because I don't know what causes it.
Braveyard
A: 

Your form is using 'get' which essentially is HTTPGET. Check the submitted URL and querystring. It should be

Unsubscription.ashx?actionmethod=subscribe&ekey=enter%20your%20email

is it showing correctly?

You do not have a name for your input-submit button, but that shouldn't affect what you want.

o.k.w