Insert user fields

Started by cristianlf, January 14, 2011, 09:49:47 PM

Previous topic - Next topic

Gruffen

Well, the validation is going to be needed in shd_save_ticket (which is when the error handling is done) - look for the array building of $context['shd_errors']. Add to that, then it'll trigger being redisplayed to the user. Make sure to repopulate $context['ticket_form'] though so it's put back into the template.

cristianlf

#16
Quote from: Gruffen on January 18, 2011, 05:44:58 PM
Well, the validation is going to be needed in shd_save_ticket (which is when the error handling is done) - look for the array building of $context['shd_errors']. Add to that, then it'll trigger being redisplayed to the user. Make sure to repopulate $context['ticket_form'] though so it's put back into the template.

Thanks for the answer,  I did before you answer but I apreciate your help,  i do something like this:
@SimpleDesk-Post.php
   @shd_save_ticket


if (!isset($_POST['myvariable']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['myvariable'])) === ''
   ||$_POST['producto']=="..." )  // this is because my variables ...
   {
      $context['shd_errors'][] = 'no_myvariable';   // this is the name of the error
      $_POST['myvariable'] = '';
   }

then

@Error.english.php
$txt['no_myvariable']     = 'My Error Message ...';//'';


and then everithing works like a charm :) 


Wel Im traying to write all I done because maybe later I will need it again or  maybe help to someone else.

by the way Im trying to add some function to the text area, I need to limit to a #  and nee to display how characters are remaining,  Im stuck with the display  the remaining chars ... if someone could help  pleaase  !!!


Regards,

Francis

Quote from: cristianlf on January 18, 2011, 08:50:31 PM
Quote from: Gruffen on January 18, 2011, 05:44:58 PM
Well, the validation is going to be needed in shd_save_ticket (which is when the error handling is done) - look for the array building of $context['shd_errors']. Add to that, then it'll trigger being redisplayed to the user. Make sure to repopulate $context['ticket_form'] though so it's put back into the template.

Thanks for the answer,  I did before you answer but I apreciate your help,  i do something like this:
@SimpleDesk-Post.php
   @shd_save_ticket


if (!isset($_POST['myvariable']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['myvariable'])) === ''
   ||$_POST['producto']=="..." )  // this is because my variables ...
   {
      $context['shd_errors'][] = 'no_myvariable';   // this is the name of the error
      $_POST['myvariable'] = '';
   }

then

@Error.english.php
$txt['no_myvariable']     = 'My Error Message ...';//'';


and then everithing works like a charm :) 


Wel Im traying to write all I done because maybe later I will need it again or  maybe help to someone else.

by the way Im trying to add some function to the text area, I need to limit to a #  and nee to display how characters are remaining,  Im stuck with the display  the remaining chars ... if someone could help  pleaase  !!!


Regards,
Displaying the remaining characters can be done with Javascript. Just Google for a characters countdown. :)

Gruffen

Unfortunately it's not as simple as that. That's only a valid solution when WYSIWYG is firmly disabled; if it's not... the textbox will be empty the whole time and the content managed through editing an iframe, which is substituted with the form values at submission.

cristianlf

#19
Well my Friends, I want to share that I did it :)
but I have a Question about  this  function:  "storeCaret(this);"

I don't know what is the purpose of that function so I just erase it ;)

My javascript knowledge is not that good, so Im going to explain what i did maybe some one could help me to improve it :)

First:
@GenericControls.template.php
   @template_control_richedit

before <textarea class ...
add this
<label id="Caracteres">250 caracteres restantes</label><br/>

In texarea tag
change onkeyup="storeCaret(this);"
for this:  onkeyup="showCar(this.value)"

then add maxlength="250"   //the number of characters you want ...

then I review the textarea id to insert it to my javascript ....
/***************JAVASCRIPT***********************/
var xmlHttp

