Jump to content

Simple Contact Form


justb3a

Recommended Posts

I have installed the module and the page appears as expected. The submit button works and redirects to the success page, or not if it detects spam.

No emails are sent and I get the following errors in the log:

[ERROR] Mail has not been sent to Name 

[ERROR] Additional mail could not be sent to Name

running PW 3.0.123 on PHP 7.1.31

I have searched the forum for a solution. Can anyone suggest where else I might look to solve this?

Link to comment
Share on other sites

In a local environment like Laragon you have to enable mail-catcher or an external SMTP.
In case of MAMP there may be similar settings.

With a local Linux environment you most likely will need sendmail, msmtp or a similar setup.

When this happens on a regular hosting plan your provider might have disabled this feature.

I'd recommend a look at WireMail: SMTP as it uses an external SMTP server/mail account (which you define).

I'd say it's the most reliable way to send emails from within ProcessWire. But that's just my opinion.

Link to comment
Share on other sites

Thanks wbmnfktr,
you put me on the right track. I had WireMail: SMTP installed but not configured. I actually uninstalled the module and emails are now being sent. 

I am having an issue where an email is sent to my address, but not to the person using the Contact form. 

The following is in the contact page template:

<?php $scf = $modules->get('SimpleContactForm');
$options = array(
'btnClass' => 'butn1',
'btnText' => 'Send',
'emailMessage' => 'You have successfully sent a message to Rob',
'item_label' => "",
'classes' => array(
'item' => 'input-field'
)
);
echo $scf->render($options); ?>
<br ><br ><br ></div> </div>
<?php include('./includes/foot.inc'); ?>

 Any clues would be appreciated.

Link to comment
Share on other sites

1 hour ago, Rob(AU) said:

but not to the person using the Contact form.

So you want to send a copy to the website visitor itself?
Never tried it but... you can define additional recipients within the options and maybe even from within a hook.

<?php
$this->addHookBefore('SimpleContactForm::sendAdditionalMail', function(HookEvent $event) {
  $form = $event->arguments(0);
  $emailCopy = $form->get('scf_emailcopy');

  // more logic here

});

More details and another hook example at the bottom of the page: https://github.com/justb3a/processwire-simplecontactform

Link to comment
Share on other sites

  • 2 weeks later...

Hello,

Im usin SCF and I'm getting a lot of spam lately, is there any captcha or something else available for this. I'm not a coder so not really sure how to solve this on my own.

My code right now is:

              <?php $scf = $modules->get('SimpleContactForm');
					$options = array(
					  'btnClass' => 'sc_button sc_button_style_filled sc_button_size_medium',
					  'btnText' => 'Po&#353;lji',
					  'classes' => array(
						'item' => 'sc_form_item sc_form_field label_over'
					  )
					);
				echo $scf->render($options);

				?>

Any help is appreciated 😉

R

Link to comment
Share on other sites

  • 2 weeks later...
On 10/17/2019 at 7:25 PM, Roych said:

Hello,

Im usin SCF and I'm getting a lot of spam lately, is there any captcha or something else available for this. I'm not a coder so not really sure how to solve this on my own.

My code right now is:


              <?php $scf = $modules->get('SimpleContactForm');
					$options = array(
					  'btnClass' => 'sc_button sc_button_style_filled sc_button_size_medium',
					  'btnText' => 'Po&#353;lji',
					  'classes' => array(
						'item' => 'sc_form_item sc_form_field label_over'
					  )
					);
				echo $scf->render($options);

				?>

Any help is appreciated 😉

R

Are you using the honeypot technique as described here?

Link to comment
Share on other sites

I'm also getting a lot of spam lately. Due to previous issues my code is a bit different, and not so clear where/how to add the honeypot field. This is the contact page template code:

	$scf = $modules->get('SimpleContactForm');

	$options = array(
	'emailMessage' => "{$input->scf_name} from {$input->scf_location} with IP {$input->scf_ip} sent this message:   	
	{$input->scf_message}",
	'emailFrom' => $input->scf_email,
	'emailSender' => $input->scf_email,
	'emailReplyTo' => $input->scf_email,
	'markup' => array(
    'list' => "<div {style='width:75%;'}>{out}</div>",
    'item' => "<p {attrs}>{out}</p>"
    ),
	'classes' => array(
    'form' => 'form BFD_contact',
    'list' => 'list-item'
	)
	);

	echo $scf->render($options);

