Conditional redirect on Submit button

tpascubarat 05 Jul, 2010
I am trying to have 2 submit buttons that will take the user to one of two forms depending on what their needs are.

In the form html, under request_options, I have:
<div class="form_item">
  <div class="form_element cf_text"> <span class="cf_text">This form can be used to Request Assistance or to refer someone to us.</span> </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
    <div class="form_element cf_text"> <span class="cf_text">I am here to:</span> 
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Request assistance for myself or my family" name="submit" type="submit" />
    <input value="Refer someone for assistance" name="submit" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>



My php code is:
<?php
    $submit = JRequest::getString('submit', 'Request assistance for myself or my family', 'post');
    if ( $submit == 'Refer someone for assistance' ) {UNKNOWN CODE
    ?>

The part where I placed "UNKNOWN CODE" is where I feel I am having the problem. I have tried several methods using ELSE, but to no avail.

On the first page with the 2 option buttons, the url is ?option=com_chronocontact&chronoformname=request_option_form

but after I hit either button, it goes to
index.php?option=com_chronocontact&task=send&chronoformname=request_option_form


I have mother_form and this one (request_option_form)

plus

The two forms:

request_assistance and

assistance_referral


Any thoughts or ideas would be appreciated.
GreyHead 06 Jul, 2010
Hi tpascubarat,

Try
<?php
$submit = JRequest::getString('submit', '', 'post');
if ( $submit == 'Refer someone for assistance' ) {
  $formname = 'assistance_referral';
} else {
  $formname = 'request_assistance';
}
global $mainframe;
$mainframe->redirect('index.php?option=com_chronocontact&chronoformname='.$formname);
?>


Bob

Later: fixed a few typos
tpascubarat 06 Jul, 2010
Hi Bob,

After I placed that code in , I get to a blank screen for either button. The debug shows:

1. Form passed first SPAM check OK
2. Form passed the submissions limit (if enabled) OK
3. Form passed the Image verification (if enabled) OK
4. Form passed the server side validation (if enabled) OK
5. $_POST Array: Array ( [submit] => Request assistance for myself or my family [c85f08133f2f01659737998f36a639e6] => 1 [1cf1] => 09b3d6cbd76fe82987cf2bc9a5040796 [chronoformname] => request_option_form )
6. $_FILES Array: Array ( )
7. Form passed the plugins step (if enabled) OK
8. Debug End

and

1. Form passed first SPAM check OK
2. Form passed the submissions limit (if enabled) OK
3. Form passed the Image verification (if enabled) OK
4. Form passed the server side validation (if enabled) OK
5. $_POST Array: Array ( [submit] => Refer someone for assistance [c85f08133f2f01659737998f36a639e6] => 1 [1cf1] => 09b3d6cbd76fe82987cf2bc9a5040796 [chronoformname] => request_option_form )
6. $_FILES Array: Array ( )
7. Form passed the plugins step (if enabled) OK
8. Debug End

The code was placed in the On Submit code - before sending email area although no email will be sent until either of the other forms are sent.
GreyHead 06 Jul, 2010
Hi tpascubarat,

I fixed a few typos.

Bob
tpascubarat 06 Jul, 2010
Thanks Bob,

I did see the 2 errors and still had some small problems. But I remembered reading somewhere before that "email the results" selector still needed to be set to yes even if no emails were created (or needed)
GreyHead 06 Jul, 2010
Hi tpascubarat,

Code in the OnSubmit After Email box will always be executed.

Code in the OnSubmit Before Email box will onlyu be executed if "Send Emails" is set to Yes on the Form General tab - It doesn't matter if any emails are actually being sent or not.

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