Two submit buttons – one submits on self, another submits into a popup

Notice: This thread is very old.
richard
Member | 60
+
0
-

Hi,

one submit button submits as normally while another one opens a popup and submits into there. Both validate the form first.

What is the practice?

Thanks.

Nox
Member | 378
+
0
-

Since popup is dependant on JavaScript and considering posibility of displaying without CSS, in screenreader etc. so imho make this a presentation-only thing with progressive enhancement.

→ mark the submit with class/rel/data/whatever and then in JS you would copy it, assign it a handler (different one from the original submit if it used any). Perhaps you could use the data attribute so that you can pass a different title from the server, more useful in multilingual apps

Never much dealt with popups so 'm not sure if this “submitting into popup” is possible

Jan Tvrdík
Nette guru | 2595
+
0
-

You can submit the form via AJAX and then open the popup.

richard
Member | 60
+
0
-

Sorry, I have no idea what is “make this a presentation-only thing with progressive enhancement” and how to “submit the form via AJAX and then open the popup”. A code example would do it.

<form>
	<input type=submit onClick="setWhatToDoOnFormSubmit()"; value="1" />
	<input type=submit onClick="setWhatToDoOnFormSubmit2()"; value="2" />
</form>

I know it is not going to be that simple…

Last edited by richard (2011-08-29 19:44)

HosipLan
Moderator | 4668
+
0
-

If that's all you need, here it is:

$form->addSubmit('one', 'Action one')
	->controlPrototype->onClick('setWhatToDoOnFormSubmit()');

$form->addSubmit('two', 'Action two')
	->controlPrototype->onClick('setWhatToDoOnFormSubmit2()');
richard
Member | 60
+
0
-

cool. you are the man.

richard
Member | 60
+
0
-

Just to particularize:

<script>
function setWhatToDoOnFormSubmit()
{
	var form = document.getElementById("frm-form");
	form.onSubmit ="window.open(...)";'
	form.target = "preview";
}
</script>

I do not need to worry about javascript being off as this is intranet… But at worst it would submit on same window which is not too bad.

Last edited by richard (2011-08-30 06:48)

richard
Member | 60
+
0
-

For anyone who tries to follow up: after trying to implement this I found out that this is not very reliable solution. I ended up with setting new action in presenter. In this action I send javascript to the template. Something like this:

<?php
....
public function handleOpenPopup() {
	... save form values to session first so you can use it in the popup
	$this->template->additionalScript = 'window.open(...);'
}
?>

Last edited by richard (2011-09-12 04:58)