Thanks for any help.

Link to comment
Share on other sites

  • 8 months later...

Hi! I'm learning more about ProcessWire and PHP in general by practicing on the different modules.

I created a test form using the SimpleContactForm module and just adding 1 text field, 1 image upload and 1 file upload field. I've alternated between just one or the other and having both uploads.

Without the upload fields, the form gets handled correctly and is stored as a page, however when I add an upload field it returns the following error:

Fatal error: Uncaught Error: Call to a member function path() on null in C:\xampp\htdocs\avanzademo\wire\modules\Fieldtype\FieldtypeFile.module:220 Stack trace: #0 C:\xampp\htdocs\avanzademo\wire\core\WireHooks.php(924): ProcessWire\FieldtypeFile->hookProcessInput(Object(ProcessWire\HookEvent)) #1 C:\xampp\htdocs\avanzademo\wire\core\Wire.php(450): ProcessWire\WireHooks->runHooks(Object(ProcessWire\InputfieldImage), 'processInput', Array) #2 C:\xampp\htdocs\avanzademo\wire\core\InputfieldWrapper.php(961): ProcessWire\Wire->__call('processInput', Array) #3 C:\xampp\htdocs\avanzademo\wire\modules\Inputfield\InputfieldForm.module(155): ProcessWire\InputfieldWrapper->___processInput(Object(ProcessWire\WireInputData)) #4 C:\xampp\htdocs\avanzademo\wire\core\Wire.php(383): ProcessWire\InputfieldForm->___processInput(Object(ProcessWire\WireInputData)) #5 C:\xampp\htdocs\avanzademo\wire\core\WireHooks.php(823): ProcessWire\Wire->_callMethod('___processInput', Array) #6 C:\xampp\htdocs\avanzademo\wire\core\Wire.php(450): ProcessWi in C:\xampp\htdocs\avanzademo\wire\modules\Fieldtype\FieldtypeFile.module on line 220

I've been looking into the mentioned files but can't seem to find the exact error. I also looked through a couple of the posts already discussing similar issues in the forum but I can't quite pinpoint what would be a viable solution for this. 

If anyone can help point me in the right direction, I'd greatly appreciate it.

Link to comment
Share on other sites

Hi @Nicole Bardales 

I don't have a solution for you yet, but a recommendation that might help: Install TracyDebugger and you'll get a better output of your error and also some great tools for debugging your scenario. For example you can add bd($var) calls in your code and get a nice visual dump of your variable and can then track the issue down.

It is a great tool for learning PW and PHP in general because it makes a lot of things visible that are usually hidden somewhare in the memory 🙂 

Hope that helps a little 🙂 

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Hi,

I'm having troubles hiding the scf-website, I created a form.php with the following:

<?php namespace ProcessWire; ?>

<div class="form__item form__item--scf-website" id="wrap_Inputfield_scf-website" id='content'>
	<?php
	echo $modules->get('SimpleContactForm')->render(); 
	?>
</div>

I can't seem to hide the scf-website field, what should I add to the CSS?

Link to comment
Share on other sites

30 minutes ago, sjaaksken said:

I can't seem to hide the scf-website field, what should I add to the CSS?

First, if you want to wrap the module render code in a div, don't use that class and id (and don't use 2 ids for the same element). Once the form is rendered, you'll see that there is already a div with that class that wraps the field you wish to hide. In the CSS, just target that class:

.form__item--scf-website { display: none; }

Link to comment
Share on other sites

  • 8 months later...

@PWaddict Yes, I've got it working. I made a simple InputField that works with FlyDev's MarkupGoogleRecaptcha module so the reCaptcha can be added to the SimpleContactForm. Then, using the info on the SFC instructions page, I added the following hood to my ready.php file. I've attached the zip file of my field type if you want to take a look. I'm no expert, but I based it on another simple module.

$this->addHookBefore('SimpleContactForm::processValidation', function(HookEvent $event) {
  $form = $event->arguments(0);
  $recaptcha = $form->get('recaptcha');
  
  if (!$this->input->post->{'g-recaptcha-response'}) { // attach an error to the field
    $recaptcha->error(__('You didn\'t pass the reCaptcha test.')); // it will be displayed along the field
  }
});

 

