Problems trying to add onclick on submit button with generate_submit_button method
#1
I'm developing some custom stuff at ACP and I can't add an "onclick" ettiquete over the HTML of the button.

$buttons[] = $form->generate_submit_button("Submit",array('onclick' => "return confirm('Are you sure?');"));

But the onclick just doesn't get print. I've also trying adding a simple "name" but it didn't work too.
Reply
#2
you can't use a submit input, try with a button input or with a simple button and after confirm post the form with jQuery
My Projects - Support My Projects

Don't forget to rate posts!
Reply
#3
I've found the source code of the generate_submit_button code, and onclick should work!!! But it doesn't

	function generate_submit_button($value, $options=array())
	{
		$input = "<input type=\"submit\" value=\"".htmlspecialchars_uni($value)."\"";

		if(isset($options['class']))
		{
			$input .= " class=\"submit_button ".$options['class']."\"";
		}
		else
		{
			$input .= " class=\"submit_button\"";
		}
		if(isset($options['id']))
		{
			$input .= " id=\"".$options['id']."\"";
		}
		if(isset($options['name']))
		{
			$input .= " name=\"".$options['name']."\"";
		}
		if(isset($options['disabled']))
		{
			$input .= " disabled=\"disabled\"";
		}
		if(isset($options['onclick']))
		{
			$input .= " onclick=\"".str_replace('"', '\"', $options['onclick'])."\"";
		}
		$input .= " />";
		return $input;
	}

Edit:

I've found the solution. The problem was in the quotes... I just changed my code to:
$buttons[] = $form->generate_submit_button("Submit",array('onclick' => 'return confirm(\'Are you sure?\');'));
And it worked!
Reply
#4
Thanks for posting the solution so others who have this same question can figure it out.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)