Giter Club home page Giter Club logo

Comments (24)

mzur avatar mzur commented on May 30, 2024

I've just tested it with my template looking like this:

<?php snippet('header') ?>
   <main class="main" role="main">
      <?php snippet('form') ?>
   </main>
<?php snippet('footer') ?>

And site/snippets/form.php exactly containing the basic example code. It worked fine.

Could you copy & paste both template and snippet code and try again?

from kirby-uniform.

kayspiegel avatar kayspiegel commented on May 30, 2024

Thx @mzur I tested some variations yesterday myself and it worked. I think it's because of the way the data is passed through on the one-pager solution http://getkirby.com/docs/solutions/one-pager. I'm using that structure for an actual client project.

The main template (I'm only using one) looks like this:

<?php
snippet('header');
foreach($pages->visible() as $section) {
   snippet($section->uid(), array('data' => $section));
}
snippet('footer');

The snippet itself is just the basic code as you published it.

Any clue on where I'm doing something wrong?

from kirby-uniform.

mzur avatar mzur commented on May 30, 2024

For me it even works with the one-pager template. Maybe you could provide a little more of your templates/snippets that don't work so I can reproduce the behaviour?

from kirby-uniform.

kayspiegel avatar kayspiegel commented on May 30, 2024

Weird ... I just tryed your updated code on a clean one-pager slate and it worked as well. Let my try later on with the page I'm working on. I don't want to mess with that code right now. I'll let you know if it worked.

from kirby-uniform.

afmklk avatar afmklk commented on May 30, 2024

I'm having the same problem. I think it may be related to the controller code? Where do you put it in a one-pager with a form in a snippet/snippet.php? If I put it in controllers/home.php (with templates/home.php being my main one-pager template) I get "Undefined variable: form" error. If I put it in controllers/snippet.php the form shows but no email is being sent.

from kirby-uniform.

mzur avatar mzur commented on May 30, 2024

@rik84 It should work if you put the controller code to controllers/home.php (since controllers are for templates only, I understand) and then pass on the $form variable to the snippet like this:

snippet($section->uid(), array('data' => $section, 'form' => $form));

And don't forget to export the $form variable from the controller, otherwise it would always be undefined in the template.

from kirby-uniform.

wtip avatar wtip commented on May 30, 2024

I am experiencing a similar issue. I put my contact form in a snippet and used it in a template for a contact-us sup page and it worked without any issues. Now I've added the snippet to a section on the home page (I also added the home controller stuff) but the form doesn't work.
When I look at the form source I can see that the button has a token that was generated by $form->token() so the controller must be working. However when I submit the form the page reloads, the form is empty and there is no success or error message.

I did discover that when I add /home to the end of the form action action="<?php echo $page->url()?>/home" it actually works. However since I want to use the form as a snippet this is not great solution.
Is this a bug with kirby or with the uniform plugin?

from kirby-uniform.

mzur avatar mzur commented on May 30, 2024

@wtip I just implemented a form as a snippet on the home page and it works fine for me. Does $page->url() return the correct URL of your home page? Is there a redirect or something from your site root to the home page?

from kirby-uniform.

wtip avatar wtip commented on May 30, 2024

$page->url() does return the correct URL of the home page. Though the home page has two correct URLs. One being the bare domain example.com and the other being example.com/home I wonder if it has anything to do with my use of routes?

c::set('routes', array(
  array(
    'pattern' => 'tag/(:any)',
    'action'  => function($tag) {

      $data = array('tag' => $tag);
      site()->visit('articles');
      return array('archive', $data);

    }
  ),
  array(
    'pattern' => '(:num)/(:num)/(:num)',
    'action'  => function($year, $month, $day) {

      if(($year > 0 && $year <= 9999)
          && ($month > 0 && $month <= 12)
          && ($day > 0 && $day <= 31)) {
          $data = array('year'  => $year,
                        'month' => $month,
                        'day'   => $day);
          return array('archive', $data);
      } else {
          go('error');
      }
    }
  ),
  array(
    'pattern' => '(:num)/(:num)',
    'action'  => function($year, $month) {

      if(($year > 0 && $year <= 9999)
          && ($month > 0 && $month <= 12)) {
          $data = array('year'  => $year,
                    'month' => $month);
          return array('archive', $data);
      } else {
          go('error');
      }
    }
  ),
  array(
    'pattern' => '(:num)',
    'action'  => function($year) {
      if($year > 0 && $year <= 9999) {
        $data = array('year'  => $year);
        return array('archive', $data);
      } else {
        go('error');
      }
    }
  )
));

from kirby-uniform.

wtip avatar wtip commented on May 30, 2024

For now I am using this action="<?php echo url() ?>/<?php echo $page->slug() ?> to get a form action url that works on any page.

from kirby-uniform.

mzur avatar mzur commented on May 30, 2024

Does it work if you disable the routing?

from kirby-uniform.

 avatar commented on May 30, 2024

Could this be reopened? I'm having the same issue as @wtip, where the form suddenly stops working if I put it on the homepage. Following your example with <form action="<?php echo $page->url()?>" method="post"> does not work for me, but implementing @wtip last post, with action="<?php echo url() ?>/<?php echo $page->slug() ?> does make it work.

I'm thinking this is because something makes the form break when we're not on the correct url? Meaning that / is not treated equally as home, even though that is my homepage c::set('home','home');

from kirby-uniform.

mzur avatar mzur commented on May 30, 2024

@BeSports Can you make a quick Kirby setup where the form fails in exactly the way you are describing? Then I can download it and reproduce the error locally for debugging.

from kirby-uniform.

 avatar commented on May 30, 2024

Sure, see the attached file. So with the exact state as I set up, it's not working. However, when I change line 11 of templates/home.php to <form action="<?php echo $page->url()?>/<?php echo $page->slug() ?>" method="post">, it will work. The form will however redirect to (url)/home, which isn't ideal either.

kirbyform.zip

from kirby-uniform.

mzur avatar mzur commented on May 30, 2024

Your ZIP works for me out of the box with $page->url() 😕 What's your local environment? Do you run the site on an Apache? Are you redirected when you submit the form?

from kirby-uniform.

 avatar commented on May 30, 2024

I'm not redirected after the submit. Currently using XAMPP, but have no idea where to check what version it is I'm running..

from kirby-uniform.

mzur avatar mzur commented on May 30, 2024

It works for me both using the PHP dev server (PHP 7) and an Apache (PHP 5.6). I'm sorry but as long as I can't reproduce this problem I can't fix it 😕

from kirby-uniform.

 avatar commented on May 30, 2024

Is there any other way I could try debugging it for myself?
It's not that the plugin is now unusable, it's just a small anoying thing which I'd be happy to try finding a fix for :)

from kirby-uniform.

mzur avatar mzur commented on May 30, 2024

Sure, you can debug away on your own machine. One thing you can check easily is whether the token of the submit button changes each time you submit the form. If it changes there may be something wrong with the guard which decides that the request was invalid and resets the form although it shouldn't.

from kirby-uniform.

mzur avatar mzur commented on May 30, 2024

@kayspiegel @aufmkolk @wtip @BeSports
I now suspect that a redirect is causing this problem during which all form data is lost. Some server configurations will redirect a request e.g. from example.com/form to example.com/form/.

So please try changing your form's action URL from <?php echo $page->url()?> to <?php echo $page->url()?>/ and see if it works.

from kirby-uniform.

 avatar commented on May 30, 2024

Hey @mzur, like I said in my second post, adding the '/' does the trick for me indeed!

from kirby-uniform.

mzur avatar mzur commented on May 30, 2024

@BeSports But you added the page slug, too, right?

<form action="<?php echo $page->url()?>/<?php echo $page->slug() ?>" method="post">

It should work without the slug and with the / suffix only:

<form action="<?php echo $page->url()?>/" method="post">

from kirby-uniform.

 avatar commented on May 30, 2024

Yup, that's indeed the current way I'm doing it :)

from kirby-uniform.

mzur avatar mzur commented on May 30, 2024

Great, then I'll take this issue as resolved.

from kirby-uniform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.