FieldtypeRecaptcha.zip

  • Thanks 1
Link to comment
Share on other sites

  • 4 months later...

I need some help..

I´m trying to get the value of an select option field to display in the mail.

This is my code

  <?php
        $scf = $modules->get( 'SimpleContactForm' );
          
        $options = array(            
          'offert_typeoffacility' => 'offert_typeoffacility->title',
          'btnText' => 'Skicka förfrågan'
        );
        echo $scf->render( $options );
        ?>

And the "offert_typeoffacility" is the select option field. But it only renderering the value ID instead of the title?

I tried also the message option in the module backend.

Typ av fastighet: %offert_typeoffacility% but it only rendering the same ID.

Do you guys have any solution to this? Please help

Link to comment
Share on other sites

@Flashmaster82 I've just had a look at how I did this before. I used a select option field to list a booking times (10:00am, 10:30am,  etc). I probably got this from someone else on these forums because my comments for the code were more detailed than I usually do! 

Rather than use the message in the module settings, override it and use a message.php file:

	$scf = $modules->get('SimpleContactForm');
	include("./message.php");
	$options = array(
	  'emailMessage' => $emailMessage,
	   ...

Note: you shouldn't need 'offert_typeoffacility' => 'offert_typeoffacility->title' in the options.

In message.php, sanitise and get the field title like this:

   $facility  = $sanitizer->int($input->post->offert_typeoffacility);
   // (other fields)...

   // To get the value of an Options Field Type, you need to
   // first get the id submitted
   // then get all the options for that field
   // then use the eq for that option to get the title (eq starts with 0, so subtract 1 from the id)
   $field = $fields->get('offert_typeoffacility');
   $all_options = $field->type->getOptions($field);
   $theFacility = $all_options->eq($facility - 1)->title;

   $emailMessage = "Hello,
		Option: {$theFacility}
		... ";

I try to use Page Reference fields for SimpleContactForm selects now because it's even easier: $theFacility = $pages->get($facility)->title;

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By monollonom
      PageMjmlToHtml
      Github: https://github.com/romaincazier/PageMjmlToHtml
      Modules directory: https://processwire.com/modules/page-mjml-to-html/
      A module allowing you to write your Processwire template using MJML and get a converted HTML output using MJML API.
      This is considered to be in alpha and as such needs some testing before being used in production!

      About
      Created by Mailjet, MJML is a markup language making it a breeze to create newsletters displayed consistently across all email clients.
      Write your template using MJML combined with Processwire’s API and this module will automatically convert your code into a working newsletter thanks to their free-to-use Rest API.
      Prerequisite
      For this module to work you will need to get an API key and paste it in the module’s configuration.
      Usage
      Once your credentials are validated, select the template(s) in which you’re using the MJML syntax, save and go visualize your page(s) to see if everything’s good. You will either get error/warning messages or your email properly formatted and ready-to-go.
      From there you can copy/paste the raw generated code in an external mailing service or distribute your newsletter using ProMailer.
      Features
      The MJML output is cached to avoid repetitive API calls Not cached if there are errors/warnings Cleared if the page is saved Cleared if the template file has been modified A simple (dumb?) code viewer highlights lines with errors/warnings A button is added to quickly copy the raw code of the generated newsletter Not added if the page is rendered outside of a PageView Only visible to users with the page’s edit permission A shortcut is also added under “View” in the edit page to open the raw code in a new tab Multi-languages support
      Notes
      The code viewer is only shown to superusers. If there’s an error the page will display:
      Only its title for guests Its title and a message inviting to contact the administrator for editors If you are using the markup regions output strategy, it might be best to not append files to preserve your MJML markup before calling the MJML API. This option is available in the module’s settings.
    • By Marco Ro
      Hi guys!
      I'm a bit anxious because this is the first module I present! (beta modulo) But I will finally be able to share something with the community too! :)
      This is a BETA version of the PayPal payment system called: PayPal Commerce Platform.
      It is an advanced system (Business Pro account is needed) that brings various benefits in terms of fees and above all integrates direct payment with credit/debit cards. 
      The module integrates with Padloper 0.0.2, which is the current installation I'm using.
      This system integrates the classic PayPal buy button, the alternative or local payment method and the new payment system: credit/debit cards that doesn't go through the PayPal account. It is a Stripe-style payment, it connects directly with the bank and integrates 3D security validation.
      I say that it is a BETA because this module currently only works with Sandbox account, to put it live you need to change API url manually (manually for the moment).
      Because this module is not ready for live:
      I would like to have your opinion on how I built the module (is the first one I do). I don't want to share something that is not fish but I need a comparison with someone more experienced than me, for be sure that this is the best way to code the module.
      If you want to try this I created a git, you will find all the instructions for installation and correct operation. (Git has a MIT licensed)
      https://github.com/MarcooRo/processwire-PayPal-Commerce-Platform I hope I did something that you guys can like :)
    • By monollonom
      (once again I was surprised to see a work of mine pop up in the newsletter, this time without even listing the module on PW modules website 😅. Thx @teppo !)
      FieldtypeQRCode
      Github: https://github.com/romaincazier/FieldtypeQRCode
      Modules directory: https://processwire.com/modules/fieldtype-qrcode/
      A simple fieldtype generating a QR Code from the public URL of the page, and more.
      Using the PHP library QR Code Generator by Kazuhiko Arase.

      Options
      In the field’s Details tab you can change between .gif or .svg formats. If you select .svg you will have the option to directly output the markup instead of a base64 image. SVG is the default.
      You can also change what is used to generate the QR code and even have several sources. The accepted sources (separated by a comma) are: httpUrl, editUrl, or the name of any text/URL/file/image field.
      If LanguageSupport is installed the compatible sources (httpUrl, text field, ...) will return as many QR codes as there are languages. Note however that when outputting on the front-end, only the languages visible to the user will be generated.
      Formatting
      Unformatted value
      When using $page->getUnformatted("qrcode_field") it returns an array with the following structure:
      [ [ "label" => string, // label used in the admin "qr" => string, // the qrcode image "source" => string, // the source, as defined in the configuration "text" => string // and the text used to generate the qrcode ], ... ] Formatted value
      The formatted value is an <img>/<svg> (or several right next to each other). There is no other markup.
      Should you need the same markup as in the admin you could use:
      $field = $fields->get("qrcode_field"); $field->type->markupValue($page, $field, $page->getUnformatted("qrcode_field")); But it’s a bit cumbersome, plus you need to import the FieldtypeQRCode's css/js. Best is to make your own markup using the unformatted value.
      Static QR code generator
      You can call FieldtypeQRCode::generateQRCode to generate any QR code you want. Its arguments are:
      string $text bool $svg Generate the QR code as svg instead of gif ? (default=true) bool $markup If svg, output its markup instead of a base64 ? (default=false) Hooks
      Please have a look at the source code for more details about the hookable functions.
      Examples
      $wire->addHookAfter("FieldtypeQRCode::getQRText", function($event) { $page = $event->arguments("page"); $event->return = $page->title; // or could be: $event->return = "Your custom text"; }) $wire->addHookAfter("FieldtypeQRCode::generateQRCodes", function($event) { $qrcodes = $event->return; // keep everything except the QR codes generated from editUrl foreach($qrcodes as $key => &$qrcode) { if($qrcode["source"] === "editUrl") { unset($qrcodes[$key]); } } unset($qrcode); $event->return = $qrcodes; })
    • By Sebi
      AppApiFile adds the /file endpoint to the AppApi routes definition. Makes it possible to query files via the api. 
      This module relies on the base module AppApi, which must be installed before AppApiFile can do its work.
      Features
      You can access all files that are uploaded at any ProcessWire page. Call api/file/route/in/pagetree?file=test.jpg to access a page via its route in the page tree. Alternatively you can call api/file/4242?file=test.jpg (e.g.,) to access a page by its id. The module will make sure that the page is accessible by the active user.
      The GET-param "file" defines the basename of the file which you want to get.
      The following GET-params (optional) can be used to manipulate an image:
      width height maxwidth maxheight cropX cropY Use GET-Param format=base64 to receive the file in base64 format.
    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
×
×
  • Create New...