Forums

2 buttons, two different outcomes when pressed

ajw3208 03 Jun, 2009
Hi,

I've been searching the forums on this issue but I can't locate a precise answer so hence the new post.

I understand how to get a form to submit and move to another form. The quesiont is:

how do you get a second button on the same form to perform a different action?

e.g. submit = submit. exit button goes to a different form or it may close the window?

any ideas?

aj
nml375 03 Jun, 2009
Untested, but should work from memory:
... Your name: <input type="text" name="fullname" /><br />
<input type="submit" name="sbutton" value="Submit data" /> or <input type="submit" name="sbutton" value="Exit" />


And "on Submit (after email)":
<?
$action = JRequest::getString('sbutton');
if (strcasecmp($action, 'submit data') != 0) {
  //Redirect to some other url...
  $t =& JFactory::getApplication('site');
  $t->initialise();
  $t->redirect('http://www.somehost.com/somewhere.html');
}


/Fredrik
ajw3208 03 Jun, 2009
Thanks Fredrik,

I'll give it a run and advise.

aj
GreyHead 04 Jun, 2009
Hi aj,

From memory there may be some problems in IE with submit buttons that don't have name='submit' - if you find problems try changing this.

Bob
ajw3208 08 Jun, 2009
Thanks Bob,

I'll look out for that. Almost none of my buttons use "submit" as name.

aj
ajw3208 08 Jun, 2009
Fredrik,

Thanks for the code snippet. Worked a treat.

aj
ajw3208 08 Jun, 2009
Hi Bob,

Just a bit of feedback on your previous heads-up re: IE.

It (the form solution) seems to work OK on IE8. (yes, brave really, but you have to test on as much as possible ):) IE7 has all sorts of issues but I think I need to revisit my newbie PHP code before I assign blame to MS (as much as I'd like to ) :wink:

aj
GreyHead 08 Jun, 2009
Hi ajw3208,

Sounds good. Just in case it's helpful - I have recently discovered IETester which is a very neat browser-like application that loads multiple IE emulators at the same time IE5,5, 6, 7, & 8. It even makes debugging a little easier.

Bob
ajw3208 10 Jun, 2009
Hi Bob,

The code below works really well if you need to redirect.

what does it look like if you need an alternate form action URL? What is the best way to modify the code below to create an alternate form action. Use case is

press submit btn #1 on form4 and on submit form action = ......regoform5
press submit btn#2 on form 4 and on submit form action = .......regoholder (the loop action). This is the one that needs to maintain the $_POST array

regards,

aj

p.s. Yes, this is same question is in the chaining post as the two issues stem from the same form🙂

<?php
$action = JRequest::getString('rf4sBtn');
if (strcasecmp($action, 'Next') == 0) {
  //Redirect to some other url...
  $t =& JFactory::getApplication('site');
  $t->initialise();
  $t->redirect('index.php?option=com_chronocontact&chronoformname=regoform1');
}
?>
ajw3208 10 Jun, 2009
forgot to say thanks for the IE tester😶

Thanks

aj
GreyHead 10 Jun, 2009
Hi aj,

The multipage plugin uses this syntax
$nextForm->showForm('form_name', $posted);
I think that $MyForm would probably work as well.

Bob
ajw3208 10 Jun, 2009
Hi Bob,

Oops, it went Bang!.

this is the error.

Fatal error: Call to a member function showForm() on a non-object in /home/wphcfc/public_html/z-wphctesting/components/com_chronocontact/libraries/customcode.php(42) : eval()'d code on line 8

This is the code in On Submit code - after sending email:

There is no URl in on submit in form URL tab of the form.

Pretty sure I'm doing something wrong but not sure what

aj

<?php
$action = JRequest::getString('rf4sBtn');
if (strcasecmp($action, 'Next') != 0) {
  //Redirect to some other url...
  //$t =& JFactory::getApplication('site');
  //$t->initialise();
  //$t->redirect('index.php?option=com_chronocontact&chronoformname=regoholder');
     $t->showForm('regoholder', $posted);
}
?>
GreyHead 10 Jun, 2009
Hi aj,

$t isn't defined so the bang is correct . . . please try it with $MyForm->

Bob
ajw3208 16 Jun, 2009
Thanks Bob,

works now.
This topic is locked and no more replies can be posted.