I want to make editable element as input form field [duplicate] - javascript

This question already has answers here:
Using HTML5, how do I use contenteditable fields in a form submission?
(4 answers)
Closed 6 months ago.
My code
<form action="" method="post">
<div name="name" contentEditable="true">You Favorite Movie</div>
<p name="Comment" contentEditable="true">Your Comment</p>
<button>Submit</button>
<form>

As far as I know, only <input> tags are sent in the form data. However, ou could use invisible <input> tags which have data copied into them, like this:
<form action="" method="post">
<div id="name" contentEditable="true" onchange="copyToHidden('name', 'nameInput')">You Favorite Movie</div>
<input type="hidden" name="name" id="nameInput">
<p id="comment" contentEditable="true">Your Comment</p>
<input type="hidden" name="Comment" id="commentInput" onchange="copyToHidden('comment', 'commentInput')">
<button>Submit</button>
<form>
then have this JavaScript somewhere in a script tag
function copyToHidden(elementId, inputId) {
document.getElementById(inputId).value = document.getElementById(elementId).textContent;
}

Related

How to pass a POST variable without a form?

What is the best way to use a PHP table to hold comments from multiple different sections, and be able to distinguish between each different comments section? Is there some way to pass POST data without the need of a form?
Is there some way for me to distinguish between these two forms? Should I be using Javascript and distinguishing by the id of the forms, or is there a cleaner way?
<form action="SubmitComment.php" method="post" id="comments1">
<h3>Name:</h3><input type="text" name="name" cols="100">
<h3>Comment:</h3><input type="text" name="comment" cols="100">
<textarea rows=4 cols="100" placeholder="Enter text here!"></textarea>
<?php $_POST['section'] = 1; ?>
</form>
<!-- I want to be able to distinguish between these two forms. -->
<form action="SubmitComment.php" method="post" id="comments2">
<h3>Name:</h3><input type="text" name="name" cols="100">
<h3>Comment:</h3><input type="text" name="comment" cols="100">
<textarea rows=4 cols="100" placeholder="Enter text here!"></textarea>
<?php $_POST['section'] = 2; ?>
</form>
There is a way to distinguish forms using
<input type="submit" name="form" value="form1">
to send data, in that way you can read $_POST['form'] value and check what form it is
If you want to send data without form you can use ajax with Javascript.

Remove autocomplete from a SELECT with HTML [duplicate]

This question already has answers here:
How do you disable browser autocomplete on web form field / input tags?
(101 answers)
Closed 4 years ago.
I have a problem with the autocomplete in HTML, I'd like to remove it from a SELECT in a web page, so it doesn't appear over the page:
This is what I want because I'm printing the result in the bottom.
<form>
<input type="text" id="nameSearch" name="nameSearch" onkeyup="searchInput(this.value)">
<div id="searchOutput"></div>
</form>
I tried to add the autocomplete tag, but it works only with the INPUT tag.
<input autocomplete="off">
To Prevent autocomplete a field:
<form>
<input type="text" id="nameSearch" autocomplete="false" name="nameSearch" onkeyup="searchInput(this.value)">
<div id="searchOutput"></div>
</form>

how can i prevent spam in subscriber in php [duplicate]

This question already has answers here:
How to Prevent SPAM without CAPTCHAs or a Centrally managed system (e.g. akismet)
(10 answers)
Closed 5 years ago.
<form action="newsletter" method="POST">
<div class="input-group">
<input type="email" class="form-control box-style-1" size="50" name="email" placeholder="Your email" required>
<input type="hidden" name="code" value="<?php echo $code; ?>" >
<div class="input-group-btn">
<button type="submit" class="btn subscribe-btn">Subscribe</button>
</div>
</div>
</form>
I have tried to send a hidden code (randomly generated) through form but i am not able to prevent the spam.
Random code has to be a part of JavaScript, otherwise it'll be simply parsed by bots
Use reCapcha for that; or extra-header for each request (that will be a part of JS); or check RELATIVE_URL to validate that submit was done from your site.

Hitting enter in form calling wrong button [duplicate]

This question already has answers here:
Can I make a <button> not submit a form?
(8 answers)
Closed 8 years ago.
HTML:
<form target="" method="post">
<input name="username" type="text" />
<input name="password" type="password" />
<button>Cancel</button>
<input type="submit" />
</form>
Fiddle: http://jsfiddle.net/n9Lpcqyr/
Problem: When I hit enter, both buttons get triggered. Tested with this jQuery:
$('button').click(function(){
alert('help');
});
$("form").submit(function(){
alert('hey');
});
Because the first <button> is mapped to .remove() the dialog, the form no longer exists to be submitted. I know I can bind the enter key to the inputs with js, but I'm looking for an HTML-only solution. I tried tabindex with no luck. What else can I do?
You could move the cancel button outside of the form, like so (and use CSS to style):
<form target="" method="post">
<input name="username" type="text" />
<input name="password" type="password" />
<input type="submit" />
</form>
<button>Cancel</button>

Issue submitting a textarea by pressing enter [duplicate]

This question already has answers here:
Submitting data from textarea by hitting "Enter"
(5 answers)
Closed 8 years ago.
I'm sorry to make this question, as others have done it already. But mostly don't have a good explanation, or always are mixed with more complex chats functions. I want a simple code. The only thing i want is to make my textarea value submit and get inserted to my db using ENTER key. Please don't redirect me to another question, as i know they must be others with starter skills that wants to learn. Just adjust the code to the simple form i have added. Thanks.
Code:
<?php
if(isset($_POST['submit'])) {
$comment = $_POST['textarea'];
$db->query("INSERT INTO blog(textarea) VALUES('$comment')");
}
?>
<form id="form1">
<div>
Comment:
</div>
<div>
<textarea name="textarea" form="form1" maxlength="200" id="textarea" placeholder="Make your comment..."></textarea>
<input style="visibility:hidden" type="submit" form="form1" name="submit" id="submit" value="Submit">
</div>
</form>
You can do this quite simply by adding a keypress event handler to the textarea:
<form id="form1">
<div>
Comment:
</div>
<div>
<textarea onkeypress="if(event.which==13)document.getElementById('form1').submit();"
placeholder="Make your comment..."
name="textarea" form="form1" maxlength="200" id="textarea"></textarea>
<input style="visibility:hidden" type="submit" form="form1" name="submitForm" id="submitForm" value="Submit">
</div>
</form>
That checks if the pressed key has keycode 13 (which is the keycode for the enter key), and submits the form if it does.

Categories

Resources