how to disable this clickable module after clicking once…..that button should remain disabled after refreshing tha page

huangapple go评论60阅读模式
英文:

how to disable this clickable module after clicking once.....that button should remain disabled after refreshing tha page

问题

<a href="oaccept1.php?id=<?php echo $data['oaid'];?>" class="btn btn-sm btn-primary login-submit-cs" 
onclick="return confirm('Are You Sure')">接受</a>

how to disable this clickable module after clicking once…..that button should remain disabled after refreshing tha page

要在接受后禁用该按钮,并且在接受文档后保持禁用状态。

英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;a href=&quot;oaccept1.php?id=&lt;?php echo $data[&#39;oaid&#39;];?&gt;&quot; class=&quot;btn btn-sm btn-primary login-submit-cs&quot; 
onclick=&quot;return confirm(&#39;Are You Sure&#39;)&quot;&gt;ACCEPT&lt;/a&gt;

<!-- end snippet -->

how to disable this clickable module after clicking once…..that button should remain disabled after refreshing tha page

want to disable that button after accepting that and it should stay disabled after accepting that doc

答案1

得分: 1

使用服务器端,不要仅依赖JavaScript。

在表格中添加一个新字段名为 accepted,并默认设置为假:

ALTER TABLE `tbl_name` ADD `accepted` BOOLEAN DEFAULT FALSE;

在点击接受按钮事件函数时,将此字段设置为真:

INSERT INTO `table_name` (id, accepted) VALUES ('2', TRUE);

然后在您的PHP中使用:

<?php if ($data['accepted'] == FALSE) { ?>
    <a href="oaccept1.php?id=<?php echo $data['oaid']; ?>" class="btn btn-sm btn-primary login-submit-cs" onclick="return confirm('Are You Sure')">ACCEPT</a>
<?php } else { ?>
    <a class="btn btn-sm btn-primary login-submit-cs" disabled>ACCEPT</a>
<?php } ?>

希望这能帮助您。

英文:

Use server side, don't depend on only javascript

In table add new field as accepted and make it false by default,

ALTER TABLE `tbl_name` ADD `accepted` BOOLEAN default false;

on click of accept button event function, set this field as true

INSERT INTO `table_name`(id, accepted) VALUES (&#39;2&#39;,true );

Then in your php have

&lt;?php  if($data[&#39;accepted&#39;]==false){?&gt;
  &lt;a href=&quot;oaccept1.php?id=&lt;?php echo $data[&#39;oaid&#39;];?&gt;&quot; class=&quot;btn btn-sm btn-
     primary login-submit-cs&quot; 
     onclick=&quot;return confirm(&#39;Are You Sure&#39;)&quot;&gt;
     ACCEPT
  &lt;/a&gt;

&lt;?php }else {?&gt;

 &lt;a  class=&quot;btn btn-sm btn-
     primary login-submit-cs&quot; 
     disabled&gt;
     ACCEPT
  &lt;/a&gt;
&lt;?php }?&gt;

hope this will help you

答案2

得分: 0

我建议你将它变成一个按钮,否则谷歌爬虫的简单访问将接受所有内容。

另一种方法是使用表单提交事件。

英文:

I suggest you make it a button, otherwise a simple visit from a google bot will accept all

Alternative is to use a form submit event

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

window.addEventListener(&quot;DOMContentLoaded&quot;, () =&gt; {
  const sub = document.querySelector(&quot;.login-submit-cs&quot;);
  const dis = false; //  localStorage.getItem(&quot;submitted&quot;); // remove &quot;false; //&quot; to activate
  if (!dis) sub.removeAttribute(&quot;disabled&quot;);
  sub.addEventListener(&quot;click&quot;, (e) =&gt; {
    let  tgt = e.target.closest(&quot;button&quot;); // using closest in case the element has children
    if (!tgt || dis) return; // not the link
    setTimeout(() =&gt; tgt.setAttribute(&quot;disabled&quot;,&quot;disabled&quot;),200); // allow the button to be pressed
    // localStorage.setItem(&quot;submitted&quot;,true); // remove comment lines to activate
    location = tgt.dataset.href;
  });
});

<!-- language: lang-html -->

&lt;button data-href=&quot;oaccept1.php?id=&lt;?php echo $data[&#39;oaid&#39;];?&gt;&quot; class=&quot;btn btn-sm btn-primary login-submit-cs&quot; disabled&gt;ACCEPT&lt;/button&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月26日 14:21:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76553995.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定