tecate1 Posted August 20, 2009 Share Posted August 20, 2009 i purchased a script that meets almost all of my needs with the exception of two things. First, I'd like to limit the number of characters in the commenting to 140 characters. At present it has no limit. Second, I want to allow the post to be posted immediately if they are logged in. At present, the submissions have to be moderated. I would like to moderate only the submissions from those who are not logged in. The website is http://MemphisDirt.com Any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/171177-need-to-limit-the-character-count-to-140-in-a-text-area/ Share on other sites More sharing options...
Daniel0 Posted August 20, 2009 Share Posted August 20, 2009 First, I'd like to limit the number of characters in the commenting to 140 characters. At present it has no limit. if (strlen($string) > 140) { echo 'too long'; } Second, I want to allow the post to be posted immediately if they are logged in. At present, the submissions have to be moderated. I would like to moderate only the submissions from those who are not logged in. Then remove the part that makes it moderated. Quote Link to comment https://forums.phpfreaks.com/topic/171177-need-to-limit-the-character-count-to-140-in-a-text-area/#findComment-902696 Share on other sites More sharing options...
mikesta707 Posted August 20, 2009 Share Posted August 20, 2009 you could also set the max length via javascript, but you may also want to use PHP as javascript can be disabled client side. However, the javascript option may make it a little less tedious for a user, so they don't accidently tyoe say 141 characters, and have to go back to the previous page again. But its all personal preference really. You could also use javascript to dynamically show the amount of characters left that they can type Quote Link to comment https://forums.phpfreaks.com/topic/171177-need-to-limit-the-character-count-to-140-in-a-text-area/#findComment-902699 Share on other sites More sharing options...
tecate1 Posted August 20, 2009 Author Share Posted August 20, 2009 I just started taking the essentials training from Lynda dot com site, so I am not a coder, but I can navigate around the code pretty well. So where should I put the php code to limit the string length? Thanks a great deal for the help. Quote Link to comment https://forums.phpfreaks.com/topic/171177-need-to-limit-the-character-count-to-140-in-a-text-area/#findComment-902708 Share on other sites More sharing options...
Daniel0 Posted August 20, 2009 Share Posted August 20, 2009 We cannot really tell. You would check the length immediately before inserting it into the database. It is probably doing some other sort of validation during the form processing. If you have absolutely no experience with programming whatsoever, you should start a simpler project though. Quote Link to comment https://forums.phpfreaks.com/topic/171177-need-to-limit-the-character-count-to-140-in-a-text-area/#findComment-902713 Share on other sites More sharing options...
Eiolon Posted August 20, 2009 Share Posted August 20, 2009 You need to put it after the line of code that starts the form submission. So when you are sanatizing all your fields, when you get to that particular field, also include the code Daniel0 posted. Quote Link to comment https://forums.phpfreaks.com/topic/171177-need-to-limit-the-character-count-to-140-in-a-text-area/#findComment-902716 Share on other sites More sharing options...
tecate1 Posted August 20, 2009 Author Share Posted August 20, 2009 I have this code from the submit.php </head> <body> <?php if($_POST['submit']){ if(!isset($_SESSION['user']['username'])) $username = "Anonymous"; else $username = $_SESSION['user']['username']; @$query = mysql_query("INSERT INTO `comps`(time,message,accepted,votes1,votes2,via,user,cat,numcoms,subcat) VALUES ('". time() ."', '". clean($_POST['comp']) ."', 'No', 0, 0, 'internet', '". $username ."', '". clean($_POST['cat']) ."', '0', '0')") or die(mysql_error()); echo "<strong>Your submission has been received!</strong> <script type=\"text/javascript\"><!-- setTimeout('Redirect()',1000); function Redirect() { opener.location.href='./'; window.close(); } // --></script>"; } else { echo ' <form action="" method="POST"> <table id="submissionform"> <tr><td class="input" colspan=5> <textarea onfocus="javascript:document.getElementById(\'commbox\').innerHTML=\'\';" name="comp" rows="13" height="75" cols="20" id="commbox">'. $names[4] .'</textarea> </td></tr> <tr><td> <select name="cat"> '; while($category = current($catlist)){ echo '<option value="'. key($catlist) .'">'. current($catlist) .'</option>'; next($catlist); } echo ' </select></td></tr> <tr><td><input type="submit" name="submit" value="Submit!" class="button_login2" /> </td></tr> </table> </form>'; } ?> </body> </html> and I have this from submitCompliment.php <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ header("Content-Type: text/xml;charset=UTF-8"); include('header.php'); if(!isset($_SESSION['user']['username'])) { $username = "Anonymous"; } else { $username = $_SESSION['user']['username']; } $query = mysql_query("INSERT INTO `comps`(time,message,accepted,votes1,votes2,via,user,cat,numcoms,subcat) VALUES ('". time() ."', '". clean($_POST['comp']) ."', 'No', 0, 0, 'internet', '". $username ."', '". clean($_POST['cat']) ."', '0', '0')"); if($query) { $result = "Ok"; } else { $result = "Nok"; } ?> <code><?php echo $result; ?></code> I would think that one of these would be the place to put the code to limit the characters to 140. Also, what specifically should I add? Thanks again for your help. This is an awesome language, and I look forward to learning it. Quote Link to comment https://forums.phpfreaks.com/topic/171177-need-to-limit-the-character-count-to-140-in-a-text-area/#findComment-902732 Share on other sites More sharing options...
mikesta707 Posted August 20, 2009 Share Posted August 20, 2009 after this if($_POST['submit']){ if(!isset($_SESSION['user']['username'])) $username = "Anonymous"; else $username = $_SESSION['user']['username']; put what daniel0 said. so something like if($_POST['submit']){ if(!isset($_SESSION['user']['username'])) $username = "Anonymous"; else $username = $_SESSION['user']['username']; if (strlen($_POST['comp']) > 140) { echo 'too long'; exit(); } @$query = mysql_query("INSERT INTO `comps`(time,message,accepted,votes1,votes2,via,user,cat,numcoms,subcat) VALUES ('". time() ."', '". clean($_POST['comp']) ."', 'No', 0, 0, 'internet', '". $username ."', '". clean($_POST['cat']) ."', '0', '0')") or die(mysql_error()); by the way that code is a mess Quote Link to comment https://forums.phpfreaks.com/topic/171177-need-to-limit-the-character-count-to-140-in-a-text-area/#findComment-902736 Share on other sites More sharing options...
tecate1 Posted August 20, 2009 Author Share Posted August 20, 2009 Well, that didn't work. I commented with a batch of Lorem Ipsum and it allowed it. I'm just curious, there were curly brackets before and after the snippet of code that I entered in, but in the original code that whole batch of code, (line 1 through line 10) was in one set of brackets, could that have broken the code or allowed it not to work as you had planned? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/171177-need-to-limit-the-character-count-to-140-in-a-text-area/#findComment-902749 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.