Jump to content

Contact form Issues


Recommended Posts

Well I got this form done a while ago and am trying to debug why all the sudden it's not submitting any values for name,email,tel, and comments.

I used soma's code to do this and its great but I thought someone might see the answer hidden in here. Thanks in advance for helping me out :)

<div class="modal fade" id="contactModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
		<div class="modal-header">
			<!--p id="id2" name = "id2" style="display:none;"></p>-->
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
			<div class="modal-body">
$sent = false;
$contactEmail = $page->parent->Employee_Email;

if ($page->parent->path == "/exhibitions/contemporary/"){
	$contactEmail = $pages->get(1248)->Employee_Email;
if ($page->parent->path == "/exhibitions/antique/"){
	$contactEmail = $pages->get(1249)->Employee_Email;
if ($page->parent->path == "/exhibitions/modern/"){
	$contactEmail = $pages->get(1250)->Employee_Email;

// sanitize form values or create empty
$form = array(
    'fullname' => $sanitizer->text($input->post->fullname),
    'email' => $sanitizer->email($input->post->email),
	'tel' => $sanitizer->text($input->post->tel),
	'url' => $page->httpUrl,
    'comments' => $sanitizer->text($input->post->comments),

// check if the form was submitted
if($input->post->submit) {

	$artid = $input->post->artinfo;
	$artwork = $pages->get($artid);

	$artinfo = "Artist: " . $sanitizer->text($artwork->parent->artist_firstname);
	$artinfo .= " " . $sanitizer->text($artwork->parent->artist_lastname) . "\n";
	$artinfo .= "Title: " . $sanitizer->text($artwork->title);

//foreach($form as $key => $value) {
//	if ($key != 'tel'){
//		if( strlen(trim($value)) == 0 ) {
//		  $error = true;
//		  break;
//    }
//	}

    // if no errors, email the form results
    if($input->post->url == "" && !$error) {
        $msg = "Full name: $form[fullname] \n" . 
               "Email: $form[email] \n" . 
			   "Phone: $form[tel] \n" . 
			   "URL: $form[url] \n\n" .
			   "-------------------\n\n" .
			   "$artinfo" .
			   "\n\n-------------------\n\n" .
               "Message: $form[comments]";

        mail($contactEmail,"Website Inquiry", $msg, "From: notifier@davidsongalleries.com");

		$session->redirect("./", false);
		$mailed = true;

if(!$sent) {
    // sanitize values for placement in markup
    foreach($form as $key => $value) {
        $form[$key] = htmlentities($value, ENT_QUOTES, "UTF-8"); 

    // append form to body copy
    echo <<< _OUT

		<form id="contact" action="./" method="post">
        <label for="fullname">Your Name</label><span class="error">( required )</span>
        <input id="contact_fullname" class="form-control required" type="text" name="fullname" value="$form[fullname]" />
		<p class = "antispam">
		<input class="nc" type="text" name="url" value = "">

        <label for="email">Your Email</label><span class="error">( required )</span>
        <input id="contact_email" class="form-control required" type="email" name="email" value="$form[email]" />
        <label for="tel">Your Phone Number (Optional)</label><br />
        <input class="form-control nc" type="tel" name="tel" value="$form[tel]" placeholder="Enter phone number only if you wish to be called about this inquiry" />

        <label for="comments">Comments</label><span class="error">( required )</span>
        <textarea id="contact_comments" class="form-control required" rows="10" name="comments">$form[comments]</textarea>
		<!-- field to hold the art information-->
		<p class = "emailartinfo">
		<input type="text" class="form-control nc" name="artinfo" id="sendartinfo" value=""> </input>


        <div class="modal-footer">
        <input id="submitQuestion" class="btn btn-default" type="submit" name="submit" value="submit" />
	 <a href="#" class="btn btn-default" data-dismiss="modal">Cancel</a>


Link to comment
Share on other sites

Hard to tell ;)

Did you echo out $_POST or checked the request with DevTools/Firebug if there are really no values sent?

Often this happens because people forget to add a trailing slash to ProcessWire urls in the form action. In this case, Pw does a redirect and you loose post variables.

One thing you could try is changing:



action="<?= $page->url ?>"

although I'm pretty sure it's not the issue...

  • Like 1
Link to comment
Share on other sites

Hey thank you guys so I got it. Every solution I ever have come right about when Im falling asleep. It turns out I have a script that that clears the form when the modal closes but when you submit the modal closes before post is done processing. Total noob mistake, I just removed the form clear from submit click and it worked :)
			$('#contactModal').on('hidden.bs.modal', function (e) {

So the email was sending perfectly just without any form values that were entered. I guess I forgot about the fact that I used a redirect on send also. 

  • 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By flydev 👊🏻
      Bootstrap-4 Minimal site profile for ProcessWire
      This profile is based on the "minimal site profile (intermediate edition)" and bundled with Boostrap v4.4.1
      Bootstrap SASS Font-Awesome SASS Render / helper functions for : Simple ul navigation Bootstrap Multi-level navbar Bootstrap Carousel Bootstrap Cards Bootstrap Jumbotron Boostrap Accordion Assets minification, files bundle   Dependencies
      jQuery Popper.js Bootstrap FontAwesome   Prequisites
       You'll want to install the following on your system before proceeding:
      Yarn / NPM How To Install
      Download the zip file at Github or clone directly the repo with git clone and skip the step 2. Extract the folder site-pwbs4-master into a fresh ProcessWire installation root folder. During the installation of ProcessWire, choose the profile "ProcessWire Bootstrap 4 profile".   After installation
      You can find the development file (CSS/SCSS/JS) in site/assets/dev/src
      The profile can be used as is only with $config->debug set to false. To use it in debug mode, you are required to install the dependencies with the package manager.
      Open a terminal in site/assets/dev and execute the following command-line: yarn Available commands :
      Rebuild, minify and bundle assets for release : yarn build   References
      Bootstrap v4 documentation ProcessWire documentation ProcessWire Forum: bootstrap tag ProcessWire Forum: bootstrap related posts   Credits
      The ProcessWire staff Inspiration from @gebeer and his Bootstrap 3 profile post Members who contributed in various post about Bootstrap navigation and code (see code-source for refs). Screenshots

    • By MarkE
      This post is related to 
      but is a different way of tackling the problem.
      The idea is to use the JqueryUI.module in the front end to present a restricted access admin page in a modal (class pw-modal). However the JqueryUI module doesn't seem to work properly in the front end (I have it working in the back end OK). I'm guessing that this is because the front end page has not loaded all the .js that is needed (that would normally be loaded in the back end). My _main.php loads the following from the core at the moment:
      'wire/modules/AdminTheme/AdminThemeUikit/uikit/dist/js/uikit.min.js' 'wire/modules/AdminTheme/AdminThemeUikit/uikit/dist/js/uikit-icons.min.js' 'wire/modules/Jquery/JqueryCore/JqueryCore.js' 'wire/modules/Jquery/JqueryUI/JqueryUI.js' Any ideas what else I need, or have I got hold of the wrong end of the stick?
    • By Marcel
      I am very new to processwire and bootstrap. I have a field (text area) and there I want to be able to insert an image which is responsive. I tryed it with Source but in the end the page doesn't seem to like it when I insert in Source the following code
      <img src="<?php echo $homepage->content_img->url; ?>" class="img-fluid" alt="Responsive image"> What can I do to make it possible to insert reponsive images in a text area?
      Thank you in advance.
    • By modifiedcontent
      I have one central website, with membership registration and content etc., and then several related websites with their own URL/domains, each on Processwire, all on the same server.
      I would like to access the database of the central website from the sister websites. How would I do that?
      You can't bootstrap one PW installation into another. You can include template parts from one in the other by just using the server path, but whatever you try to get/post just comes/goes to the database of the site you are on.
      Could you switch databases by including the config.php from another PW installation somewhere?
      What is the correct, secure way to do this?
    • By androbey
      Hello again! 

      Unfortunately I came across another problem. 

      I have a "regular" ProcessWire setup and want to create a separate php script. That script should be executed by a cron job and is bootstrapped with my PW setup. Main goal is to send mails which are stored in a email field. 
      My problem: I want to access a specific field from a template where only specific users have access to. Right now, the cron job is executed as "guest", of course. 

      How can I bypass this restriction, so that I have access to that specific field (it's only one email field)? 

      Does it make sense to set current user via api? 

      Hope you can help me out there.

  • Create New...