Redirect issue with reCaptcha v2 error on contact form

  • Posts: 2094
  • Thank you received: 713
  • Hikashop Business
4 months 1 week ago #335569

-- HikaShop version -- : 4.1.0
-- Joomla version -- : 3.9.something
-- PHP version -- : 7.3

Hi,

I'm using the HikaShop reCaptcha v2 plugin only in the contact form... the one that opens after clicking the contact button on product pages.
While HikaShop is admittedly not the newest, the reCaptcha plugin is: downloaded it just a few hours ago.

It's generally working fine, until someone has filled in all form fields but forgets to tick the reCaptcha box.
In that case the user is being redirected to a weird URL -- actually a "fraction" of the original URL. For example:
- Regular contact form URL: domain.com/aaa/bbb/contact/cid-1234
- Redirected in case of reCaptcha error to: domain.com/aaa/bbb
The form is still there (with the system error message above), but this weird URL leads to a horrible, unwanted page layout due to all sorts of modules showing that shouldn't be there. (I could eventually restructure numerous module assignments, but neither will it be "fun", nor should it be necessary.)
I see in the _checkCaptcha function in recaptcha2.php a redirect to @$_SERVER['HTTP_REFERER'), but that doesn't seem to be what's happening. How to fix?

Thanks!

Last edit: 4 months 1 week ago by lousyfool. Reason: Version numbers. Sorry sorry, getting confused with sites...

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

  • Posts: 2094
  • Thank you received: 713
  • Hikashop Business
4 months 1 week ago #335572

Ooooh... had not tried this, yet: when successfully sending a request via the form, it's redirecting to that weird fractional URL as well.

I hope there's an easy way to change it.

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

  • Posts: 74542
  • Thank you received: 11498
  • MODERATOR
4 months 1 week ago #335573

Hi,

The

@$_SERVER['HTTP_REFERER']
in the recaptcha2.php file is not being used as the _checkCaptcha function is called with the $redirect parameter being false in the onBeforeSendContactRequest function triggered by the product controller's send_email function.
In the case of HikaShop's contact form, when the captcha is invalid, the send_email task will just as for the display of the form on the redirected page.
I think what's missing is adding the current Itemid to the URL of the contact form in order to stay on the same menu item and thus not loose the link with the modules.
To do that, add the code:
<?php
		global $Itemid;
		$this->url_itemid='';
		if(!empty($Itemid)){
			$this->url_itemid='&Itemid='.$Itemid;
		}
?>
at the beginning of the product / contact.php view file via the menu Display>Views.
And then change the line:
<form action="<?php echo hikashop_completeLink('product'); ?>" id="hikashop_contact_form" name="hikashop_contact_form" method="post"  onsubmit="return checkFields();">
to:
<form action="<?php echo hikashop_completeLink('product&task=contact&cid='.hikaInput::get()->getInt('cid').$this->url_itemid); ?>" id="hikashop_contact_form" name="hikashop_contact_form" method="post"  onsubmit="return checkFields();">
there.
It should then work like you want.

The following user(s) said Thank You: lousyfool

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

  • Posts: 2094
  • Thank you received: 713
  • Hikashop Business
4 months 1 week ago #335582

Hi Nicolas,

Ah ok... I've been looking in the wrong place again. Your explanation and especially the solution are greatly appreciated! Excellent -- it does the trick, indeed! Maybe something you want to add to the next version -- I can't be the only one stumbling over it.

Now I can remove my JS which I used for "clean-up" on submission or error.
Some I'll keep, though: checking if a success system message exists (= after successful submission) I'm hiding the form (who'd need it then any longer?!) and showing "back to product" and "continue shopping" (linking to the main category listing) buttons instead below the message. B)

Many thanks once again!

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

  • Posts: 74542
  • Thank you received: 11498
  • MODERATOR
4 months 1 week ago #335584

Hi,

Yes, we'll add a cleaner modification for the next version to fix that.

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

Time to create page: 0.061 seconds
Powered by Kunena Forum