Contact form in hidden div

I'm using Zen Photo's built in contact form. Currently the form is placed in a div that's initial state is hidden. A visitor to the site can click a link that makes the div visible and they can enter their data. That all works just fine. The problem comes in when the form is submitted. The div hides itself again. If you click the link that makes the div visible the contact form is performing as it should, asking the user to confirm their submission.

I know the problem is caused by the page reloading and setting the div back to it's original state. I've tried using a postback function, but I'm afraid that may strictly be an ASP command and not suitable for the php form. Does anyone have any suggestions to tell the page "if you reloaded because of a form submit, make this div visible"?

Thanks

Comments

  • acrylian Administrator, Developer
    The easiest would be to customize the form template form.php. Place your div around the form there and add if/else check for the `$_POST['sendmail']` (please look at the plugin code I do not remember correctly right now) to hide/unhide that div by either changing an attached css class for example.
  • So, you did not say which theme you were using. From the distribution, only the Effervescence+ them incorporates the contact form plugin. And it does not place the form in a hidden DIV.

    So I would guess that you are using something else. Anyway, don't put the form in a hidden DIV if you want it to show.

    Normally you would create a separate page for the contact form and link to it from wherever you wish on your other pages.
  • sbillard, you are right I am using a custom theme. I have the contact form placed on my image.php. People click the email button and the contact form becomes visible. It works great with the exception that every time the page needs to refresh (ie for validation, confirmation, etc.) the div hides itself again. Aside from that it is working like it is suppose to, you just need to keep clicking the contact button to complete each step of the form process.

    So far, based off of acrylian's suggestion I've come up with this:

    `
    function postback() {
    if(isset($_POST['sendmail'])) {
    document.getElementById('inquiry').style.visibility = 'visible';
    }
    else {
    if (document.layers) { // Netscape 4
    document.inquiry.visibility = 'visible';
    }
    else { // IE 4
    document.all.inquiry.style.visibility = 'visible';
    }
    }
    }
    `
    But, so far I haven't had any luck. Is PHP not capable of telling a div to become visible if it is returning data from a form? Am I close to solving it with what I've written?
  • acrylian Administrator, Developer
    Well, you mixed JavaScript and PHP code. That will not work this way. You need to use CSS. Create two css classes for the div in your theme's css file, one visible and on invisible. Then use it in a similar way like `if post echo '
    ' else echo '
    ` (this is not valid code!). Or use inline css to style the div.
  • Thanks Acrylian. I don't know if I completely did what you were suggesting, but it is working. The div now stays up through the entire form process. I had to add an or statement for `$_POST['confirm']))` as the confirmation would hide the div again. The "inquiry" id holds all the formating for my div. The "show" and "hide" classes are the visibility states set in my style sheet.

    `
    ><?php printContactForm( ) ?>

    `
    Any idea why there is a lag in receiving the emails and other times they just come right through? I'm guessing it's a hosting issue (using GoDaddy). Or maybe my email provider (Gmail)

    Thanks again for your help!
  • acrylian Administrator, Developer
    Ok, I forgot the "confirm" part, it was out of memory. About the mail recieve issue I don't know, tests on my host worked fine. Maybe you get into a spam queue or something. The mail is sent via Zenphoto's internal mail functions that rely on the phpmail function installed on your server.

    Update: I did a new test on my host and it worked fine.
  • I experienced the lag too but it was the host in my case too. As soon as i switched the host the problem was solved. I used Hostgator
Sign In or Register to comment.