Reputation: 13850
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.
Upvotes: 14
Views: 30118
Reputation: 749
You can optionally use JQuery's ajax method when submitting your form:
<form action="process_form">
<button type="submit"></button>
</form>
<script>
$(form).submit(function(){
var formdata = $(this).serialize()+"&var1=12&var2=24";
$.ajax(function(){
url: 'http://example.com/process_form'
data: formdata,
success: function(data){
// do something nice here
}
});
});
</script>
This simply adds your form variables to the form data url string
Upvotes: 0
Reputation: 1000
The way I've usually seen this done is: <input type="hidden" name="field_name" value="myValue" />
Upvotes: 2
Reputation: 12281
use:
<input type='hidden' name='hidden_value' value='hidden' />
In you form you will either have access to $_GET['hidden_value']
or $_POST['hidden_value']
depending on your form method. The value of the variable will be hidden
Upvotes: 0
Reputation: 95518
Use a hidden input element:
<input type = "hidden" name = "topic" value = "something" />
Upvotes: 31