Page 1 of 1
I think this is Nested PHP?
Posted: Thu Jul 29, 2010 2:10 pm
by markosjal
I know I have done this before however I seem to have a mental block and can not find where I may have done it so examples are appreciated.
I have a webform that should not show some components if a user is not logged in so I want to show those fields only when in admin or a user is logged in. I know this is not right and I am most certainly fouling up on the quotes and nested PHP.
Code: Select all
<td>
<?php if ($in_admin || $logged_in)
{echo '
<input name="showemail" type="radio" value="0"''<?php if(isset($data['showemail']) && $data['showemail']==EMAIL_HIDE) echo "checked";
?> '>'</td>;
else
{
echo $somevariable;
} ?>
Any help appreciated
Re: I think this is Nested PHP?
Posted: Thu Jul 29, 2010 2:19 pm
by Jade
You can't have php tags inside of each other. You also have several syntax errors.
Code: Select all
<td>
<?php if ($in_admin || $logged_in)
{
echo '<input name="showemail" type="radio" value="0"';
if(isset($data['showemail']) && $data['showemail']=='EMAIL_HIDE') echo " checked";
echo '>';
}
else
echo $somevariable;
?>
</td>
Re: I think this is Nested PHP?
Posted: Thu Jul 29, 2010 2:21 pm
by shawngoldw
try
Code: Select all
<td>
<?php
if ($in_admin || $logged_in)
{
echo '<input name="showemail" type="radio" value="0"';
if(isset($data['showemail']) && $data['showemail']==EMAIL_HIDE) echo " checked";
echo ' />';
else
{
echo $somevariable;
}
?>
</td>
You can't put a <?php tag in another <?php tag. that doesn't work
edit: looks like I got beat to the reply
Re: I think this is Nested PHP?
Posted: Thu Jul 29, 2010 3:23 pm
by markosjal
I tried this,
Code: Select all
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<td><?php
if ($in_admin || $logged_in)
{
echo '<input name="showemail" type="radio" value="0"';
if(isset($data['showemail']) && $data['showemail']==EMAIL_HIDE) echo " checked";
echo ' />';
?>
</td>
</tr>
<tr>
<td><input name="showemail" type="radio" value="2" <?php if(!isset($data['showemail']) || $data['showemail']==EMAIL_USEFORM) echo "checked"; ?>></td>
<td><?php echo $lang['POST_EMAILOPTION_USEFORM']; ?></td>
</tr>
<tr>
<td><input name="showemail" type="radio" value="1" <?php if($data['showemail']==EMAIL_SHOW) echo "checked"; ?>> </td>
<td><?php echo $lang['POST_EMAILOPTION_SHOW']; ?></td>
</tr>
</table>
the original code was
Code: Select all
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<td><input name="showemail" type="radio" value="0" <?php if(isset($data['showemail']) && $data['showemail']==EMAIL_HIDE) echo "checked"; ?>></td>
<td><?php echo $lang['POST_EMAILOPTION_HIDE']; ?></td>
</tr>
<tr>
<td><input name="showemail" type="radio" value="2" <?php if(!isset($data['showemail']) || $data['showemail']==EMAIL_USEFORM) echo "checked"; ?>></td>
<td><?php echo $lang['POST_EMAILOPTION_USEFORM']; ?></td>
</tr>
<tr>
<td><input name="showemail" type="radio" value="1" <?php if($data['showemail']==EMAIL_SHOW) echo "checked"; ?>> </td>
<td><?php echo $lang['POST_EMAILOPTION_SHOW']; ?></td>
</tr>
</table>
And the page fails to load,
Re: I think this is Nested PHP?
Posted: Thu Jul 29, 2010 3:35 pm
by shawngoldw
try
Code: Select all
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<td><?php
if ($in_admin || $logged_in)
{
echo '<input name="showemail" type="radio" value="0"';
if(isset($data['showemail']) && $data['showemail']==EMAIL_HIDE) echo " checked";
echo ' />';
}
?>
</td>
</tr>
<tr>
<td><input name="showemail" type="radio" value="2"
<?php if(!isset($data['showemail']) || $data['showemail']==EMAIL_USEFORM) echo "checked"; ?>></td>
<td><?php echo $lang['POST_EMAILOPTION_USEFORM']; ?></td>
</tr>
<tr>
<td><input name="showemail" type="radio" value="1" <?php if($data['showemail']==EMAIL_SHOW) echo "checked"; ?>> </td>
<td><?php echo $lang['POST_EMAILOPTION_SHOW']; ?></td>
</tr>
</table>
you're missing a }
also turn on error reporting, it will tell you where you're error is
Re: I think this is Nested PHP?
Posted: Fri Jul 30, 2010 1:44 pm
by markosjal
Thanks for the help on this howeever there were too many errors for my stupidity and the complexity of all of the code that needed to be edited. It was easier to make if and elseif with includes.