2012-01-08 1:16, Shapper wrote:
> Let me change my example to:
Explaining what you are trying to accomplish might be more useful than
mutating some sketchy markup.
It seems that your page contains information about a specific product
and a form for deleting the product, whatever that might mean (it's up
to the server-side form handler of course). And the product code, like
240 in the example, is hard-wired into a URL inside the page:
> <form action="/product/delete/240" method="post">
> <input type="submit" value="Delete" name="Delete" id="Delete">
> </form>
The name and id attribute appear to be redundant here.
> 1 - My initial question was:
> Should the form wrap all content?
> Or should I place it in the end?
> The other markup is still not decided.
Functionally, it does not matter. Any content that is not form fields
can be put into a form without affecting the way the form works. Is
there any reason to consider making the form larger than it needs to be
> 2 - The name/id of the Submit Input should be "Delete"?
The id attribute value does not matter unless you use it elsewhere on
the page. The presence of a name attribute along with a value attribute
causes the name=value data to be included in the form data. This is
redundant if the script at "/product/delete/240" does what you seem to
be implying it does: it deletes (in some sense) something it knows how
to identify, using the URL of the request.
> Does this apply to all forms?
I have no idea of what you mean by that question. You haven't mentioned
any other forms.
> 3 - Yes, I am using POST method on the form.
> And I am overriding to DELETE when the browser supports it.
I'm afraid there's a misunderstanding here. The DELETE method in HTTP
transactions is for deleting resources such as files, and it is normally
not used in HTML.
> 4 - The form action is now: action="/product/delete/240"
> 240 is the ID of the product currently being viewed.
> Is this what you mean with:
> "there is nothing that will transmit with the form *what* your
> are deleting"
Who knows? But this sounds like an odd way of doing this. It would be
much more normal to have a script address like "/product/delete" and the
script written so that it gets an identification of the thing to be
deleted in the _form data_. This could be a hidden field, such as
<input type=hidden name=thing value=240>
This would add thing=240 into the form data, and the script would then
get it using whatever tools the scripting language has for accessing
that data.
If the script is of a more generic nature, so that it can delete,
modify, copy, transmogrify and deify things, for example, then it would
make sense to pass, in the form data, an instruction-like thing, e.g. with
<input type=submit name=action value=Delete>
which would add action=Delete into the form data.
--
Yucca,
http://www.cs.tut.fi/~jkorpela/