FORUMS CLOSED DUE TO SPAM. YOU STILL CAN ADD POST!

Contact Form

Feed 9 posts, 4 voices

Avatar
11 posts

Well this must be a simple one, but not for me. I'm not a PHP guru :) I've searched the forum and Wiki but nothing, maybe a Tips and Tricks discussion where some one can post snippets of code would be great.

So the question: How to set up a contact form using frog?

Thanks guys.

 
Avatar
1493 posts

Philippe is "The Man", but here are some things you might check. I have next-to-no knowledge of PHP, but put together a small contact form for use at my workplace, but that was in independent, static HTML pages. I'm not sure what the best way to do this in Frog. Anyway, from simplest to most complex:

http://www.digital-web.com/articles/bulletproof_contact_form_with_php/

http://www.ibdhost.com/contact/

http://green-beast.com/blog/?page_id=71

Of course, Google will find you lots more! ;) Hope that helps, though.

 
Avatar
1493 posts

Actually, Vitor, I just realized: of course you should be able to adapt the "comment-form" snippet for use as a contact form. If you have the latest beta, Philippe has already provided that feature.

 
Avatar
11 posts

Thanks David, i really appreciate your replies, I'm going to see what i can do with the comment form.

 
Avatar
11 posts

Nop, can't find a way to make a contact form for frog, If someone as a plugin already done :) that will be great. If not, someone who could point me in the right direction would be great.

Thanks

 
Avatar
11 posts

Ok, I've managed to put a simple contact form to work with frog, based on the link David provided at top

http://www.digital-web.com/articles/bulletproof_contact_form_with_php/

soon as I have time I will try to put this in the wiki.

 
Avatar
541 posts

here is one :

<?php 
if (isset($_POST['commit']) && isset($_POST['contact']))
{
    $contact = $_POST['contact'];


    foreach ($contact as $key => $value)
    {
        $contact[$key] = trim($value);
    }

    if (empty($contact['name'])) $error_name = true; 

    if (empty($contact['email'])) $error_email = true;
    else if (! preg_match('/^[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]+(\.[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]+)*@(([a-z0-9]([-a-z0-9]*[a-z0-9]+)?){1,63}\.)+([a-z0-9]([-a-z0-9]*[a-z0-9]+)?){2,63}$/i', $contact['email'])) $error_email = true;

    if (empty($contact['subject'])) $error_subject = true;

    if (empty($contact['message'])) $error_message = true;

    if ( ! isset($error_name) && ! isset($error_email) && ! isset($error_subject) && ! isset($error_message))
    {
        $to = "votre_nom@votre_site_web.com";
        $headers  = "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=UTF-8\r\n";
        $headers .= "From: {$contact['name']} <{$contact['email']}>\r\n";

        mail($to, $contact['subject'], $contact['message'], $headers);
        $is_sended = true;
    }
}
?>

<?php if (isset($is_sended)): ?>

<p>Merci <b><?php echo $contact['name'] ?></b>!<br />Votre message nous a été transféré avec succès!<p>

<?php else: ?>

<form action="<?php echo $this->url() ?>" method="post">
  <div class="contact-left<?php if(isset($error_name)) echo ' error'; ?>">
    <label for="contact-name">Votre nom: </label>
  </div>
  <div class="contact-right">
    <input type="text" name="contact[name]" id="contact-name" size="30" maxlength="50" value="<?php if(isset($contact['name'])) echo $contact['name']; ?>" /> (requis)
  </div>
  <div class="contact-left<?php if(isset($error_email)) echo ' error'; ?>">
    <label for="contact-email">Votre email:</label>
  </div>
  <div class="contact-right">
    <input type="text" name="contact[email]" id="contact-email" size="30" maxlength="50" value="<?php if(isset($contact['email'])) echo $contact['email']; ?>" /> (requis)
  </div>
  <div class="contact-left<?php if(isset($error_subject)) echo ' error'; ?>">
    <label for="contact-subject">Subjet:</label>
  </div>
  <div class="contact-right">
    <input type="text" name="contact[subject]" id="contact-subject" size="30" maxlength="50" value="<?php if(isset($contact['subject'])) echo $contact['subject']; ?>" /> (requis)
  </div>
  <div class="contact-left<?php if(isset($error_message)) echo ' error'; ?>">
    <label for="contact-message">Votre message: </label>
  </div>
  <div class="contact-right">
    <textarea name="contact[message]" id="contact-message" cols="45" rows="15" ><?php if(isset($contact['message'])) echo $contact['message']; ?></textarea>
  </div>
  <div class="contact-right">
    <input type="submit" name="commit" value="Envoyer le message" id="contact-submit" />
  </div>
</form>

<?php endif; ?>
 
Avatar
541 posts

in french sorry ... but easy to understand I'm sure :P

 
Avatar
7 posts

I'm using Phillipe's contact form from #7 for a number of different people on the same site. It's only a general contact form, so rather than repeat the entire thing 4-5 times, I just created a dropdown that selects the addressee...

In the top php area;

if ($contact['sendto'] = general) $to = "info@company.com";
if ($contact['sentdo'] = editor) $to = "editor@company.com";
if ($contact['sendto'] = director) $to = "artdirector@company.com";

And down in the form itself (I preselected General Inquiries).

<label for="contact-sendto">Who are you contacting?</label>
<select id="contact-sendto" name="contact[sendto]">
    <option value="general" selected="selected">General Inquiries</option>
    <option value="editor">Jack, editor</option>
    <option value="director">Brandon, art director</option>
</select>
 
Avatar
7 posts

I also adjusted the message from the form, to make it clear that it has been sent through the site.

First, the subject line is from the Contact Form:

$subject = "Contact Form: {$contact['subject']}\r\n";

Then the form fields are written out for reference. I was having trouble with line breaks, so I wrapped the message body in nl2br().

$body = nl2br("From: $contact['name'] \n E-Mail: $contact['email'] \n Phone: $contact['phone'] \n\n Message: \n $contact['message']");

And finally,

    mail($to, $subject, $body, $headers);