Jump to content

Recommended Posts

I have a form with a drop down menu and am calling an external language file. The language file works fine except when using the echo within this array. Does anyone have any options or suggestions?

 

code

				
<?PHP
$maritalstatus = '<option value="<?php echo PARTNER126?>" /><?php echo PARTNER126?></option>
<option value="<?php echo PARTNER14?>">Never Married</option>
<option value="Divorced">Divorced</option>
<option value="Widowed">Widowed</option>
<option value="Separated">Separated</option>
<option value="Annulled">Annulled</option>';
$maritalstatus = str_replace('<option value="'.$row['MaritalStatus'].'">', '<option value="'.$row['MaritalStatus'].'" selected>', $maritalstatus);
			echo $maritalstatus;
			?>

 

The PARTNER126 is for the language file. I need it to echo the value instead of writing in the value as above. As above it does not work. The normal values show fine, but no echo.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/165132-solved-echo-inside-an-array/
Share on other sites

Looks like you've got <?php ... ?> nested inside of PHP code, that's not going to work.

 

$maritalstatus = '<option value="<?php echo PARTNER126?>" /><?php echo PARTNER126?></option>
<option value="<?php echo PARTNER14?>">Never Married</option>
...

 

That code right there is going to make the value of the first option literally be <?php echo PARTNER126?>, which isn't what you want. You're going to want to set up some function to return the text from the language file. Like this:

 

$maritalstatus = '<option value="' . get_language_text('PARTNER126') . '" />' . get_language_text('PARTNER126') . '</option>
<option value="' . get_language_text('PARTNER14') . '">Never Married</option>
...
function get_language_text($partner) {
... code to return text based on $partner param here ...
return $text;
}

Looks like you've got <?php ... ?> nested inside of PHP code, that's not going to work.

 

$maritalstatus = '<option value="<?php echo PARTNER126?>" /><?php echo PARTNER126?></option>
<option value="<?php echo PARTNER14?>">Never Married</option>
...

 

That code right there is going to make the value of the first option literally be <?php echo PARTNER126?>, which isn't what you want. You're going to want to set up some function to return the text from the language file. Like this:

 

$maritalstatus = '<option value="' . get_language_text('PARTNER126') . '" />' . get_language_text('PARTNER126') . '</option>
<option value="' . get_language_text('PARTNER14') . '">Never Married</option>
...
function get_language_text($partner) {
... code to return text based on $partner param here ...
return $text;
}

 

Thanks for the tip and fast reply. I am still struggling with returning multiple values. It will display the PARTNER126 in both places, but it does output the correct word from the language file.

I also tried to use an array, but it only output the word array in the drop down box.

 

Any help on using the multiple call so that it will read each from the language file?

 

			<?PHP
function get_language_text($partner) {
$text = PARTNER126;
$text = PARTNER14;
   return $text;
}
?>

 

The above will only output the first $text in both places. I tried to change the second $text to something like $text2 and return both values, but it did not work.

 

Thanks again

In your get_language_text($partner) function, you'll probably want to use a switch statement. That will allow you to see which partner value to use (based on $partner) then return the appropriate value, using the language constants you have

 

Thanks again for your help, but I am still unable to get it working. This is the last code of my switch statement, after changing it about 50 times. Nothing will show in my drop down list using the switch statement. Could you post an example of how i am suppose to do it?

I know I am close, but missing something.

 

<?PHP
function get_language_text($partner){
switch ($partner) {
case "PARTNER126":
case "PARTNER14":
echo $partner;
break;
}
}
?>

I have found a long way to do what I want. Which basically consists of a new function for each item.

 

function get_language_text($partner){
$text = PARTNER126;
return $text;
}
function get_language_text2($partner2){
$text = PARTNER14;
return $text;
}

 

This does work.

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.