function showCar(str)
{
   alert (str);
   xmlHttp=GetXmlHttpObject()
   if (xmlHttp==null)
   {
      alert ("Browser does not support HTTP Request")
      return
   }
   var textarea =document.getElementById('shd_message')
   var largomaximo =textarea.getAttribute('maxlength')
   
   var url= "http://mysite/Sources/count.php" //"count.php"
   url=url+"?q="+str+"&lm="+largomaximo
   xmlHttp.onreadystatechange=stateChangedChar
   xmlHttp.open("GET",url,true)
   xmlHttp.send(null)
//   alert (str.length+1)
}

function stateChangedChar()
{
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
      var label = document.getElementById('Caracteres')
      label.innerHTML =xmlHttp.responseText
   }
}

function GetXmlHttpObject()
{
   var xmlHttp=null;
   try
   {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
   }
   catch (e)
   {
      //Internet Explorer
      try
        {
           xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
           xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
   }
   return xmlHttp;
}
/***************JAVASCRIPT***********************/

As you see I use count.php  but this is the part  i want to remove but i do not know how ?_? 

this is count.php

/**********count.php*******************/
<?
   $q=$_REQUEST['q'];
   $lm=$_REQUEST['lm'];
   $resta =$lm-strlen($q);
   if ($resta>1)
      $leyenda =" caracteres restantes";
   elseif ($resta==1)
      $leyenda=" caracter restante";
   else
      $leyenda =" caracteres restantes";
   
   echo $resta.$leyenda;
?>

well If there are somethig you can recomend to me please do,

Regards


Gruffen

storeCaret is used by SMF quite a bit, specifically in IE it deals with handling the cursor for the purposes of adding bbcode from buttons as well as smileys... so if you removed it, it's now going to be broken.

:o

Let me explain the problem with that. For every single keypress a user makes in your textbox, that's going to generate a full roundtrip to your server.

Just writing the above, I would have generated 370 requests on your server. 370 connections, 370 page loads. It will overload your server to keep doing that!

You could have gotten the length of content without a server roundtrip but that still wouldn't solve the issue of the fact that neither what I was talking about or the above will work with WYSIWYG which will always report a length of 0 characters.

Why it is so important to keep it within 250 characters? Given that the first three paragraphs I wrote (everything before the 'Just writing the above') is over 50% larger than your 250 character limit, and that there is almost no performance difference between using 250 characters and 25000 in a ticket post, I really have to wonder what the benefit of limiting user post size is?

cristianlf

thanks for your answer,

Well I think that way, but my boss want to limit to 250 because is a way to make users write the main problem withouth unimportant details,
Besides I disable bbc and html editing I need just plain text ... 

if you can help me with the javascript part to be more eficient pleaaase do,

thanks :)

I will try to do it without calling a php file ... do not how but i will :)

Regards,

cristianlf

Ok I did it I erase de PHP file ... this is my function now :)


function showCar(str)
{
   
   
   var textarea =document.getElementById('shd_message')
   var largomaximo =textarea.getAttribute('maxlength')
   var texto =""
   var label = document.getElementById('Caracteres')
      texto =largomaximo-str.length
      var leyenda =" Caracteres Restantes"
      if (texto == 1)
      {
         leyenda =" Caracter Restante"
      }
      label.innerHTML =texto + leyenda
}



Francis

To be honest I would of simply limited the database field to 250 and edited the string for Description to Description (250 characters max.).

Gruffen

If you've disabled WYSIWYG the above function should be fine.

But really 250 characters is not even 2 text messages... it's useless for providing any actual detail and it'll annoy your users more than it'll help your boss because all that'll happen is users either won't use it, or they'll make multiple posts up to get their information across.

(I can't honestly believe too *much* detail is a problem. Too *little* is always more a problem and making it 250 characters encourages them to leave out useful details!)

Gruffen

Fortunately we tackled this in the custom fields implementation; you can set a maximum size on things but otherwise it's 64K characters in length.