Jump to content

Recommended Posts

Hi all.  I have this code.

 

<?php $ext = ' <form action="/members/clubs/view-activity.php" method="post" name="venuefrm">
            <button type="submit" id="close" class="link"><span>View Activity</span></button>
            <input name="activity" type="hidden" value="<?php echo $activites['activityID']; ?>" />
            </form>'; 

?>

 

The code falls down at the  value="<?php echo $activites['activityID']; ?>" part.

 

Can someone please show me how I break into php to write this part properly as I dont understand an it is obviously wrong.

 

Thanks

 

Danny

Link to comment
https://forums.phpfreaks.com/topic/258732-echo-php-in-a-variable-with-html/
Share on other sites

You are already inside php tags, you don't need them again.'

You need to concatenate the array value since the single index quotes will break the string.

 

$ext = ' <form action="/members/clubs/view-activity.php" method="post" name="venuefrm">
            <button type="submit" id="close" class="link"><span>View Activity</span></button>
            <input name="activity" type="hidden" value="' . $activites['activityID'] . '" />
            </form>'; 

The other way to do it is to change your quotes. PHP takes single quotes as literal, as in it will build a sting with exactly what is inside them, without preprocessing the values of any variables that you put in in, use double quotes to get around this.  In your example you have a lot of double quotes inside the string, so you would either need to change them all to single quotes or escape them by putting a \ directly before them.  also, when using array values in a double quoted sting wrap the declaration inside {}.  so using the escaped method it would look like this:

<?php 
$ext = " <form action=\"/members/clubs/view-activity.php\" method=\"post\" name=\"venuefrm\">
            <button type=\"submit\" id=\"close\" class=\"link\"><span>View Activity</span></button>
            <input name=\"activity\" type=\"hidden\" value=\"{$activites['activityID']}\" />
            </form>"; 
?>

Another way to write blocks of string content into a variable is to use <<<UID to open the block and UID; to close it, where UID is a unique name for the string block. eg:

<?php 
$ext = <<<FORM 
            <form action="/members/clubs/view-activity.php" method="post" name="venuefrm">
            <button type="submit" id="close" class="link"><span>View Activity</span></button>
            <input name="activity" type="hidden" value="{$activites['activityID']}" />
            </form>; 
FORM;
?>

You must make sure that there are no leading spaces on the line where you close the block (FORM; in this case) or it will create an error.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.