Citytech Tester Posted June 11, 2015 Share Posted June 11, 2015 Hello all I am new to processWire. I want a simple contact form in my website. Please tell how can i add contact form in my website. Thanks Link to comment Share on other sites More sharing options...
adrian Posted June 11, 2015 Share Posted June 11, 2015 Hi there! This module might be your easiest option: http://modules.processwire.com/modules/simple-contact-form/ There are other modules and you can also build a contact form manually, so let us know if this doesn't suit your needs and we can provide more info. 1 Link to comment Share on other sites More sharing options...
iNoize Posted June 11, 2015 Share Posted June 11, 2015 Hello, for me worked the tutorial from Soma https://processwire.com/talk/topic/2089-create-simple-forms-using-api/ in most cases fine. (I HATE TO CODE FORMS BUT ITS NECESSARY ) This is for the PHP Code. For Example you can Put it in the contact-template.php <?php $out = ''; // create a new form field (also field wrapper) $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name",'subscribe-form'); //generate the Form with <form id="subscribe-form" ... // create a text input $field = $modules->get("InputfieldText"); $field->label = "Name"; $field->attr('id+name','name'); $field->required = 1; $field->attr("class" , $field->attr("class") . " form-control"); // generate <input id="name" class=" form-control ..... " $form->append($field); // append the field to the form // create a text input $field = $modules->get("InputfieldText"); $field->label = "Adresse"; $field->attr('id+name','adresse'); $field->required = 1; $field->attr("class" , $field->attr("class") . " form-control"); $form->append($field); // append the field to the form // create a text input $field = $modules->get("InputfieldText"); $field->label = "Plz/Ort"; $field->attr('id+name','plz'); $field->required = 1; $field->attr("class" , $field->attr("class") . " form-control"); $form->append($field); // append the field to the form // create email field $field = $modules->get("InputfieldEmail"); $field->label = "E-Mail"; $field->attr('id+name','email'); $field->required = 1; $field->attr("class" , $field->attr("class") . " form-control"); $form->append($field); // append the field // create a text input $field = $modules->get("InputfieldTextarea"); $field->label = "Nachricht"; $field->attr('id+name','text'); $field->attr("class" , $field->attr("class") . " form-control"); $field->required = 1; $form->append($field); // append the field to the form // oh a submit button! $submit = $modules->get("InputfieldSubmit"); $submit->attr("value","Absenden"); $submit->attr("class"," btn btn-lg btn-primary"); $submit->attr("id+name","submit"); $form->append($submit); // form was submitted so we process the form if($input->post->submit) { // user submitted the form, process it and check for errors $form->processInput($input->post); // here is a good point for extra/custom validation and manipulate fields $email = $form->get("email"); if($email && (strpos($email->value,'@hotmail') !== FALSE)){ // attach an error to the field // and it will get displayed along the field $email->error("Bitte Email eingeben."); } if($form->getErrors()) { // the form is processed and populated // but contains errors $out .= $form->render(); } else { // do with the form what you like, create and save it as page // or send emails. to get the values you can use // $email = $form->get("email")->value; // $name = $form->get("name")->value; // $text = $form->get("text")->value; // // to sanitize input $name = $sanitizer->text($input->post->name); $adresse = $form->get("adresse")->value; $plz = $form->get("plz")->value; $message = $form->get("text")->value; $subject = "Web Anfrage"; // $emailFrom = $form->get('email')->value; $emailFrom = $sanitizer->email($form->get("email")->value); $emailTo = 'youremail@domain.com'; $body = "Die Email ist von ".$name."\r\n"."\r\n".$adresse."\r\n".$plz."\r\n".$message; mail($emailTo, $subject, $body, "From: $emailFrom"); $out .= "<h2>".$name."</h2><h2> Ihre nachricht wurde versendet.</h2>"; } } else { // render out form without processing $out .= $form->render(); } ?> and at the place where you will have your form you can use <?php echo $out; ?> Its not 100% perfect solution but as I was new to processwire and also PHP it works for me. 1 Link to comment Share on other sites More sharing options...
Raymond Geerts Posted June 11, 2015 Share Posted June 11, 2015 I'm using FormBuilder for mostly all forms its a small investment (since it is a commercial module). But it saved many hours of coding and debugging. And as additional benefit it supports Ryan (the creator of ProcessWire) in a little way. 3 Link to comment Share on other sites More sharing options...
Citytech Tester Posted June 12, 2015 Author Share Posted June 12, 2015 Hello iNoize Thanks for your help. You code worked for me. Thanks a lot. Link to comment Share on other sites More sharing options...
giannisok Posted September 6, 2016 Share Posted September 6, 2016 Check my post here: Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now