Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way of sending form values without inputs

Let say that I have the form below:

<form action="sendMessage.php" method="post">
    <label>Subject</label><input type="text"></input>
    <label>Message</label><input type="text"></input>
    <input type="submit"></input>
</form>

How can I send an another value like topic(which is pre-defined) without creating an another element for that? Is it possible or do I have to make input element and style it with display: none;

The answer can contain html, javascript or jquery code.

like image 237
einstein Avatar asked Jul 07 '11 15:07

einstein


People also ask

Do inputs always need to be in a form?

Yes, you can have a valid input without a form.

How do you send data through a form?

The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute). The form-data can be sent as URL variables (with method="get" ) or as HTTP post transaction (with method="post" ). Notes on GET: Appends form-data into the URL in name/value pairs.

Should I wrap inputs in a form?

No you don't. The form is used to send data to the server, like some kind of search mask to query a database. You can put all your input tags in one form tag.


1 Answers

Use a hidden input element:

<input type = "hidden" name = "topic" value = "something" />
like image 192
Vivin Paliath Avatar answered Nov 10 '22 04:11

Vivin Paliath