dreamclutch
Programmer
I'm having a bit of trouble with this one. I've got conflicting array brackets and was curious how to break it apart programmatically so that is functions correctly.
The problem exists at the form action below. I'm including javascript at the end of the post action so that it checks the javascript wordFilter function below. That's fine and dandy but the name fields which I'm retrieving ALSO have brackets.
Normally the onsubmit code would look like the following under the form action and would work:
onSubmit="return wordFilter('form1',['word9','word82', 'etc.'])";>
however the names that I need to use include brackets within the text field names, e.g. word[9] and word[82], etc. like below.
onSubmit="return wordFilter('form1',['word[9]','word[82]','etc[]'])";>
Thanks
The problem exists at the form action below. I'm including javascript at the end of the post action so that it checks the javascript wordFilter function below. That's fine and dandy but the name fields which I'm retrieving ALSO have brackets.
Normally the onsubmit code would look like the following under the form action and would work:
onSubmit="return wordFilter('form1',['word9','word82', 'etc.'])";>
however the names that I need to use include brackets within the text field names, e.g. word[9] and word[82], etc. like below.
onSubmit="return wordFilter('form1',['word[9]','word[82]','etc[]'])";>
Thanks
PHP:
<script language="JavaScript">
var swear_words_arr=new Array("badword","badword","badword","badword","badword","badword","badword","badword","badword","badword","badword","badword");
var swear_alert_arr=new Array();
var swear_alert_count=0;
function reset_alert_count()
{
swear_alert_count=0;
}
function wordFilter(form,fields)
{
reset_alert_count();
var compare_text;
var fieldErrArr=new Array();
var fieldErrIndex=0;
for(var i=0; i<fields.length; i++)
{
eval('compare_text=document.' + form + '.' + fields[i] + '.value;');
for(var j=0; j<swear_words_arr.length; j++)
{
for(var k=0; k<(compare_text.length); k++)
{
if(swear_words_arr[j]==compare_text.substring(k,(k+swear_words_arr[j].length)).toLowerCase())
{
swear_alert_arr[swear_alert_count]=compare_text.substring(k,(k+swear_words_arr[j].length));
swear_alert_count++;
fieldErrArr[fieldErrIndex]=i;
fieldErrIndex++;
}
}
}
}
var alert_text="";
for(var k=1; k<=swear_alert_count; k++)
{
alert_text+="\n" + "(" + k + ") " + swear_alert_arr[k-1];
eval('compare_text=document.' + form + '.' + fields[fieldErrArr[0]] + '.focus();');
eval('compare_text=document.' + form + '.' + fields[fieldErrArr[0]] + '.select();');
}
if(swear_alert_count>0)
{
alert("The form cannot be submitted.\nYou f**** cursed. Get ride of these words.:\n_______________________________\n" + alert_text + "\n_______________________________");
return false;
}
else
{
return true;
}
}
</script>
<?
//start of form
<form name="form1" action="/site/index.php" method="post" onSubmit="return wordFilter('form1',['word[9]','word[82]','word[146]','word[176]','word[486]','word[648]','word[805]','word[822]','word[864]','word[877]','word[931]','word[1049]','word[1237]','word[1537]','word[1711]','word[1759]','word[1769]','word[1928]','word[cbarrwentfar]'])";>
//the form fields
<tr><td>An emotion</td><td><input type="textbox" size="10" name="word[864]"></td></tr>
<tr><td>...etc. //othe form inputs with text name fields in the format of word[xxx]
//eventually the submit button
<input type="submit" name="submit">
</form>
?>