SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast Phyxas's Avatar
    Join Date
    Mar 2010
    Location
    Houston, TX
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Disable Element by PHP if-statement

    Hey, as the summary already states, I want to disable an HTML-Element with PHP if an action occurs. For example I have a simple input button, and if the input button has been clicked 5 times, it is being disabled.

    If anyone has an idea, please help.

    Regards,

    Phyxas

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You're going to have to supply some more details. Is the input button going to refresh the page? If so, we can count the clicks with PHP and then disable the button by adding the "disabled" attribute with PHP before spitting the HTML out. If not, we need to count with JS and PHP has nothing to do with this, and we can disable the button with JS.

    What the point of this is might help as well.

  3. #3
    SitePoint Enthusiast Phyxas's Avatar
    Join Date
    Mar 2010
    Location
    Houston, TX
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code PHP:
          if ($_POST['rock'] * 5) {
              // action for disabling the input class ".inputButtons1"
          }
          else {
          }

    Inside the if-statement, it should somehow work to disable the element with jQuery or JavaScript, and else do nothing.

  4. #4
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you want to use javascript, you can get php to echo out the javascript to set the element's "disabled" property to true to disable it or false to enable it.

  5. #5
    SitePoint Enthusiast Phyxas's Avatar
    Join Date
    Mar 2010
    Location
    Houston, TX
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And that's what I was trying to do, but don't know how..

  6. #6
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This w3schools tutorial might help.

  7. #7
    SitePoint Enthusiast Phyxas's Avatar
    Join Date
    Mar 2010
    Location
    Houston, TX
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This wouldn't work, since I can't disable it right away after it has been clicked. I need to disable it by an PHP if-statement, and as you said printing out the JS or jQuery by an echo is more useful..

  8. #8
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep, that tute just shows how to use javascript to disable/enable elements.

    In your application you would have to get php to echo out the appropriate javascript, based on the tute, in an IF block or whatever.

    Otherwise, if you are refeshing the page on each click and don't want to use javascript, you can count the clicks in PHP (as opposed to counting them in javascript) and then after a certain number of clicks (stored in a session variable) you can get php to not output the html to display the element.

    Personally, if each button click is refreshing the page I wouldn't bother using javascript at all and just store the click count in a session variable as mentioned above.

  9. #9
    SitePoint Addict skunkbad's Avatar
    Join Date
    Apr 2008
    Location
    Temecula, CA
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have forms on my website that make it impossible to click the submit button if certain form elements don't validate. I think this is the appropriate way to limit submissions. If you have somebody that keeps submitting again and again, you should try setting a form token, which involves a cookie/session. Also, you will need to validate all of your form input with php, and re-populate the form as needed.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •