Jump to content

Syntax error, unexpected T_ECHO


scheda

Recommended Posts

I'm getting a syntax error in this code.

 

Basically I'm printing out a form, and depending on the value of an option, I want "checked" to be printed out.

 

I was getting a syntax error by using the non-shorthand version of an if statement too.

 

Any ideas why?

 

'<input type="radio" name="position" value="1" '.(get_option("shPosition") == 1 ? echo "checked" .' /> Top   
<input type="radio" name="position" value="0" '.(get_option("shPosition") == 0 ? echo "checked" .' /> Bottom'

Link to comment
Share on other sites

Since the content you posted is apparently being built in a string, which you are either assigning to a variable to be echoed later or directly echoing, you don't put an echo statement inside of it. You must also supply a value after the :

'<input type="radio" name="position" value="1" '.(get_option("shPosition") == 1 ? "checked" : '') .' /> Top   
<input type="radio" name="position" value="0" '.(get_option("shPosition") == 0 ? "checked" : '').' /> Bottom'

 

 

Link to comment
Share on other sites

Since the content you posted is apparently being built in a string, which you are either assigning to a variable to be echoed later or directly echoing, you don't put an echo statement inside of it. You must also supply a value after the :

'<input type="radio" name="position" value="1" '.(get_option("shPosition") == 1 ? "checked" : '') .' /> Top   
<input type="radio" name="position" value="0" '.(get_option("shPosition") == 0 ? "checked" : '').' /> Bottom'

 

Oh that works perfectly.

 

Thank you for clarifying!

Link to comment
Share on other sites

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.