I have a form and I want it to only show completed fields in the emails that are sent to the person who submitted the form.
Heres an example code to go in "OnSubmit - after email":
Let's say you fill out everything except email2, then I dont want that table row (3rd row in my example above) to show at all in the resulting mail and thank you page. There's only a few of the fields that I need to check if they are empty or not, rest of them are requiered fields (and thus they need no checking).
I guess it should be some if-statement like
...if ($_POST['email2'] != NULL) then write the table row
else carry on with the next row...
How can I implement this in the above code? I'm a php novice...
I'm using Joomla 1.0.15 and ChronoForms 2.3.9
Heres an example code to go in "OnSubmit - after email":
<?php
$recipient = $_POST['email'];
$ccemails = $_POST['email2'];
$subject = "My subject";
$html_message = "<h1>My thank you page</h1>
<p>Thank you <strong>".$_POST['fname']."</strong>, for filling out my form.</p>
<br />
<table>
<tr><td>First name: </td><td>".$_POST['fname']."</td></tr>
<tr><td>1st email: </td><td>".$_POST['email']."</td></tr>
<tr><td>2nd email: </td><td>".$_POST['email2']."</td></tr>
<tr><td>City: </td><td>".$_POST['city']."</td></tr>
<tr><td>Country: </td><td>".$_POST['country']."</td></tr>
</table>";
mosMail($from, $fromname, $recipient, $subject, $html_message, true, $ccemails, $bccemails, $attachments, $replyto_email, $replyto_name );
echo $html_message; ?>
Let's say you fill out everything except email2, then I dont want that table row (3rd row in my example above) to show at all in the resulting mail and thank you page. There's only a few of the fields that I need to check if they are empty or not, rest of them are requiered fields (and thus they need no checking).
I guess it should be some if-statement like
...if ($_POST['email2'] != NULL) then write the table row
else carry on with the next row...
How can I implement this in the above code? I'm a php novice...
I'm using Joomla 1.0.15 and ChronoForms 2.3.9
The row will be:
Cheers
Max
<?php if($_POST['email2']){ ?><tr><td>2nd email: </td><td>".$_POST['email2']."</td></tr><?php } ?>
Cheers
Max
That doesn't work... Maybe it's because I start the template with <?php ... and end it with ?> so I guess you can not put another php start- and endtags inside of those... ๐คจ
Hi ProEventMedia,
No you don't need to nest <?php . . . ?> tags, and doing so will cause an error. If they are open, then you write in php, if they are closed then you write ordinary html.
Bob
No you don't need to nest <?php . . . ?> tags, and doing so will cause an error. If they are open, then you write in php, if they are closed then you write ordinary html.
Bob
yeah, so my code should be:
if($_POST['email2']){ ?><tr><td>2nd email: </td><td>".$_POST['email2']."</td></tr><?php }
Hi,
I think the final <?php needs to be chopped off too. Because this gets so messy I prefer to use a slightly different syntax and build up the variable bits first.
Bob
I think the final <?php needs to be chopped off too. Because this gets so messy I prefer to use a slightly different syntax and build up the variable bits first.
<?php
. . .
$second_email = ""; // declare variable to prevent PHP notices
if ( $_POST['email2'] ) {
$second_email = "<tr><td>2nd email: </td><td>".$_POST['email2']."</td></tr>";
}
$html_message = "<h1>My thank you page</h1>
<p>Thank you <strong>".$_POST['fname']."</strong>, for filling out my form.</p>
<br />
<table>
<tr><td>First name: </td><td>".$_POST['fname']."</td></tr>
<tr><td>1st email: </td><td>".$_POST['email']."</td></tr>
$second_email
<tr><td>City: </td><td>".$_POST['city']."</td></tr>
<tr><td>Country: </td><td>".$_POST['country']."</td></tr>
</table>";
. . .
?>
This way the code is clear and the line will be completely omitted if it is empty.Bob
Great Bob, I didn't pay attention to the string..
@ProEventMedia, use Bob's code, mine will not work because we are inside a string, unless you terminate and continue the string before and after the line!
Cheers
Max
@ProEventMedia, use Bob's code, mine will not work because we are inside a string, unless you terminate and continue the string before and after the line!
Cheers
Max
Okey, I used Bobs code and it worked!๐
Thank you for all your help!
Now I just need to figure out how to make it work with JoomFish...
Thank you for all your help!
Now I just need to figure out how to make it work with JoomFish...
This topic is locked and no more replies can be posted.