Reputation: 25
im working on a project where a user can describe his location in multiple lines but when i press enter button for new line in input form it gets submitted into database. i feel myself stucked here. help me to get rid of this please
my html code is:
<form method="POST" id="name-form">
<div class="h4">Describe Location</div>
<input type="text" value='Describe Location' name="disc" class="input-formm">
<input type="submit" value="discribe" name="discribe" class="edit-button">
</form>
and my php code is :
if (isset($_POST['discribe'])) {
$disc = htmlspecialchars(trim($_POST['disc']));
$qry = "UPDATE `Location` SET disc=:disc WHERE city = :city";
$result = $conn->prepare($qry);
$result->bindParam(':disc', $disc, PDO::PARAM_STR);
$result->bindParam(':city', $city, PDO::PARAM_STR);
$result->execute();
}
please help me
Upvotes: 2
Views: 56
Reputation: 31
if you go with input type text and do not want any textarea then just used this jquery code
$('form [name="disc"]').keydown(function (e) {
if (e.keyCode == 13) {
e.preventDefault();
return false;
}
});
Upvotes: 0
Reputation: 26
Instead of using "<input type="text" ...>" you can use "<textarea ..>" markup. It can be easily used in forms and shouldn't submit on enter while in this text area.
Upvotes: 1