Jump to content

Recommended Posts

Hi Group,

 

I looked through the internet and couldn't find an answer, but I was wondering on the appropriate syntax on inserting PHP code into an input element. See below.

 

<input type="text" name="id" value="<?php echo $main['id']; ?>"  size="10" />

 

Now this is purely an example (and I'm aware of php short tags, just don't want to use them). I only ask cause I've used CodeLobster and Eclipse and they don't really know what to do with the added php syntax. CodeLobster and Eclipse wouldn't finish marking up the rest of the line in the appropriate colors (all the text was black after the < in <?php like how I showed it above), however Eclipse's built in debug system thinks this is a syntax error.

 

It runs just fine in the browser and does what I want it to, but I'd like the appropriate systax to get rid of this "error".

 

Thanks in advance,

 

ImmortalFirefly

You should at least make sure the element isn't empty before trying to use it. Keeps warnings from being generated. The below syntax uses the ternary operator, btw.

 

<input type="text" name="id" value="<?php echo !empty($main['id']) ? $main['id'] : ''; ?>"  size="10" />

[/code]

That is good to know.....maybe it'd help if I supplied the error that Eclipse is giving me....

 

"Start tag (<input>) not closed."

"Invalid character used in text string (<?php echo echo $main['id']; ?>"  size="10" />)."

 

As soon as I get rid of the inserted php code, both errors go away.

 

ImmortalFirefly

 

Well the main file is a PHP file and I've included this html file that loads when a condition is met and inserts it into the php file. So it is a html file all by itself, but it's being included into a php file.

 

IFF

If it's got php code in it, no matter what you name it or how you request it, it IS server-side scripting.

 

It's not actually HTML until it has been processed on a web server and sent out to the browser. Any HTML validation errors you are getting from your editor don't apply until after the php code in it has been parsed, tokenized, and interpreted.

For those that are glued to their screens in anticipations of an answer (since so many people have this problem....) I changed the file from .html to .php and left it exactly the way it was. I include that file which works great, and it got rid of my errors in Eclipse.

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.