Solved

Disable button on php code

Posted on 2011-02-23
13
694 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
Comment Utility
just this would do

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


0
 
LVL 1

Author Comment

by:plus_ec
Comment Utility
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
Comment Utility
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
 
LVL 1

Author Comment

by:plus_ec
Comment Utility
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
Comment Utility
similarly only

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

Author Comment

by:plus_ec
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
Comment Utility
ok, then

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

Author Comment

by:plus_ec
Comment Utility
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
Comment Utility
Try switching
<script language="javascript">
to
<script type="text/javascript">
0
 
LVL 40

Expert Comment

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

Please try the same
0
 
LVL 1

Author Comment

by:plus_ec
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now