Display image instead of text - php

I am very new in php. I have a site with the CMS joomla 3.6.
In the register of a third part component I have a select box to the members inform his gender. In the html of the page, returns the text 'male' and 'female'.
What I need is to replace the text 'male' and 'female' with images.
In the PHP file I have this:
public function getFieldData($field) {
$options = array("COM_COMMUNITY_MALE" => "COM_COMMUNITY_MALE", "COM_COMMUNITY_FEMALE" => "COM_COMMUNITY_FEMALE");
$value = strtoupper($field['value']);
if ( isset($options[$value])) {
return JText::_($options[$value]);
}else {
return '';
}
}
So, I know that the second "COM_COMMUNITY_MALE" and "COM_COMMUNITY_FEMALE" are the output html and I have tried to replace them with that code <img src="image/image.png"/>. But no luck, can someone tell me what is the path to do this?
Thank you in advance for your attention.

The problem is that you are using a dropdown box, and, for example, COM_COMMUNITY_MALE is the value and the label of one of the options in that dropdown box, and you can't have a value in a dropdown that is HTML code (for example, an img tag). You will need to review your requirements.

Related

Need a PHP echo to produce a text hyperlink on buffer

I have a php form on my site. The form ultimately produces an article submitted by the user.
One of the data fields in the form, is a drop down menu so the user can select which publication they represent.
Currently, the form works if I am only trying to display the name of their publication.
However... I would also like that name to be a clickable link to their respective publication.
In an attempt to achieve this, I set my form up like this:
Form: <select name="publication" id="publication">
<option value="http://www.espn.com">ESPN</option>
<option value="http://www.cnn.com">CNN</option>
<option value="http://www.abcnews.com">ABC</option>
<option value="http://www.cbsnews.com">CBS</option>
<option value="http://www.foxnews.com">FOX</option>
</select>
And the echo is set up like this:
Echo:
<?php $publication = htmlspecialchars($_POST['publication']); echo $publication; ?>
Unfortunately, the result produces the full URL instead of the Text Link I am trying to achieve.
Not sure how I am supposed to code the form or the echo to achieve the desired clickable text link.
It is taking the value option, not the innerHTML. One solution is to make the value the following:
<a href='http://example.org'>Example</a>
Note: You may need to escape characters for this to work.
The value of $_POST['publication'] is going to be the chosen <option>'s value, not the display name.
If you want to display the link along with the name, consider encoding the list of publications into a static array, then outputting that:
$publications = [
"media1" => "link",
"media2" => "link"
]
if (array_key_exists($_POST["publication"], $publications)) {
echo '' . htmlspecialchars($_POST["publication"]) . '';
}

How to add static html markup to a CiviCRM form

I have CiviCRM 4.4.6 + Drupal 7 and i alter one of CiviCRM's forms.
Inside hook_civicrm_buildForm(), i try to:
form->addElement('html', 'statichtml', '<div>aa</div>');
$template =& CRM_Core_Smarty::singleton();
$bhfe = $template->get_template_vars('beginHookFormElements');
if (!$bhfe) {
$bhfe = array();
}
$bhfe[] = 'statichtml';
$form->assign('beginHookFormElements', $bhfe);
If i use it with 'text' element type, it works correctly. This way nothing is rendered, but an empty additional tr is added.
How to use this type of element correctly?
http://pear.php.net/manual/hu/package.html.html-quickform.intro-elements.php
Here is the explanation.
The element type should be static, not html and the above code starts to work.

How to pull variable from one form to another form on same web page

