Jump to content

Form does not perform its callback


Guy Verville
 Share

Recommended Posts

We are experiencing a big problem with our forms. You can see them in action here: https://www.centura.ca/en/my-centura/sign-up

Since the Retailer form is the most used for the moment (the site is in soft launch), I will discuss this one. When a retailer signs up, the callback creates a profile and a user. 

The form is rendered with this code:

return $_form->render($form, function($form, $template) {
			return $this->createUser($form, $template, true);
		});

The callback is, of course createUser. This callback has been set in a custom render function which calls the real $form->render method.

public function createUser(InputfieldForm $form, \TemplateEngine $template, bool $notify = false): \TemplateEngine {
		$form = $this->validateCreateUserForm($form);
		if(count($form->getErrors()) > 0) {
			return $template;
		}
[...]
		$_form->setMessage(__("Your request has been sent to Centura for validation. We will contact you as soon as possible."));
		wire("session")->redirect($_SERVER["REQUEST_URI"]);   
[...]
		return $template;
}

The callback is performed as requested for most of the users. And then, it is not fired for apparent no reason and users complain. They are reverted back to their form, already filled. They then try to send again the form to be redirected again with the form without any other indication of something going on. In the backend, nothing is performed.

I was able to reproduce the problem. Using Tracy Debugger, I placed some bdb() calls in the createUser callback to realize that it is not fired at all!

Then I discovered that opening a new window in furtive mode resolved the problem. I was able to send my form. All the bdb() calls were fired and the user was created as planned.

I have checked for console errors, server errors, etc. Nothing.

The redirecting code that was first written by the programmer was: 

header('Location: '.$_SERVER["REQUEST_URI"]);

I decided to with the wire("session") equivalent, but to no avail.

We seem to experience this problem with Chrome or Opera. But I can't be sure of that at that point.

Any idea?

 

Link to comment
Share on other sites

Probably a dumb question, but in $_form->render($form, function($form, $template) { ... }) what exactly is $_form? I'm assuming it's a instance of InputfieldForm, but is that right? Also, how are you adding callback support? As far as I can tell, by default InputfieldForm->render() doesn't take any arguments ?

You mentioned that you "placed some bdb() calls in the createUser callback", but if you meant placing them within the createUser() function, have you tried placing them before it's called, i.e. before the "return $this->createUser($form, $template, true);" line? Just to make sure whether we reach that point at all.

Assuming that this is all server-side code, I don't see how the browser could be relevant. The first options I can think would be ...

  1. To make sure that however you're adding these new features to the render() method, it really gets done on each page load.
  2. To make sure that this issue isn't caused by an error in the form, i.e. a required field being blank or having invalid value.
  3. To make sure that caching isn't involved (seems unlikely, but it might be worthwhile turning all kinds of caching off and test if the issue still appears).
Link to comment
Share on other sites

Hello Teppo,

Thank you for your kind reply. The programmer who wrote the code just inspected it. The problem is... Google or Opera and their autocomplete feature that fills the honeypot field of the form... Since the field is fields, the form does not continue. The problem seems to be well known for ages.

As for the InputfieldForm->render() not taking any arguments, I wrote above that this callback has been set in a custom render function which calls the real $form->render method. ? 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...