how to disable a button with php

I have a button in html like :

<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">

how can I disable that button with php if certain condition meets ?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongSoftware Team LeadCommented:
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary"  <?php if ($yourCondition) { echo " disabled "; }   ?>   >

Open in new window

Terry WoodsIT GuruCommented:
@Ryan's solution will display the button as disabled, however also bear in mind that the user is still able to submit their data if they choose to re-enable the button themselves. That probably means on the server side of your app you should block POST requests that are made when the conditions are met for the button to be disabled.
NerdsOfTechTechnology ScientistCommented:
Also, you might want client-side JavaScript (JS) to toggle enable/disable the submit button, not server-side PHP. Moreover, you could code a user-defined function to validate the information before enabling the button's action. Although, it is highly recommended for the server-side to do the real sanitation/ validation on submit, to avoid attacks.

Not the cleanest approach but hopefully this conveys the idea.

<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary" onclick="validate();">
<span id="warn" style="display: none;">Please check your inputs</span>

Open in new window

function validate(){
// some condition
return true;
// give user an error message and don't sumbit yet
document.getElementById("warn").style.display = "block";
return false;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crescueAuthor Commented:
Tnx for your help. It guided me to the right direction (NerdsOfTech)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.