Enter details before downloading
3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 27, 2013 (RSS)
By Toledoh - March 25, 2013
Hi All,
My client has a few files that they add to their site. Is there a way to get people to fill in a form prior to getting access to those files? I don't want to go down the path of the membership plugin, just a simple in-page snippet that pops up when they click a link?
I know it's not very user-friendly, but that's what they want...
Tim (toledoh.com.au)
By gregThomas - March 26, 2013
Hi Tim,
What about using something like this:
<?php
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('C:/wamp/www/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
//Set page variables
$errorsAndAlerts = "";
//If the form has been submitted.
if(@$_REQUEST['formSubmitted']){
//Validate form
if(!@$_REQUEST['name']){ $errorsAndAlerts .= "You must enter you name.<br>"; }
//If there are no errors
if(!$errorsAndAlerts){
//Set a session variable for the user
$_SESSION['accessFiles'] = 'true';
}
}
?>
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php if($errorsAndAlerts): ?>
<div class="errors">
<?php echo $errorsAndAlerts; ?>
</div>
<?php endif; ?>
<form action="scratch.php" method="get">
<!-- hidden input to check form has been submitted -->
<input type="hidden" name="formSubmitted" value="yes" />
<input type="text" name="name" value="<?php echo @$_REQUEST['name']; ?>" />
<input type="submit" name="submit" value="submit" />
</form>
<!-- If the user has the accessFiles session variable set, display the list of files. -->
<?php if(@$_SESSION['accessFiles']): ?>
<div class="fileList" >
<ul>
<li>List</li>
<li>Files</li>
<li>Here</li>
</ul>
</div>
<?php endif; ?>
So if the user has entered their information correctly into the form, you set a session variable for the user. Then you can use that session variable to trigger if the list of files is displayed or not.
The only issue with doing it this way is that the session data will be lost after a few days or if the user deletes their history. So they would have to fill in the form again to access the files.
Let me know if you have any questions.
Thanks
Greg
PHP Programmer - interactivetools.com