Solved

Disable button on php code

Posted on 2011-02-23
13
706 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
  • 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
on window close, not beforeunload 6 21
issue with DB import 1 22
maven not picking latest jar instead picking old jar from .m2 12 24
Why is initialize not a function? 8 26
This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

820 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