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.

Recommended Answers

All 2 Replies

Member Avatar for nevvermind

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>
...
";

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.