• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Trouble with form return message

A

account8226

Guest
#1
Hello,

I am having trouble with my forms, I have an action, and data-fieldValidatorUrl, with data-redirect on off.

When I submit my form :

If there is an error, it's working fine, a nice XenForo's error popup is showing up with the following code :
PHP:
$this->responseError(new XenForo_Phrase('error'));
But when everything goes fine, I would like the page to refresh, but it's actually returning a javascript error, here is the result with firebug :
PHP ?> {"status":"ok","message":" [........]
Here is the final return code :
PHP:
$redirectUrl = XenForo_Link::buildPublicLink('my_link');
       
        return $this->responseRedirect(
            XenForo_ControllerResponse_Redirect::SUCCESS,
            $redirectUrl,
            new XenForo_Phrase('my_text')
        );

How can I return a simple message as a popup for example ? That would say everything was fine, do I have to use javascript ?

Regards.
 

Chris D

XenForo developer
Staff member
#2
You're doing it the right way.

On your form element in the template ensure you have "AutoValidator" as one of the class names and have data-redirect="on" as an attribute on the form too.
 
A

account8226

Guest
#3
You're doing it the right way.

On your form element in the template ensure you have "AutoValidator" as one of the class names and have data-redirect="on" as an attribute on the form too.
Hey thanks for the reply,

My problem is that I have everything like you said, like the AutoValidator or data redirect tag, but it's throwing a JS error :
error.png

The JS error message is above on post #1.
 

Chris D

XenForo developer
Staff member
#4
Is that all that's in the console? Doesn't look like an error to me.

Just a thought: Make sure you've not got anything that could modify the output of the form action...

e.g. If you have anything like echo, or var_dump or Zend_Debug::dump then it may very well generate an error (as it breaks the json output).

Aside from that, a javascript error message can come up due to some other reason. Check closely for syntax errors etc.
 
A

account8226

Guest
#5
Check out this :
redirect.png

It it's the Javascript Console (error).

Don't you think that ?> is strange at the begining ?
 

Chris D

XenForo developer
Staff member
#6
hm actually, yeah that doesn't quite look correct.

As I say, you've probably got a boo boo in your code - whatever code is running when the form is submitted.

Possibly even a missing close bracket }
 
A

account8226

Guest
#7
Is that all that's in the console? Doesn't look like an error to me.

Just a thought: Make sure you've not got anything that could modify the output of the form action...

e.g. If you have anything like echo, or var_dump or Zend_Debug::dump then it may very well generate an error (as it breaks the json output).

Aside from that, a javascript error message can come up due to some other reason. Check closely for syntax errors etc.
Lol ;)

cb48803a6b9b8e2a6f96a88f4f590b07.png

epic_fail2.jpg

Thanks for the help Chris :)