Solved

Disable button on php code

Posted on 2011-02-23
13
738 Views
Last Modified: 2012-05-11
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
Comment
Question by:plus_ec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
13 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34962625
just this would do

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


0
 
LVL 1

Author Comment

by:plus_ec
ID: 34962710
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
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34962731
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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 1

Author Comment

by:plus_ec
ID: 34962902
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
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34962922
similarly only

<input type="button" id="btn1" disabled="true"/>
0
 
LVL 1

Author Comment

by:plus_ec
ID: 34963111
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
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 34963140
ok, then

<script>
  document.getElementById("btn1").disabled = "true";
</script>
0
 
LVL 1

Author Comment

by:plus_ec
ID: 34963312
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
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34963478
Try switching
<script language="javascript">
to
<script type="text/javascript">
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34963488
it will work, i am using getElementById, not getElementsByName like you.

Please try the same
0
 
LVL 1

Author Comment

by:plus_ec
ID: 34963740
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
 
LVL 1

Assisted Solution

by:plus_ec
plus_ec earned 0 total points
ID: 34994353
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
 
LVL 1

Author Closing Comment

by:plus_ec
ID: 35034690
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question