I’ve found 2 hacks but i don’t know how to use it with CF7…
1:
var $message = $(“#message”);
$message.on(“keydown keypress”, function() {
var $this = $(this),
val = $(this).val()
.replace(/(\r\n|\n|\r)/gm,” “) // replace line breaks with a space
.replace(/ +(?= )/g,”); // replace extra spaces with a single space
$this.val(val);
});
2:
Another option without jQuery is to compare the currently assigned key to the previous key. If they are the same, and both are in the set of illegal keys, refuse the keypress action. This approach will not change the starting text in any way, no matter what spacing that has.
HTML:
<form action=”includes/change_status.php” id=”form2″ method=”post” name=”form2″>
<div class=”status-border-top”></div>
<div class=”status-border”>
<!– notice the onkeypress attribute –>
<textarea data-id=”status” id=”status” maxlength=”80″ name=”status” style=”width: 187px; margin-top:-4px; text-align:left; padding-left:5px; padding-top:3px; padding-bottom:2px; padding-right:3px; margin-left:-4px; height: 54px; font-size:12px; resize: none; border: hidden; -moz-border-radius: 6px; -webkit-border-radius: 6px; border-radius: 6px; position:relative; z-index:100;” onkeypress=”return ignoreSpaces(event);”><?php echo htmlspecialchars ($profile[‘status’]); ?></textarea>
<input class=”status-submit” id=”submit” name=”submit” src=”../PTB1/assets/img/icons/save-status.png” type=”image” value=”submit”>
</div>
</form>
Javascript:
var lastkey;
var ignoreChars = ‘ \r\n’+String.fromCharCode(0);
function ignoreSpaces(e){
e = e || window.event;
var char = String.fromCharCode(e.charCode);
if(ignoreChars.indexOf(char) >= 0 && ignoreChars.indexOf(lastkey) >= 0){
lastkey = char;
return false;
}else{
lastkey = char;
return true;
}
}