nliautaud / p01contact

Create contact forms by writing simple tags. Also a plugin for GetSimple and Pico CMS.
MIT License
16 stars 15 forks source link

form action correction #3

Closed neurobox closed 7 years ago

neurobox commented 9 years ago

Hi I'm a bit of a git noob, but I'll contribute this... The form has appeared to stop working because instead of actually submitting to the same page, e.g. /contact-us/#p01contact, it goes to /#p01contact. I'm not sure what's behind this behavior, but found that it behaves correctly if you replace action="#p01contact" with just action="", which forces a reload of the same page.

nliautaud commented 9 years ago

Hi, You're right, but the anchor is useful as it allow to focus on the submitted form. If it's not off-screen and if you don't have several ones on the same page you can get rid of the action parameter (instead of an empty value). It should be fixed by using the absolute url of the page instead. Something like :

$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$html  = '<form action="' . $url . '#p01-contact' . $this->id . '" autocomplete="off" ';

Feel free to give it a try.