1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How can I filter text field by keywords through php $_POST

Discussion in 'PHP' started by umarpk, Feb 24, 2012.

  1. #1
    I have a form having text fields and text areas. I want to filter keywords , for example I have a contact form if some use to fill the form and clicks on submit, the form should be submited as normal, at this stage the php code should analyse that the name field should not contain any keywords which is already instructed to php code and if that keyword in the feild or text area found, it should return an error instead of send an email to the webmaster.


    Any help will be appreciated and thanks in advance.
     
    umarpk, Feb 24, 2012 IP
  2. Lee Stevens

    Lee Stevens Peon

    Messages:
    148
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #2
    This should give you a head start :)
    PHP:
    1.  
    2. <?php
    3. $word_not_aloud = array("word", "word1", "word2");
    4.  
    5. if (in_array($_POST['name'], $word_not_aloud))
    6. {
    7.     echo "Error can not use that word.....";   
    8. } else
    9. {
    10.     // continue with submitting the email  
    11. }
    12. ?>
    13.  
     
    Lee Stevens, Feb 24, 2012 IP
  3. umarpk

    umarpk Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Lee, You really helped me but please make little alteration in the code, let me explain it,

    This code is okay if I use to submit only one keyword same as in the array which is already specified, but when i uses more keywords and in among the text there is a spam keyword , it is unable to findout.

    for example, there is value of $_POST['name'] = "This is key word."
    In the above line you have noticed that there a spam keyword "word" I need a code which will point out and find automaticaly from a line or paragraph and should filter it.

    Thanks, hope you can understand me. waiting for reply.

     
    umarpk, Feb 24, 2012 IP
  4. Lee Stevens

    Lee Stevens Peon

    Messages:
    148
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #4
    I'm confused what your trying to ask.

    If the keyword is in $_POST['name'], regardless if a sentence or one word it wont display it.
     
    Lee Stevens, Feb 24, 2012 IP