How can I display different thank you message based on input

sorin74z 18 Dec, 2008
I have a form where the user can select one of two radio buttons. I want to display a thank you message (On Submit code - after sending email) for the first option selected and another one for the second option. I thought it's something like:

<? php
if (/* some condition */) : ?>
<p>Thank you for choosing option one</p>
<? php else : ?>
<p> Thank you for choosing option two </p>
<? php endif; ?>

Does this look ok? What would the condition be?
GreyHead 18 Dec, 2008
Hi sorin74z,

Yes, that's pretty much it. The condition will depend on the value of a Request variable (assuming that you are using Joomla 1.5). The code will be like this
<?php
$my_var = JRequest::getVar('myvar', ', 'post'); 
if ( $my_var = 'some value' ) {
    echo "<p>Thank you for choosing option one</p>";
} else {
    echo "<p> Thank you for choosing option two </p>";
}
?>

Bob
sorin74z 18 Dec, 2008
Hi Bob,

Thank you for your answer. It seems good, only I seem to have a problem when I try and add any sort of php code in the "On Submit code" section. I even tried:

<? php
echo "<p>Thank you for choosing option one</p>";
?>

and still get nothing displayed. If I don't use php (for example just write <p>Thank you for your reply</p>) it works fine, but with php nothing seems to happen. Could I have some wrong setting somewhere?

Thanks,
Sorin

PS: I'm using joomla 1.5
GreyHead 19 Dec, 2008
Hi sorin74z,

I didn't notice before but there is an extra space in the php tag - should be <?php - with no spaces. I don't think this is the problem though. Please can you post here the whole of the code you have in the OnSubmit Box.

Bob
sorin74z 19 Dec, 2008
Hi Bob,

Thank you very much for the suggestion. I only tried the code I posted and it didn't work before, but once I removed the space between <? and php it worked fine.

So finally I have:
<?php
$my_var = JRequest::getVar('my_var', 'post');
if ( $my_var == 'option one' ) {
    echo "<p>You chose option one</p>";
} else {
    echo "<p>You chose another option</p>";
}
?>
This works fine.

Many thanks,
Sorin
dannyh 22 Mar, 2009
Using this code above..how would you handle this is people have more options to choose from in different fields?

I asume that you have
option 1 values 1 or 2

now I have
option1 values 1 2 3
option2 values a b c
option3 values aq de 4r

etc..
how could I the below and still display the right message?
GreyHead 22 Mar, 2009
Hi DannyH,

Is every combination possible i.e. do you have different messages for each of 1+a+aq, 2+a+aq, 3+a+aq, 1+b+aq, 2+b+aq, . . . that's a lot of messages (27 I think). Or is there some grouping?

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