Hi All

Im not sure if this is possible but here is the thing

I have thankyou.html page that should be opened in the lightbox when a submit button is clicked and the email is sent, I have a contact.php that send an email to the person with the details filled in an HTML form

the problem is I Cant open the lightbox and send the email at the same if I call the lightbox class in the submit button, that only opens the lightbox and doesnt send the email,

I am a novice in PHP and I need to know if I can link the lightbox with PHP, like calling a lightbox class in an PHP file

another thing I am recieving an error when the below code is executed but the message is sent

if($send) {header( "Location: thankyou.html" );} 
else {print "We encountered an error sending your mail, please notify thandeka@sayovi.org.za"; } } } ?>

and this is the error

Warning: Cannot modify header information - headers already sent by (output started at /home/sayovjcv/public_html/contact.php:1) in /home/sayovjcv/public_html/contact.php on line 36
} ?>

I hope this make sense

Recommended Answers

All 7 Replies

a submit button takes the user to a new page, that is what it is supposed to do.
you could use some javascript to post the data then open the lightbox.
however your best bet is probably to use AJAX

Thanx

But I dont know AJAX either, could you help me with that too please

Thanx

But I dont know AJAX either, could you help me with that too please

There is a good tutorial on AJAX here

I am developme a light box style entry form and also message bob in php script.

pleas help how do this script.

may i know whether the lightbox code is same for both images and anchor tags?

Member Avatar for diafol

Listen, use jquery-flavoured ajax for your lightbox.

Your mail will be sent via normal form?

  1. Send the form to a form handling page as opposed to the same page.
  2. This handling page will validate your data. If all is correct, you send the mail and then check for errors in sending. If all OK return (via header) to a page of your choice - possibly the actual form page. You can send info back to this page via querystring ($_GET) or probably better by session data ($_SESSION). If all is not okay - any errors - head back to the form page with info.
    3A. If all OK in step 2, the page of your choice processes any sent info and opens the lightbox.
    3B. If an error - on form page either lightbox or inline/div error message from info via $_GET or $_SESSION. Also fill mail form with the previous data (best to do this via session).

You can do this thus:

formhandler.php (bits of code)

session_start();
...
//if all validation is clear, do this:
//otherwise a [CODE]$_SESSION['e-msg']['err'][/CODE] with a unique error code will be set
if (mail($to, $sub, $msg)) {
  $_SESSION['e-msg']['err'] = 0; //this means success!
} else {
  $_SESSION['e-msg']['err'] = 8; //this is your error code for 'fail to send'
}
$_SESSION['e-msg']['to'] = $_POST['to'];
$_SESSION['e-msg']['sub'] = $_POST['sub'];
$_SESSION['e-msg']['msg'] = $_POST['msg'];

//return to form page, regardless of success or failure
header("Location:http://www.example.com/form.php");

form.php (bits)

session_start();
...
//check for $_SESSION['e-msg']['err'] - if it exists then there's a problem
if(isset($_SESSION['e-msg']) && $_SESSION['e-msg'] > 0){
  //output variables for error
}else{
  //output variables for success
}
if(isset($_SESSION['e-msg']))unset($_SESSION['e-msg']);//must kill this off

//now fill form fields or hidden tags (for lightbox) from the output variables.

you can activate the lightbox with js in a script tag - decided by php (success or fail). 

<...form code...>
<...lightbox code...>
<?php
if($success){
?>
<script>openSesame('lightbox1');</script>
<?php
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.