Jump to content

FrontendForms - A module for creating and validating forms on the frontend


Juergen

Recommended Posts

This issue has nothing to do with the module itself, but it seems that the $_SERVER array is not loaded at that moment.

You can try the following: 

// Replace the following line inside the FrontendForms.module file on line 858

if (strpos($_SERVER['REQUEST_URI'], $this->wire('config')->urls->admin) === 0) {

with this line

if (!is_null($_SERVER) && strpos($_SERVER['REQUEST_URI'], $this->wire('config')->urls->admin) === 0) {

Let me know if it works

Link to comment
Share on other sites

This gives the same error.

I fill this is related with the module because this is not the first time I bootstrap PW and never had an issue before to install this module.

You are using REQUEST_URI, but when bootstrapping, isn't it expected that it's not defined?

It's easy to test, just include PW index.php in any script and run it directly (no web page involved).

Edited by da²
Link to comment
Share on other sites

Then try the following:

if (!is_null($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], $this->wire('config')->urls->admin) === 0) {

Have not tried it with bootstrapping but the code inside the if condition is not important for running forms. It is only there to add CSS and JS files to the backend, so you can prevent the running of the code inside the condition by checking the existence of $_SERVER['REQUEST_URI'] first.

Link to comment
Share on other sites

On 8/30/2025 at 9:59 PM, Juergen said:
if (!is_null($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], $this->wire('config')->urls->admin) === 0) {

This gives a warning, better like this:

if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], $this->wire('config')->urls->admin) === 0) {

Will you publish a fix?

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Hello,

Is there a way to put some fields into a div, so I can manage form layout more precisely? Is it with the FieldsetOpen/FieldsetClose elements?

EDIT:

Another thing, after form submission I'd like the form to be still displayed for another use, it is used to filter data in a table so it should always be visible. Actually after submission the form is hidden and replaced with the message "Thank you for your message.".

I tried to use $form->showForm(true); but there is a bug, the value shown in the form is not always the value I selected before to submit (in a Select element).

Edited by da²
Link to comment
Share on other sites

7 minutes ago, da² said:

Is there a way to put some fields into a div, so I can manage form layout more precisely?

Of course, there are several options. Which one you should use depends on your preferred output.

1) Wrap multiple inputfields inside a fieldset

Take a look here for more information or here for a working example. Sometimes a fieldset is the best option to wrap some inputfields syntactically correct.

2) Wrap multiple inputfields within a div container by using the append() and prepend() methods

Take a look here for more information and here is an example using this methods.

If you want to wrap for example 4 inputfields inside an extra div container, the idea is to add the opening div tag via the prepend method to the fist field and the closing div tag via the append() method to the last input field.

3) Use the setMarkUp() method to add the opening and closing div

I think this is the most practicable method for you if you do not want to use a fieldset. You will find more information here.

Example for wrapping multiple fields between 2 div tags:

$markup = new Markup();
$markup->setMarkup('<div>'); // opening div
$form->add($markup);
  
// here enter your inputfields

 	....
  	....
  
$markup = new Markup();
$markup->setMarkup('</div>'); // closing div
$form->add($markup);

Best regards

  • Like 1
Link to comment
Share on other sites

Thank you @Juergen

I edited my message with more questions while you were answering:

  • Another thing, after form submission I'd like the form to be still displayed for another use, it is used to filter data in a table so it should always be visible. Actually after submission the form is hidden and replaced with the message "Thank you for your message.".
    I tried to use $form->showForm(true); but there is a bug, the value shown in the form is not always the value I selected before to submit (in a Select element).
  • And another question, following the documentation I added $form->setMethod('get'); but get an error: "::setMethod does not exist or is not callable in this context"
Link to comment
Share on other sites

12 minutes ago, da² said:

And another question, following the documentation I added $form->setMethod('get'); but get an error: "::setMethod does not exist or is not callable in this context"

I found in your code that it is $form->setAttribute('method', 'get'); (documentation needs an update 🙂 ). But now the page is empty after submission, empty head and body. I don't understand what's happening.

EDIT: Looks like there is an exit() somewhere, because no code in my template is executed after $form->isValid() when I use GET method. 🧐

Edited by da²
Link to comment
Share on other sites

25 minutes ago, da² said:

I tried to use $form->showForm(true); but there is a bug, the value shown in the form is not always the value I selected before to submit (in a Select element).

Strange in my case it shows exactly the value that I have chosen before the form submission. Is this a simple select element or a select multiple in your case?

Before submission:

image.png.245d962cd44c97f4b22ea9ddaeef3cef.png

 

After submission

image.png.09390f197f2879a1e46c0050774cf4cc.png

 

As you can see the value "custom" is before and after the submission present.

Link to comment
Share on other sites

21 minutes ago, da² said:

EDIT: Looks like there is an exit() somewhere, because no code in my template is executed after $form->isValid() when I use GET method.

I can confirm this behavior but I must take a closer look to find out what is happening. 🤔I am always using POST and not GET in my forms, so I have not discovered this issue until now.

  • Like 1
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
×
×
  • Create New...