Jump to content

Advanced contact form


Amazzing

Recommended Posts

Hello,

 

I am looking for a developer, who could improve the default contact form or create a new one.

 

The contact form has to contain about 10 additional text fields. Some of them required, some of them not required.

 

Some fields are bundled in a group.

User can add extra groups, if required.

 

an example of the form:

form_required.png

 

No need to care about design.

No need to care about integration with BO.

 

After all modifications are made, a brief description of how to add new fields is enough.

Edited by Amazzing (see edit history)
Link to comment
Share on other sites

I'm not a developer - just do enough when I can't find someone to do the work at a reasonable price. I recently created custom forms, and while I don't have enough time right now to hunt down every piece, the jest is this: You need to create a new .tpl file in your theme corresponding to your new form page, for example, dynamic.tpl. You will then need to create a controller DynamicController.php (/themename/controllers/front/) and php file dynamic.php (/themename) associated with this new form page. Use the contact-form file locations as a guide. Inside the Controller, you will need to accept the new form name/values that you create in dynamic.tpl. Here's part of the code, so hopefully this gives you a start. If you're still needing help a few weeks from, email me, and I'll give you a hand - I have customer that needs nearly exactly what you're looking for.

 

public function postProcess()
{
 if (Tools::isSubmit('submitMessage'))
 {
  $fileAttachment = null;
  if (isset($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['tmp_name']))
  {
   $extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg');
   $filename = uniqid().substr($_FILES['fileUpload']['name'], -5);
   $fileAttachment['content'] = file_get_contents($_FILES['fileUpload']['tmp_name']);
   $fileAttachment['name'] = $_FILES['fileUpload']['name'];
   $fileAttachment['mime'] = $_FILES['fileUpload']['type'];
  }
  //$message = Tools::getValue('message'); // Html entities is not usefull, iscleanHtml check there is no bad html tags.
  $fullname = Tools::getValue('fullname');
  $phone = Tools::getValue('phone');
  $companyname = Tools::getValue('companyname');
  $message = $fullname." ".$phone." ".$companyname;
  if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from))
   $this->errors[] = Tools::displayError('Invalid email address.');
  /*else if (!$message)
   $this->errors[] = Tools::displayError('The message cannot be blank.');
  else if (!Validate::isCleanHtml($message))
   $this->errors[] = Tools::displayError('Invalid message');*/
  else if (!($id_contact = (int)(Tools::getValue('id_contact'))) || !(Validate::isLoadedObject($contact = new Contact($id_contact, $this->context->language->id))))
   $this->errors[] = Tools::displayError('Please select a subject from the list provided. ');
  /*else if (!empty($_FILES['fileUpload']['name']) && $_FILES['fileUpload']['error'] != 0)
   $this->errors[] = Tools::displayError('An error occurred during the file-upload process.');
  else if (!empty($_FILES['fileUpload']['name']) && !in_array(substr(Tools::strtolower($_FILES['fileUpload']['name']), -4), $extension) && !in_array(substr(Tools::strtolower($_FILES['fileUpload']['name']), -5), $extension))
   $this->errors[] = Tools::displayError('Bad file extension');*/
  else
  {

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...