Registration Custom Fields Depend On Checkbox

  • Posts: 108
  • Thank you received: 2
13 years 1 month ago #26645

Hello again.
After i bought my second copy i need in that website to have at registration 2 options: register as a shopper or register as a affiliate.
The affiliate box is handling that, but i need to add fields when someone is requesting to sign as affiliate (custom fields).

How can i have when the checkbox is clicked, some fields will be displayed and when is off they will be hidden and unavaliable?

Thanks in advance!

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #26657

Hi,

What you should do is to edit file "registration" of the view "user" via the menu Display->Views. There, you could add some javascript to hide/display the custom fields area based on the value of that affiliate checkbox. The only limitation you will have with this method is that your custom fields can't be required. You will also need to know PHP and javascript to do that.

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 2
13 years 1 month ago #26659

Ok thats good, but i must have them required.. other wise there is no use..
How can i require those fields?

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #26675

That won't be possible with the required option of the custom fields as there are protections in the fields system so that the users cannot tamper with the fields.

You would have to leave then not required in HikaShop and add some more customization in the file "step" of the view "checkout" so that when the user clicks on the next button, you check with some javascript that the fields are not empty.

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 2
13 years 1 month ago #26735

Done all but one thig.. i cant seem to get them invisible or visable depend on checkbox..
I have done this:

<script language="text/javascript">
function showhidefield()
{
if (document.'hikashop_checkout_form.hikashop_affiliate_checkbox.checked)
{
document.getElementById("hideablearea").style.display = "block";
}
else
{
document.getElementById("hideablearea").style.display = "none";
}
}
</script>

this is in the header.

and i have the manual fields coverd in div hideablearea:

<div id='hideablearea' style='display:none'>
<tr class="hikashop_registration_placement_line">
...
<span class="hikashop_field_required">*</span>
</td>
</tr>
</div>


And i add the onclick for the checkbox:

<input class="hikashop_affiliate_checkbox" id="hikashop_affiliate_checkbox" type="checkbox" name="hikashop_affiliate_checkbox" onclick="showhidefield()" value="1" <?php echo $this->affiliate_checked; ?> /></span>

Do you have any idea why that wont work?
Thanks alot!

Last edit: 13 years 1 month ago by bars92.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #26753

You have :
document.'hikashop_checkout_form.hikashop_affiliate_checkbox.checked

instead of:
document.hikashop_checkout_form.hikashop_affiliate_checkbox.checked
in your function.

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 2
13 years 1 month ago #26791

Thanks,but still no use.. the function is not called at all.. the onclick is not working for some reason..

Any suggestions?

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #26817

That sounds ok though.
Do you have a link to that page ?

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 2
13 years 1 month ago #26998

Well i changed the code to that:

<script type="text/javascript">
function showhidefield()
{

if (document.hikashop_registration_form.hikashop_affiliate_checkbox.checked)
{
alert("Checked True");
document.getElementById("hideablearea").style.display = "block";
}
else
{
document.getElementById("hideablearea").style.display = "none";
}
}
</script>

and now i get in the alert but nothing happens..
Here is a link: **** .

EDIT: Never mind, i fixed it. Apprently the div was not displayed right, so the function couldnt hide the non-exsisting div.

Thank you for you help!

Last edit: 13 years 1 month ago by bars92.

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 2
13 years 1 month ago #27052

After the changes i made i ran into a bug.
Once i complete the registration the address is not been saved..
I added 2 inputs as it appear in the front page (<tr><td><lable>....)
and added a visible/invisible divs.
OnClick disable all the hideableareaX divs.
the 2 inputs are not required in Hikashop config.
When i remove my custom part, the registration is working fine.

Could you tell me what made Hikashop not save the address?

Code:

<tr class="hikashop_registration_placement_line">
<?php
$lang =& JFactory::getLanguage();

?>
<td class="key">
<div id='hideablearea0' >
<label for="user_placement"><?php if($lang->getName() == 'Hebrew'){echo "מקום";}else{echo "Placement";}?></label>
</div>
</td>
<td>
<div id='hideablearea1'>
<input id="user_placement" class="inputbox" type="text" value="" name="data[user][user_placement]">
<span class="hikashop_field_required">*</span>

</div>
</td>
</tr> <tr><td colspan="2"><div id='hideablearea2' ><?php echo '<br />' . JText::_('HIKA_PLACEMENT_EXPLAIN');?></div></td> </tr>

<tr class="hikashop_registration_position_line">
<td class="key">
<div id='hideablearea3'>
<label for="position"><?php if($lang->getName() == 'Hebrew'){echo "עמדה";}else{echo "Position";}?></label>
</div>
</td>
<td>
<div id='hideablearea4' >
<select id="position" size="1" name="data[user][position]">
<option id="position_Left" selected="selected" value="Left"><?php if($lang->getName() == 'Hebrew'){echo "שמאל";}else{echo "Left";}?></option>
<option id="position_Right" value="Right"><?php if($lang->getName() == 'Hebrew'){echo "ימין";}else{echo "Right";}?></option>
</select>
<span class="hikashop_field_required">*</span>
</div>
</td>
</tr>
<tr><td colspan="2"><div id='hideablearea5' > <?php echo '<br />' . JText::_('HIKA_POSITION_EXPLAIN');?></div></td></tr>

Last edit: 13 years 1 month ago by bars92.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #27059

Your fields have the name data[user][position]
But you're talking about the address not being saved.
If your custom fields are address custom fields, you should have the name data[address][position] instead.

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 2
13 years 1 month ago #27068

Custom fields have no connection to address.
Both costum fields are user fields.
The bug is that somehow the address is not been saved..

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #27069

Then I don't know as I don't see any problem in the code you posted. Did you modify other things ?

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 2
13 years 1 month ago #27070

No, did not add anything else.
When i remove the code above, it's working again, but when i add it back it's not saving the address.

I can't find the connection..

EDIT: I just found out it does save nothing but the email, full name and user name.. maybe that can help.

Last edit: 13 years 1 month ago by bars92.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #27071

I don't see the problem.

You say you didn't add anything else, but I suppose that you added some JS code right ? Maybe it comes from the js ?

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 2
13 years 1 month ago #27083

Yes, i added JS at the header of all pages:

<script type="text/javascript">
function showhidefield()
{

if (document.hikashop_checkout_form.hikashop_affiliate_checkbox.checked)
{
document.getElementById("hideablearea0").style.display = "block";
document.getElementById("hideablearea1").style.display = "block";
document.getElementById("hideablearea2").style.display = "block";
document.getElementById("hideablearea3").style.display = "block";
document.getElementById("hideablearea4").style.display = "block";
document.getElementById("hideablearea5").style.display = "block";
}
else
{
document.getElementById("hideablearea0").style.display = "none";
document.getElementById("hideablearea1").style.display = "none";
document.getElementById("hideablearea2").style.display = "none";
document.getElementById("hideablearea3").style.display = "none";
document.getElementById("hideablearea4").style.display = "none";
document.getElementById("hideablearea5").style.display = "none";
}
}
</script>

I don't think it might me the problem..

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #27136

Did you create custom fields with the column names user_placement and position for the table user ?
Otherwise, that might create such problem as the field data would be missing.

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 2
13 years 1 month ago #27138

Aha! I named them placement and position without the user_ before so i removed the [user] before the input and it's working now.
I dont know why did it displayed with [user] before when i copied it..

Thanks again :)

Please Log in or Create an account to join the conversation.

Time to create page: 0.087 seconds
Powered by Kunena Forum