lexomatic
asked 7 years ago

We are having problems with users entering large chunks of text in the title line instead of the textbox where it belongs. Is there a way to limit the title of the question to, say, 60 characters? I am asking because the title of the question gets picked up as the title tag for the page. Google typically displays the first 50-60 characters of a title tag, and having additional characters is not SEO-friendly. I would like to be able to limit the title to 60 characters and not allow the form to be submitted (i.e., use validation) if the user enters more. If the user has more text to enter, he/she can use the textbox. 

2 Answers
DominicStaff
answered 7 years ago

To resolve this issue, you can open the question-submit-form.php file in the templates folder then replace the line code 17 to 22 with the following code:

<form method="post" class="dwqa-content-ask-form" id="form_elem">
<p class="dwqa-search">
<label for="question_title"><?php _e( 'Title', 'dwqa' ) ?></label>
<?php $title = isset( $_POST['question-title'] ) ? $_POST['question-title'] : ''; ?>
<input type="text" data-nonce="<?php echo wp_create_nonce( '_dwqa_filter_nonce' ) ?>" id="question-title" maxlength="70" name="question-title" value="<?php echo $title ?>" tabindex="1">
<span id="error_msg" style="color:red"></span>
<script type="text/javascript">
$("#validate").click(function(){
var inputStr = $("#question-title").val();
if(inputStr.length<70)
$("#error_msg").html("enter atleast 5 chars in the input box");
else
$("#form_elem").submit();
})
</script>
</p>
lexomatic
answered 7 years ago

Since you sent this response, I have updated from version 1.0.0 to version 1.0.7. Are these instructions still accurate? Looking at question-submit-form.php, it appears that the code ends at line 30 instead of line 27. I want to make sure that I don’t break the code. 
Also, I noticed that the error message in the code you sent is “enter at least 5 chars in the input box.” Shouldn’t that say that they can only enter up to 70 characters in the input box? 

Dominic Staff
replied 7 years ago

You can replace the old file with the following code:
Code url link: http://snippi.com/s/urawr5c

Powered by DW Question & Answer Pro