CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Profile field Amendments
Pages: [1]

Author Topic: Profile field Amendments  (Read 543 times)

deej99

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.0
  • CMS version: Joomla
  • MySQL version: 5.5.9
  • PHP version: 5.3.6
Profile field Amendments
August 09, 2011, 04:06:54 am
Hello. I need some help and advice as I am struggling with this code. I made a Custom profile form and now would like to use coding to make the option available when user select something.

For e.g.: There are 2 fields.

Have you got a topic to discuss - Yes/No (Drop Down)

*If user select No, nothing happens. If Yes Another field come which states Please Specify - Text Box.

Both these fields are in the profile form lets name it Registration. Now I have done this coding but looks like I am doing something wrong.

I worked on two files: select.php & Block.tpl

In Select.php I added this code:

$myName = $this->getName();
                $this->setName($myName . '[]');
                $attrString = $this->_getAttrString($this->_attributes);
                $this->setName($myName);
            }
      
******NEW CODE STARTS******   
         if($this->_attributes[name]=="custom_14"){
         $strHtml .= $tabs . '<select onchange=topic(this.value)' . $attrString . ">\n";
         }
         else
         {
            $strHtml .= $tabs . '<select' . $attrString . ">\n";
         }
***NEW CODE ENDS******

            $strValues = is_array($this->_values)? array_map('strval', $this->_values): array();
            foreach ($this->_options as $option) {
                if (!empty($strValues) && in_array($option['attr']['value'], $strValues, true)) {
                    $option['attr']['selected'] = 'selected';
                }

IN THE ABOVE CODE - Custom_14 is text field id which I picked up from HTML Snippet in the registration form code. I am using topic as value.

This is what I have added to select.php

Now in block.tpl

{* Show explanatory text for field if not in 'view' or 'preview' modes *}
            {if $field.help_post && $action neq 4 && $action neq 1028}
                <span class="description">{$field.help_post}</span>
            {/if}
            </td>
        </tr>
    {else}
**NEW CODE STARTS HERE**
        <tr>
        {if $form.$n.label == '<label for="custom_15">Please specify?</label>'}
            <div class="label" id="semina1" style="display:none;">{$form.$n.label}</div>
             
              {else}
            <div class="label">{$form.$n.label}</div>
            {/if}
           
            {if $form.$n.label == '<label for="custom_15">Please specify?</label>' }
            <div class="edit-value content" id="semina2" style="display:none;">
           
            {else}
             <div class="edit-value content">
            {/if}
            **CODE ENDS HERE**
         
    {else}
        <div class="crm-section {$n}-section">
           {* Show explanatory text for field if not in 'view' or 'preview' modes *}
             {if $field.help_pre && $action neq 4 && $action neq 1028}
                &nbsp;&nbsp;<span class="description">{$field.help_pre}</span>
             {/if}

I am using content id- semina1 & semina2 and Also Custom 14 is drop down menu & custom 15 is text field stating Please specify? It will appear when Option Yes is selected.

IN THE SAME BLOCK.TPL FILE I ADDED THE BELOW CODE AS WELL TO DEFINE CONTENT ID.

{if $help_post && $action neq 4}<br /><div class="messages help">{$help_post}</div>{/if}
    {/strip}
 
{/if} {* fields array is not empty *}

**NEW CODE START**

{if $field.groupTitle == "Registration"}
        {literal}
        <script type="text/javascript">
         function topic(element){
         if(element == "Yes"){
         document.getElementById("semina1").style.display = "";
         document.getElementById("semina2").style.display = "";
         }
         else{
            document.getElementById("semina1").style.display = "none";
            document.getElementById("semina2").style.display = "none";
         }
       }
      
      </script>
      {/literal}
        {/if}
**NEW CODE ENDS**
{literal}
  <script type="text/javascript">
   
IN THIS CODE - Registration is name of the profile form, Topic is select value mentioned in Select.php, Content Id semina1 & 2 as mentioned above.

I am not sure what I am doing wrong. Looks like I am missing something in block.tpl.

Thank you for your help in advance.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Profile field Amendments

This forum was archived on 2017-11-26.