I want the visit to to be able to download a free 10 page article to their computer
The process would be they click on the link and they are taken to a page that asks them for their name and email. Once they click submit the article is downloaded to their computer.
I know how to insert the name and email into the database etc its more how the next stage works.
I suppose another way would be to send download info through email?
if you want to handle the form submission and display of a download link without a page refresh then you can do it with AJAX
but if you want to make sure it will work in javascript disabled browsers then you could
when the submit button is clicked, send name and email address to a form processing script (formProcessor.php)
in formProcessor.php after you have validated, sanitised and inserted the name and email into the database, use php to change the display style of a normally hidden download link to block to make it visible.
set the href of the download link to the file you want to download.
Thanks for getting back to me. I don’t know AJax and I guess I am a little wary about javascript the way you suggested using aphp form script looks the way to go.
but my knoledge around constructing php forms kind of begins and ends at validation, sending info to database, putting up thank you page, sending email to client to confirm and sending an email to me to say someone has but something in the database.
could you explain a litle further how I would change display visisbiliuty and how it all actually ads on to the script. Or if you could point me in the direction of a good tutorial that would be great.
sorry , not sure what you mean by a flag. do i need a function here?
How would it fit into a script like this:
<?php require_once("connect/connection.php");
require_once("includes/functions.php");
if(isset($_POST['submit'])){
$errors = array();
$requiredfields = array('first_name'=> 'Please enter your FIRST NAME','surname'=> 'Please enter your SURNAME','email'=> 'Please enter your E Mail ADDRESS','text'=> 'Please enter your current needs');
foreach($requiredfields as $fieldname => $requiredfieldsmessage){
if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname]) || strlen(trim($_POST[$fieldname])) == 0) {
$errors[] = $requiredfieldsmessage;
}
}
if(count($errors) == 0){
$_POST = array_map('mysqli_prep', $_POST);
$first_name = mysqli_prep($_POST['first_name']);
$surname = mysqli_prep($_POST['surname']);
$email = mysqli_prep($_POST['email']);
$text = mysqli_prep($_POST['text']);
$query = "INSERT INTO form (first_name,surname,email,text)Values('{$first_name}','{$surname}','{$email}','{$text}')";
$result = mysqli_query($connection, $query);
$message="A contact form has been completed on web-writer-articles.co.uk";
$subject="Ghostwriter contact form";
$subject2="Nick Cassells: Ghostwriter and copywriter";
$message2="Thank you for contacting me concerning your copywriting or ghostwriting needs. I will get back to you at this email address as soon as possible.<br> With best regards,<br> Nick Cassells";
$email2=$email;
mail('njc27@sky.com',$subject,$message);
mail($email2, $subject2, $message2);
header('Location: brief_return.php');
exit;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="content">
<div id="mainContent">
<div id="contactform"><?php
if(count($errors) != 0){
echo '<h3>Sorry, please address the following errors:-</h3>';
echo '<ul>';
foreach ($errors as $error) {
echo '<li>' . $error . '</li>';}echo '</ul>';
}
?><h3 class="contacttext">For a <span style="color:red">free</span> pdf guide about your manuscript or a <span style="color:red">free </span>web site review for your web content needs please fill in the contact form below. h3>
<p class="contacttext">Telephone: 01795 843184
<a href="mailto:njc27@sky.com">Email</a>
or fill in the form below and I will get back to you as soon as possible:</p>
<form style="padding:15px;" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
<p>First Name:<br/> <input type="text" size="30" name="first_name" value="<?php echo htmlspecialchars($_POST['first_name'],ENT_QUOTES); ?>" id="fname" /></p>
<p> Surname:<br/><input type="text" size="30" name="surname" value="<?php echo htmlspecialchars($_POST['surname'],ENT_QUOTES); ?>" id="sname" /></p>
<p>E mail:<br/><input type="text" size="40" name="email" value="<?php echo htmlspecialchars($_POST['email'],ENT_QUOTES); ?>" id="email" /></p>
<input type="submit" name="submit" value="Submit " />
</form>
</div>
by a “flag” I mean just a boolean variable whose value is true or false
$isOkToDownload = false; //initialise flag
/*
your code to validate, sanitise and insert the form data into your database.
then when the data has been inserted to the database.
*/
$isOkToDownload = true;
//you might have some more code here to do stuff
//then display the download link
if($isOkToDownload) {
//code to display the link
}