guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.04k stars 1.31k forks source link

HOW TO send form content via email after parsley validation #114

Closed nici99 closed 11 years ago

nici99 commented 11 years ago

Hello,

first a great THANK YOU for this great form validation!

I don't know if I'm here at the right place...

I’m new with javascript / ajax – so I have no idea how to send the form content after parsley validation via email (or to database).

I had a solution for that already with php – but validation was not working like I wanted it to ;-) Now I have perfect validation but don’t know how to send it …

How can I add further event/s to ... onClick="javascript:$('#form').parsley( 'validate' );"> ?? I want the data of the fields to be red out, inserted into mailbody.txt and sent AFTER PARSLEY VALIDATION (preferably with one click for the user), further I'd like to give the user a message like "Thank you! We will reply to you soon!" or link user to thank you page. If data is additionally sent to database it would be perfect!

I don't care if I use js/ajax or php for that, I'd like to implement "the best and safest" solution (I know it's org.apache.wicket.ajax.WicketAjaxReference ... or something with sessions - but I don't get it yet ;-)) I guess I have to call this 2nd event somewhere within/after onFormSubmit: function ( isFormValid, event, ParsleyForm ) {} -> or does there exist an "easy way" by jquery?

I've red a lot of code the last days on different sites but I don't get it...

see for example mail.php:

<?php header( 'Content-Type: text/html; charset=utf-8' ); $myemail = 'myemail@abcdefg.com';

if (isset($_POST['submit'])) // --> if (parsley validation is ok) instead { include( 'functions.inc.php' ); // --> this does parsley validation

cleanInput(); // --> I don't know how to prevent email-injection in js/ajax an if necessary? I don't like captcha as a user so I also don't like it at my form...

$name = checkName( $_POST['name'] ); // -->  collect fied inputs - get js object with inputs instead...

// --> and insert them into mailbody.txt
$mailbody1 = file_get_contents( 'mailbody1.txt');
// --> placeholders
$mailbody1 = str_replace( '###NAME###', htmlspecialchars( $name ), $mailbody1 );
$mailbody1 = str_replace( '###EMAIL###', $email, $mailbody1 );
...
$mailheader1 = "From: MyPage NoReply <noreply@" .$_SERVER['SERVER_NAME']. ">\r\n";
$mailheader1 .= "Reply-To: " .$name. "<" .$email. ">\r\n";
...
// --> send mail(s)     
    if((@mail( $myemail, "Message from MyPage", $mailbody1, $mailheader1 )) && (@mail( $email, "Confirmation of your message to MyPage", $mailbody2, $mailheader2 )))       {

// --> return thank you message or link to thank you page
        return('Thank you, we will reply to you soon.');

// --> I'd prefer here js/ajax too - there is for sure a better solution existing than header in php    
        header("refresh:8;url=/kontakt.html/");
        exit;
    }

} ?>

I know the preview is not perfect but I hope you know what I mean... Coud someone help me with that? How did you get this working? I'd be very thankful for your help!

@catearcher Wie hast Du das mit den Umlauten hinbekommen? Bei den Umlauten selbst erhalte ich komische Zeichen, ich habe es dann mit den html Sonderzeichen versucht aber wird eben genau so angezeigt... ich habe auch schon recherchiert und probiert js utf-8 Code Schnipsel in das Script einzufügen aber dann hat nichts mehr gefunkt... dafür bin ich einfach noch zu schwach...

Danke auf jeden Fall für Deine Übersetzung und viell. kannst Du mir ja einen Tipp geben? Ich habe vorerst mal alle Sätze mit Umlauten umgeschrieben ... wobei mir "gültig" schon besser gefallen würde ;-) ... aber bei "größer" habe ich dann "oe" verwendet...

Kind regards Nici

guillaumepotier commented 11 years ago

Hi.

I'm sorry but I cannot help you here on building a complex form mail system with database, ajax and PHP. I'm just here to listen for Parsley enhancements, feature requests or bugs repport.

I think stackoverflow would be a much more fitted place to ask some help here (Parsley validation is just a tiny brick in the complex behavior you want to implement.)

Thanks for you understanding.

Best

nici99 commented 11 years ago

I understand that, I just thought I try ;-) Thank you for your hint. I'll ask for that at stackoverflow like you recommended.

THX