Jump to content

creating a form


helmut2509
 Share

Recommended Posts

what is the most convenient way to create a form?

As far as I can see, there are three approaches:

- forms using API
- module Form Template Processor and Mailer
- module FormTemplateProcessor

As a newbie, it is not easy to find out all the pros and cons of each approach.

What do you suggest?

Link to comment
Share on other sites

form builder is easiest, but it is commercial (although offers great value for money).

Building forms with API is great one too, soma has written easy to follow tutorial about it.

form template processor is more like poc, while it works, I dont really recommend using it.

Link to comment
Share on other sites

You forgot you can do your own html form.

yes, I already tried it. but I do not know, how to integrate this form in the processwire complex. Do I have to create a page for the form?

to submit the form, what do I have to enter in the action attribut of the form tag? just putting the php file?

then I skip index.php and all system variables are not available......

  • Sad 1
Link to comment
Share on other sites

Greetings,

There are many methods you can use for forms -- as others have suggested. Remember: ProcessWire allows terrific flexibility to accomplish almost anything. But that flexibility also means you have to be clear about what you want to accomplish.

I regularly build front-end interfaces for my ProcessWire projects, largely based on forms (of course). Once you head down this path, the possibilities are endless! I tend to build my forms with classic HTML, as Soma suggested. That method gives you the greatest flexibility.

Please provide more information about what you want to accomplish, then we can give better answers. For example, are you trying to create and control ProcessWire content through the foms?

I've worked through all this and posted about it before, as have others. Here are some links to get you started:

Form to Create ProcessWire Content Using HTML (with file uploads):

http://processwire.com/talk/topic/3105-create-pages-with-file-upload-field-via-api/

Form to Create ProcessWire Content Using ProcessWire Field Modules:

http://processwire.com/talk/topic/2089-create-simple-forms-using-api/

Form to Edit ProcessWire Content

http://processwire.com/talk/topic/4350-how-edit-a-page-using-api/?p=42620

Follow up if you have other questions.

Thanks,

Matthew

  • Like 4
Link to comment
Share on other sites

Please provide more information about what you want to accomplish, then

we can give better answers. For example, are you trying to create and

control ProcessWire content through the foms?

hi Matthew, for the beginning, I just want to create a simple contact form which fits in the general layout of the other pages.

That means, I want to include header, footer, navigation menu when the user calls that form and also after submitting, along with a confirmation message.

Link to comment
Share on other sites

Hi Helmut,

you may create a new template with its own template file.

  • Create a blank textfile and call it myform.php, copy it into the site/templates/ folder of pw.
     
  • Go into the pw admin and under setup templates and create a new template. There should be a list with template filenames from your site/templates/ folder (without the .php extension). Check the one you have newly created and save it.
     
  • Now create a new page under homepage and assign your form-template to it. Lets say the url of it is "/contactform/".
     
  • Go to your Editor and write into your template file some code like that:
<?php

if($input->post->aFormFieldName) {
    // a user has send the form, proceed the data and display a thank you message
    ...
    echo "<h4>Thank you for contacting us. We will get back to you soon.";

    return;  // stop with template code here
}

// if we have no post data, lets display a html form
$myForm1 = "
    <form action='{$page->url}' method='post'>
        // your inputfields and buttons here
    </form>
";

echo $myForm1;

Now go to the browser and call:  example.com/contactform/ and try it out.

If you use a profile with header.inc and footer.inc, add it to the template file like it is within the other template files:

<?php

include("./head.inc");

    if($input->post->aFormFieldName) {
        // a user has send the form, proceed the data and display a thank you message
        ...
        echo "<h4>Thank you for contacting us. We will get back to you soon.";

        include("./foot.inc");  // load the footer here, because we stop template execution in the next line!

        return;  // stop with template code here
    }

    // if we have no post data, lets display a html form
    $myForm1 = "
        <form action='{$page->url}' method='post'>
            // your inputfields and buttons here
        </form>
    ";

    echo $myForm1;

include("./foot.inc");

Have fun! :)

  • Like 2
Link to comment
Share on other sites

Hi Helmut,

you may create a new template with its own template file.

  • Create a blank textfile and call it myform.php, copy it into the site/templates/ folder of pw.
  • Go into the pw admin and under setup templates and create a new template. There should be a list with template filenames from your site/templates/ folder (without the .php extension). Check the one you have newly created and save it.
  • Now create a new page under homepage and assign your form-template to it. Lets say the url of it is "/contactform/".
  • Go to your Editor and write into your template file some code like that:
<?php

if($input->post->aFormFieldName) {
    // a user has send the form, proceed the data and display a thank you message
    ...
    echo "<h4>Thank you for contacting us. We will get back to you soon.";

    return;  // stop with template code here
}

// if we have no post data, lets display a html form
$myForm1 = "
    <form action='{$page->url}' method="post">
        // your inputfields and buttons here
    </form>
";

echo $myForm1;

Now go to the browser and call:  example.com/contactform/ and try it out.

If you use a profile with header.inc and footer.inc, add it to the template file like it is within the other template files:

<?php

include("./head.inc");

    if($input->post->aFormFieldName) {
        // a user has send the form, proceed the data and display a thank you message
        ...
        echo "<h4>Thank you for contacting us. We will get back to you soon.";

        include("./foot.inc");  // load the footer here, because we stop template execution in the nest row!

        return;  // stop with template code here
    }

    // if we have no post data, lets display a html form
    $myForm1 = "
        <form action='{$page->url}' method="post">
            // your inputfields and buttons here
        </form>
    ";

    echo $myForm1;

include("./foot.inc");

Have fun! :)

thanx Horst, I will try this.

Link to comment
Share on other sites

  • 2 years later...
23 hours ago, yetkind said:

How can I make it work via processwire ? 

What's the thing you do not understand ?  Did you tried to follow this post ?

 

There are another example:

 

A tutorial where you can took inspiration for processing your form :

 

And a ton of references there:

https://encrypted.google.com/search?q=processwire+contact+form

  • Like 3
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

×
×
  • Create New...