Jump to content

Recommended Posts

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.

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.

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

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.

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.

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.

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

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.