• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 845
  • Last Modified:

Disable button on php code

Hi,
I have a button called ''btn_finalizar'' this button is disable=false, so, what I want is to after the php code, the button ''btn_finalizar'' get disabled=true. After this if statement: if ($res >= 2 && $form->submitter >= 0 ) {

$username = $_POST['curso_boxmax'];
	if ($username == "1er Ciclo") {
		if ($res >= 2 && $form->submitter >= 0 ) {
		$form->page = 2;
		}
			if ($res >= 1 && $form->submitter >= 0 ) {
			$form->error = "Usted ya ha completado la evaluación de los docentes del 1er Ciclo, usted no podrá llenar más!!!";
	?>
			<script language="javascript">
              		var btn_finalizar = document.getElementsByName('btn_finalizar')[0];   
		   	if (btn_finalizar) btn_finalizar.disabled = true;
			</script>
	<?php
}

}

Open in new window

I do not know how to disable the button in php code, the above code does not work for me.
Thanks.
0
plus_ec
Asked:
plus_ec
  • 7
  • 5
2 Solutions
 
Gurvinder Pal SinghCommented:
just this would do

<body>
<input type="text" id="text1" disabled="true"/>
</body>


0
 
plus_ecAuthor Commented:
sorry, but, I do not understand, could you please be more detailed?
Or I don't know if I misunderstand my question?
Thanks for reply.
0
 
Gurvinder Pal SinghCommented:
i am trying to say that you dont need javascript to disable the textbox, if the textbox has to be disabled at the page load event itself
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
plus_ecAuthor Commented:
Thanks,
But in my question I said that is a button, not a texbox.

The whole code is this:
$form->data['user_id'] = &JFactory::getUser()->id;
$db_name =  $form->formXMLStruct['database']['name'];

$query = "select count(id) from $db_name where user_id={$form->data['user_id']}";
$database = &JFactory::getDBO();
$database->setQuery($query);
$res = $database->loadResult();
if ($res == null) die($query);

$username = $_POST['curso_boxmax'];
	if ($username == "1er Ciclo") {
		if ($res >= 2 && $form->submitter >= 0 ) {
		$form->page = 2;
		}
			if ($res >= 1 && $form->submitter >= 0 ) {
			$form->error = "Usted ya ha completado la evaluación de los docentes del 1er Ciclo, usted no podrá llenar más!!!";

	/* Here is where I need to enabled ''btn_finalizar'' button
}
}	

Open in new window


so, if user has submit more than 2 form, he is redirect to a specific page and the error message is displayed, and at same time I need to enabled ''btn_finalizar'' button.(this is what I need).
The ''btn_finalizar'' is not the default submit button, this is another submit button that allow me redirect users to different pages.
Tnks

0
 
Gurvinder Pal SinghCommented:
similarly only

<input type="button" id="btn1" disabled="true"/>
0
 
plus_ecAuthor Commented:
Ok, Thanks, but sorry,
This is not what I need, As i said I need to disable button after the ''if'' sentence is done. Or better said, I need to disable button when the sentence is done.
The button by default is enabled on pageload, so, what I need is to disable button after the php code has done his job after ''if'' sentence.
I'm working on joomla, specifically with smartformer gold plugin. This plugin allow to design form with drag and drop, and allow to insert php, javascript and html code, but these code works in different windows.
0
 
Gurvinder Pal SinghCommented:
ok, then

<script>
  document.getElementById("btn1").disabled = "true";
</script>
0
 
plus_ecAuthor Commented:
Thanks, but, Actually, I was trying this from the beginning, but not working.
Is as if javascript do not load inside php code, after ''if'' sentence. I don't know why?
0
 
Lukasz ChmielewskiCommented:
Try switching
<script language="javascript">
to
<script type="text/javascript">
0
 
Gurvinder Pal SinghCommented:
it will work, i am using getElementById, not getElementsByName like you.

Please try the same
0
 
plus_ecAuthor Commented:
Roads_Roads
I'm was trying to switching the tags, but it's do not work.

gurvinder372
From beginning I added id tag to buttons to use different ways, including yours, but it's do not work.

Another suggestions?
0
 
plus_ecAuthor Commented:
For an unknow reason, the smartformer plugin does not allow to insert javacript code inside php code, so, I did the following:
As you can see in this code I restrict form submissions.
$form->data['user_id'] = &JFactory::getUser()->id;
$db_name =  $form->formXMLStruct['database']['name'];
$query = "select count(id) from $db_name where user_id={$form->data['user_id']}";
$database = &JFactory::getDBO();
$database->setQuery($query);
$res = $database->loadResult();
if ($res == null) die($query);
echo "<input type='text' id='res' name='res' value='{$res}' readonly='readonly' style='position:absolute; width:15px; height:16px; font-size:10px; visibility: hidden;'>";  

$username = $_POST['curso_boxmax'];
	if ($username == "1er Ciclo") {
		if ($res >= 8 && $form->submitter >= 0 ) {
		$form->page = 2;
		$form->error = "error message here!!!";
		}
}		

Open in new window

In the "echo", the variable $res, I put the value in a texbox with HTML code.
And in the javascript windows I did the following:
 I get the value of the variable $rest, and if $res==8, this are number of form submission, I disable button.
var n1 = document.getElementById("res");
if (n1.value == "7"){
document.getElementById("btn_finalizar").disabled = "true";
alert("error message here");
}
}

Open in new window

Thanks all for help, all you answers were Ok, but, the problem is in the plugin.
No one could answer my question in smartformer gold plugin, so, I can't divide Point, because no one reply was addressed to my question in joomla.
0
 
plus_ecAuthor Commented:
No one could answer my question in smartformer gold plugin, so, I can't divide Point, because no one reply was addressed to my question in joomla.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now