I have a php web page that has 2 separate forms on it that both show results at the bottom of the page. The first form uses one drop-down menu (titled Quickshow) with 6 choices that filters the results when selected, with the top choice being the default selection when the page is opened. The second form has 6 drop-down menus, each with multiple choices, that filters the results once the "Filter Results" button is clicked.
My problem is when the second form is used, it is using the default selection from the first form instead of staying with the selected choice from the first form. I understand the code that is making the first choice the default, and also allowing it to change for the first form, but how do I keep (call?) the optional choices for the second form? Below is the code being used for both forms. The first part is the web (.php) page portion, the second part is on the template (.tpl) page that is being pulled over to the web page. I didn't write the pages, but am trying to fix the filter on it.
.php page
function enumRequests() {
$getQuickShow = 1;
if (!$_REQUEST['feature_quickshow'] == '') {
$getQuickShow = (int)$_REQUEST['feature_quickshow'];
}
$quickShow = eval(quickShow($getQuickShow));
$whereArray[] = (string)$quickShow;
if ($_REQUEST['resultsFiltered']) {
$quickShow = eval(quickShow($getQuickShow));
//$whereArray[] = (string)$quickShow;
foreach ($_REQUEST AS $key => $val) {
if ($val) {
$val = mysql_real_escape_string($val);
if (strpos($key, 'fld_') === 0) {
$newKey = str_replace('fld_','',$key);
$whereFragment = "{$newKey} = '{$val}'";
$whereArray[] = (string)$whereFragment;
}
}
}
}
}
.tpl page
Quick Show:[#quickshow]
Thanks in advance for any help I receive with this.
you can always refer to document.forms[1].mytxt.value = document.forms[0].utxt.value

symfony image inside a button?

I'm trying to include an image inside a button using symfony1.4 with this code:
<?php
echo button_to(image_tag('icon.png')."button_name",'url-goes-here');
?>
But the result i get, instead of what i want is a button with "img src=path/to/the/icon.png button_name" as the value of the button. I've google'd it long enought and found nothing, so i'll try asking here.
In other words:
i'd like to find the way to generate html similar to:<button><img src=..>Text</button> but with a symfony url associated in the onclick option
How can i do it to put an image inside a button with symfony? Am i using the helpers wrong?
Thank you for your time!
You are using Symfonys button_to function incorrectly. From the documentation:
string button_to($name, $internal_uri, $options) Creates an
button tag of the given name pointing to a routed URL
As far as I can tell, the button_to function does not allow for image buttons. Instead, you will probably create the button tag yourself and use symfonys routing to output the url.
I finally created my own helper to display this kind of buttons. I know is not very efficient and flexible but works in my case. Here is the code
function image_button_to($img,$name,$uri,$options){
$sfURL = url_for($uri);
$sfIMG = image_tag($img);
if(isset($options['confirm'])){
$confirm_text = $options['confirm'];
$jsFunction = 'if(confirm(\''.$confirm_text.'\')){ return window.location=\''.$sfURL.'\';}else{return false;}';
}else{
$jsFunction = 'window.location="'.$sfURL.'";';
}
$onclick = 'onclick="'.$jsFunction.'"';
if(isset($options['title'])){
$title = 'title=\''.$options['title'].'\' ';
}else{
$title = '';
}
if(isset($options['style'])){
$style = 'style=\''.$options['style'].'\' ';
}else{
$style = '';
}
return '<button type="button" '.$onclick.$title.$style.' >'.$sfIMG." ".$name.'</button>';
}
With this function as helper, in the templates i just have to:
<?php echo image_button_to('image.png',"button_name",'module/actionUri');?>
hope this be useful for someone ;)

Having problems theming the search box in Drupal

I'm not the world's most experienced Drupal and I'm having a nightmare trying to customise the search box. I'm using the example from the Drupal help site and it's simply not working.
I've copied search-theme-form.tpl.php from the search module into my theme and copied the example code, Any HTML in that code outside of the pre-process function shows fine but as far as I can tell, the pre-process function either isn't called or just isn't affecting my search box.
I'm almost certain that I'm missing something absolutely fundamentally basic about how Drupal works but I can't find any info at all.
Here's the code:
<?php
function danland_preprocess_search_theme_form(&$vars, $hook) {
// Remove the "Search this site" label from the form.
$vars['form']['search_theme_form']['#title'] = t('');
// Set a default value for text inside the search box field.
$vars['form']['search_theme_form']['#value'] = t('Search this Site');
// Add a custom class and placeholder text to the search box.
$vars['form']['search_theme_form']['#attributes'] = array('class' => 'NormalTextBox txtSearch', 'onblur' => "if (this.value == '') {this.value = '".$vars['form']['search_theme_form']['#value']."';} ;", 'onfocus' => "if (this.value == '".$vars['form']['search_theme_form']['#value']."') {this.value = '';} ;" );
// Change the text on the submit button
//$vars['form']['submit']['#value'] = t('Go');
// Rebuild the rendered version (search form only, rest remains unchanged)
unset($vars['form']['search_theme_form']['#printed']);
$vars['search']['search_theme_form'] = drupal_render($vars['form']['search_theme_form']);
$vars['form']['submit']['#type'] = 'image_button';
$vars['form']['submit']['#src'] = path_to_theme() . '/images/search.jpg';
// Rebuild the rendered version (submit button, rest remains unchanged)
unset($vars['form']['submit']['#printed']);
$vars['search']['submit'] = drupal_render($vars['form']['submit']);
// Collect all form elements to make it easier to print the whole form.
$vars['search_form'] = implode($vars['search']);
}
?>
<div id="search" class="container-inline">
<?php print $search_form; print $search_theme_form; ?>
</div>
Put the preprocess function in template.php in your theme directory, then clear the cache at "admin/settings/performance"
Here are some helpful links to learn about theming with templates/preprocess functions:
About overriding themable output
Setting up variables for use in a template (preprocess and process functions)

Categories