dtdsbakn210537 2014-02-13 13:50
浏览 39

表单提交时禁用按钮

I made a BlackJack game using only php, and html of course for the layout. But what im trying to say is I need to only use PHP. So no javascript or something else.

My game is near completion, all that's left is the buttons.

I have 3 buttons, Start, Hit and the Stand button. These buttons work with forms, If you click Start it will submit a form where the player draws 2 cards and the dealer 1. Then if you click hit it submits a form where the page will give you 1 card. And by clicking Stand it lets the dealer play, drawing cards untill he hits => 17.

I hope you understand how my system works. (If not please tell me!)

Now when i start the program all buttons except Start needs to be disabled, when i submit the start form (Click the start button) it needs to disable the start button and enable all the others. I find this complicated to achieve since I've never done anything like this before without javascript.

I tried the following:

if (!isset($_SESSION["buttons"])){$_SESSION["buttons"]='disabled';}

This runs at the very start of the form, and in the buttons i echo the session out, so when i start it for the first time it disables all buttons, this works fine.

But when i click start, and run this:

if(FORM_start("Start")){
    buttons();
}

And buttons(); being the following:

function buttons() {
   $_SESSION["buttons"] = '';
}

It doesn't work the first time i click on Start, however if i click start again the other buttons get enabled suddenly.

So this way seems to work, only i need to press start twice, meaning i got 4 cards and the dealer 2.

Is there any way i can let it happen immediately or maybe there is some other way to disable/enable buttons using only PHP.

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • duanluwei9374 2014-02-13 13:54
    关注

    Well, the easiest way to to do is setting up a numeric variable.

    Lets say, it is $hands_played; thus, the starting hand will be 0;

    so, set your session to check is $hands_played = 0, if so, then add attribute disabled="disabled" to the button, if more than 0, don't.

    but, to be honest, please use Javascript.

    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?