Create Contact Us Form

Create Contact Us Form

by Nishant Pandya -
Number of replies: 9

Hi guys !! I am using moodle 2.9 version. I want to create a contact us form. I want to display that form in new url like http://www.moodlesite.com/contactus. Is there any plugin ? If you guys suggest custom page to create contact us then how can I do. Below are the image :


I have also try to module : http://moodle.org/download.php/modules/contact_form.zip. But I am getting error while installing, I think issue of version.

Thanks,

Nishant

Average of ratings: -
In reply to Nishant Pandya

Re: Create Contact Us Form

by Simon Rediss-Whitfield -

This is something you probably shouldnt do but it would be quick and easy....why do you not copy the source and edit the HTML so it looks as you want and then create a page through the resources in moodle and then just insert and edit the button?

In reply to Simon Rediss-Whitfield

Re: Create Contact Us Form

by Nishant Pandya -

Thanks for quick reply Simon. 

You mean that custom page creating a best way ?

But how do admin know that results ? That whom send what ?


Thanks,

Nishant

In reply to Nishant Pandya

Re: Create Contact Us Form

by Simon Rediss-Whitfield -

You can set your own conditions on the button so you can have the send button send an email to whoever which will contain the contents of the contact form.


All the source will do is provide you with the full layout, is this the best way to do it....probably not...or


use this html

<form name="htmlform" method="post" action="html_form_send.php">
<table width="450px">
</tr>
<tr>
 <td valign="top">
  <label for="first_name">First Name *</label>
 </td>
 <td valign="top">
  <input  type="text" name="first_name" maxlength="50" size="30">
 </td>
</tr>
 
<tr>
 <td valign="top"">
  <label for="last_name">Last Name *</label>
 </td>
 <td valign="top">
  <input  type="text" name="last_name" maxlength="50" size="30">
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="email">Email Address *</label>
 </td>
 <td valign="top">
  <input  type="text" name="email" maxlength="80" size="30">
 </td>
 
</tr>
<tr>
 <td valign="top">
  <label for="telephone">Telephone Number</label>
 </td>
 <td valign="top">
  <input  type="text" name="telephone" maxlength="30" size="30">
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="comments">Comments *</label>
 </td>
 <td valign="top">
  <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
 </td>
 
</tr>
<tr>
 <td colspan="2" style="text-align:center">
  <input type="submit" value="Submit">   ( <a href="http://www.freecontactform.com/html_form.php">HTML Form</a> )
 </td>
</tr>
</table>
</form>


and use this php


<?php
if(isset($_POST['email'])) {
     
    // CHANGE THE TWO LINES BELOW
    $email_to = "you@yourdomain.com";
     
    $email_subject = "website html form submissions";
     
     
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
     
    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');      
    }
     
    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required
     
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
     
    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";
     
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
?>
 
<!-- place your own success html below -->
 
Thank you for contacting us. We will be in touch with you very soon.
 
<?php
}
die();
?>

Average of ratings: Useful (5)
In reply to Simon Rediss-Whitfield

Re: Create Contact Us Form

by Nishant Pandya -

Thanks Simon. Thanks a ton. I'll try this & let you know if I am getting any error. 

Thanks,

Nishant

In reply to Nishant Pandya

Re: Create Contact Us Form

by Usman Asar -
Picture of Plugin developers Picture of Testers

Nishant, although Simon has already assisted you to build your own form, but another easier way would be using Google Forms and regarding putting them into your moodle, using static_pages plug-in by Alexander, you can find the plug-in in directory, its barely 5 mins work.

Average of ratings: Useful (1)
In reply to Usman Asar

Re: Create Contact Us Form

by Nishant Pandya -

Oh gr8 Usman Asar.

May you please help me how can I do this using Google Forms & synchronize in moodle.

Thanks,

Nishant

Average of ratings: Useful (1)
In reply to Nishant Pandya

Re: Create Contact Us Form

by Simon Rediss-Whitfield -

Hi Nishant,


The plugin which has been referred to is;

https://moodle.org/plugins/view/local_staticpage

If you are not too technical and new to moodle I still think that the code I provided is alot easier as all you need to to do is change the url and email in the code.

I hope we have provided you with an answer to get you started anyway, and thanks for making me aware of the plugin Usman, its not one I had come across before.



 

In reply to Simon Rediss-Whitfield

Re: Create Contact Us Form

by Usman Asar -
Picture of Plugin developers Picture of Testers
Youre welcome Simon, start adding plug-ins to your database (favorites) like I have nearly 100's by now, and this static_page is my most used one for it inherits the CSS properties, plus easier to use then traditional method of adding pages to front page.
You may want to check Alex's other plug-ins too, I have found all very useful.
In reply to Nishant Pandya

Re: Create Contact Us Form

by Usman Asar -
Picture of Plugin developers Picture of Testers

Nishant, though Simons code is straight work, use plug-in, copy/paste the code and you are done and better off with it, with Google Forms, it will be easier too, but your queries will land into an excel sheet, not email.

if you are still stuck with it, lemme know.