Create simple forms using API

Recommended Posts

On 4/25/2018 at 8:22 PM, Ivan Gretsky said:

Thanks for the thread @Soma. One of the most important and cited ones in the whole forum history!

In the original post there are a few points that seem to be not discussed later in the thread, but which are extremely interesting to me.


Are there any good examples of those to dig into? Gists maybe?


Looking here it seems arrays are not allowed. I might be not understanding it right or things might change since when it was written. Is there actually a way to process input from a page or an array?


There was already a question about what kind of validation processInput does and @adrian's answer too. I read the code a few times but still not sure should I sanitize values after processInput before saving to page fields or not. Is it necessary?

Thanks again! Learning ProcessWire is still fun (or am I doing it too slow?!)

1. There's a example in the code itself with email:

if($email && (strpos($email->value,'@hotmail') !== FALSE)){        // attach an error to the field
        // and it will get displayed along the field
        $email->error("Sorry we don't accept hotmail addresses for now.");


Anything the API provides is possible. I can't go into details as there's too much and don't have any examples ready.

2. Of course an array is possible, input->post is also and array. You just have to make it a WireInputData array.

3. "Validation" is per Inputfield and it depends. Some inputfields do some sanitations to make sure an expected format or type of value is given (for example email but most do nothing at all. You can look at all the Inputfields processInput() method to see what it does. Text and Textarea have some Inputfield settings to strip tags for example. It depends also on what the Form is used for and where you use the data afterwards. It's never an issue to save data to DB ie Pages, it's always about what and where you output the data (website, email, ...).

  • Like 2

Share this post

Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.