0

Hello all

I have a form working perfectly, however I need to put this form in a $display_block .= "... ... ...";
which I have done and which works fine also (minus the following radio code).

My problem is that when I add this code back inside the display block, it causes an error (my guess is bad syntax ...<?php if ...)
The error is Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in ... on line ... (<input type='radio')

$display_block .= "
...
<div...>
<input type='radio' name='status' value='Visible' <?php if ($_POST['status']=='Visible' 
|| !isset($_POST['status'])) echo 'checked';?>>Visible
<input type='radio' name='status' value='Hidden'  <?php if ($_POST['status']=='Hidden') echo 'checked';?>>Hidden
</div>
...
";

I have tried to break it up with ". ." etc, but I just have not figured it yet.
Thanks in advance if someone finds a fix before I do.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by momo219
0

This is not correct:

$string = "Hello <?php echo ' world'; ?> !";

Try this (I'm using the ternary operator):

$visible_checked = ($_POST['status']=='Visible' || !isset($_POST['status'])) ? 'checked="checked" ' : NULL;
$hidden_checked = ($_POST['status']=='Hidden') ? 'checked="checked" ' : NULL;

$display_block .= "
...
<div...>
  <input type='radio' name='status' value='Visible' $visible_checked/>Visible
  <input type='radio' name='status' value='Hidden' $hidden_checked/>Hidden
</div>
...
";
0

Excellent stuff nevvermind - that worked a treat... very much appreciated and thanks for the link too.

Edited by momo219: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.