I am trying to process a form with ajax, jquery and php and I am getting a 404 error, searched before I posted but I did not find the answer to help me fix my problem, this is the .js file :
$(document).ready(function() {
$('form #error-message').hide();
$('#submit').on('click' , function(e) {
e.preventDefault();
var valid = '';
var required = " is required";
var fname = $('form #fname').val();
var lname = $('form #fname').val();
var dbirth = $('form #dbirth').val();
var adress1 = $('form #adress1').val();
if (fname = '' || fname.lenght <= 2) {
valid += '<p><span>X</span> Full Name ' + required + '</p>';
}
if (lname = '' || lname.lenght <= 2) {
valid += '<p><span>X</span> Full Name ' + required + '</p>';
}
if (dbirth = '' || dbirth.lenght <= 2) {
valid += '<p><span>X</span> Full Name ' + required + '</p>';
}
if (adress1 = '' || adress1.lenght <= 5) {
valid += '<p><span>X</span> Full Name ' + required + '</p>';
}
if(valid != '') {
$('form #error-message').removeClass().addClass('warning')
.html('<h1>Please complete all the fields</h1>' + valid);
} else {
var contactData = $( 'form' ).serialize();
console.log(contactData);
$.ajax({
type: 'POST',
url: 'ajaxform/process.php',
data: contactData,
success: function() {
$('#error-message').removeClass().addClass('success')
.html("<h1>Thank you for contacting me. I will reply as soon as i can!</h1>");
},
error: function() {
$('#error-message').removeClass().addClass('alert-error')
.html("An error has occured. Please try again later")
},
complete: function() {
$('form')[0].reset();
}
});
}
});
});
and this is the .php file :
<?php
sleep(1);
$to = 'yourcompany#gmail.com';
$subject = 'My form contact';
if( isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['dbirth']) && isset($_POST['adress1'])) {
$fname = trim($_POST['fname']);
$lname = trim($_POST['lname']);
$sdate = trim($_POST['dbirth']);
$adress1 = trim($_POST['adress1']);
if(!empty($fname) && !empty($lname) && !empty($dbirth) && !empty($adress1)) {
$full_name = $fname . " " . $lname;
$body = $full_name . "\n" . $adress1;
$headers = "From {$full_name} " . $dbirth;
mail($to, $subject, $body, $headers);
}
} else {
header('location: ../index.html');
}
?>
I suggest you phpmailer. You can download it at this link.
<?php
require_once('class.phpmailer.php');
sleep(1);
$to = 'yourcompany#gmail.com';
$subject = 'My form contact';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1; // will send erros and messages
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; //Gmail smtp port
$mail->Username = "youremail#gmail.com";
$mail->Password = "yourpassword";
$mail->SetFrom($headers);
$mail->Subject = $subject;
if( isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['dbirth']) && isset($_POST['adress1'])) {
$fname = trim($_POST['fname']);
$lname = trim($_POST['lname']);
$sdate = trim($_POST['dbirth']);
$adress1 = trim($_POST['adress1']);
if(!empty($fname) && !empty($lname) && !empty($dbirth) && !empty($adress1)) {
$full_name = $fname . " " . $lname;
$body = $full_name . "\n" . $adress1;
$headers = "From {$full_name} " . $dbirth;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
header('location: ../index.html');
}
}
}
?>
Related
I installed a php gallery and configured it and I finally could make it to run inside an iframe.But now when I click at an image, I want it to open that image pop-up view outside the iframe.imgGallery
<?php
if (isset($this->vars['file_list']))
{
$thumb_code['file'] = $this->getThumbCode("file");
foreach ($this->vars['file_list'] as $file)
{
$output = '';
$img_url = $this->genThumbURL($request, $file);
if ($this->settings['use_popup_image_viewer'] == true) {
$url = "?image=" . $request . $file['file'];
if ($this->settings['show_thumbs_under_viewer'] == true) {
$fancy_class = "fancybox-thumbs";
$fancy_attr = "data-fancybox-group=\"thumb\"";
} else {
$fancy_class = "fancybox";
$fancy_attr = "data-fancybox-group=\"gallery\"";
}
} else {
$url = '?view=' . $request . $file['file'];
$fancy_class = "";
$fancy_attr = "";
}
//<<URL>> = $url = ?view=folder/image.jpg
//<<FANCY_CLASS>> = $fancy_class = fancybox-thumbs (If left out fancybox will not work. Use inside class attribute on A tag)
//<<FANCY_ATTR>> = $fancy_attr = data-fancybox-group="gallery" (If left out fancybox will not work. Use on A tag)
//<<TITLE>> = $file['file'] = image.jpg
//<<THUMB_WIDTH>> = $this->settings['thumb_size_' . $this->vars['thumb_size']] = 125 (autodetect thumb size also)
//<<THUMB_HEIGHT>> = $this->settings['thumb_size_' . $this->vars['thumb_size']] = 125 (autodetect thumb size also)
//<<THUMB_LOCATION>> = $this->escapeString($img_url) = phppi/cache/folder/image_small.jpg (may also set to phppi/themes/gallery/themename/images/no_images.png if no image)
//<<THEME_LOCATION>> = $this->showThemeURL(1) = phppi/themes/gallery/themename
$replace_codes = array("<<URL>>",
"<<FANCY_CLASS>>",
"<<FANCY_ATTR>>",
"<<TITLE>>",
"<<THUMB_WIDTH>>",
"<<THUMB_HEIGHT>>",
"<<THUMB_LOCATION>>",
"<<THEME_LOCATION>>"
);
$replace_values = array($url,
$fancy_class,
$fancy_attr,
$file['file'],
$this->settings['thumb_size_' . $this->vars['thumb_size']],
$this->settings['thumb_size_' . $this->vars['thumb_size']],
$this->escapeString($img_url),
$this->showThemeURL(1)
);
echo str_replace($replace_codes, $replace_values, $thumb_code['file']);
}
}
echo "<div style=\"clear: both;\"></div>\n";
}
function showPrevFolderURL($format = 0)
{
//0 = Output url
//1 = Return url as string
if ($format == 0)
{
echo '?' . $this->vars['dir']['req']['parent'];
} else if ($format == 1) {
return '?' . $this->vars['dir']['req']['parent'];
}
}
function showPrevImageURL($format = 0)
{
//0 = Output url
//1 = Return url as string
if ($format == 0)
{
if ($this->settings['use_javascript_navigation'] == true)
{
echo 'javascript: phppi.go_prev_image();';
} else {
if (isset($this->vars['file_list'][$this->vars['previous_image_id']]['full_path']))
{
echo '?view=' . $this->vars['file_list'][$this->vars['previous_image_id']]['full_path'];
} else {
echo '';
}
}
} else if ($format == 1) {
if ($this->settings['use_javascript_navigation'] == true)
{
return 'javascript: phppi.go_prev_image();';
} else {
if (isset($this->vars['file_list'][$this->vars['previous_image_id']]['full_path']))
{
return '?view=' . $this->vars['file_list'][$this->vars['previous_image_id']]['full_path'];
} else {
return '';
}
}
}
}
function showNextImageURL($format = 0)
{
//0 = Output url
//1 = Return url as string
if ($format == 0)
{
if ($this->settings['use_javascript_navigation'] == true)
{
echo 'javascript: phppi.go_next_image();';
} else {
if (isset($this->vars['file_list'][$this->vars['next_image_id']]['full_path']))
{
echo '?view=' . $this->vars['file_list'][$this->vars['next_image_id']]['full_path'];
} else {
echo '';
}
}
} else if ($format == 1) {
if ($this->settings['use_javascript_navigation'] == true)
{
return 'javascript: phppi.go_next_image();';
} else {
if (isset($this->vars['file_list'][$this->vars['next_image_id']]['full_path']))
{
return '?view=' . $this->vars['file_list'][$this->vars['next_image_id']]['full_path'];
} else {
return '';
}
}
}
}
function showUpFolderURL($format = 0)
{
//0 = Output url
//1 = Return url as string
if ($format == 0)
{
echo '?' . $this->pathInfo($_GET['view'], 'dir_path');
} else if ($format == 1) {
return '?' . $this->pathInfo($_GET['view'], 'dir_path');
}
}
function showThemeURL($format = 0)
{
//0 = Output url
//1 = Return url as string
if ($format == 0)
{
echo 'phppi/themes/gallery/' . $this->settings['theme'] . '/' . $this->vars['theme_mode'] . '/';
} else if ($format == 1) {
return 'phppi/themes/gallery/' . $this->settings['theme'] . '/' . $this->vars['theme_mode'] . '/';
}
}
function showTitle($format = 0)
{
//0 = Output url
//1 = Return url as string
if ($format == 0)
{
echo $this->vars['page_title'];
} else if ($format == 1) {
return $this->vars['page_title'];
}
}
function showSiteName($format = 0)
{
//0 = Output name
//1 = Return name as string
if ($format == 0)
{
echo $this->settings['site_name'];
} else if ($format == 1) {
return $this->settings['site_name'];
}
}
function showLogo($format = 0)
{
//0 = Output img tag
//1 = Return img tag as string
if ($format == 0)
{
echo "<img id=\"page-logo\" src=\"" . $this->settings['page_title_logo'] . "\" alt=\"" . $this->settings['site_name'] . "\">";
} else if ($format == 1) {
return "<img id=\"page-logo\" src=\"" . $this->settings['page_title_logo'] . "\" alt=\"" . $this->settings['site_name'] . "\">";
}
}
function showNav($format = 0, $home = "", $prev = "", $sep = "", $mode = "")
{
//Mode:
//classic = Only show title and previous button
//new = Breadcrumb style, may take up most of the page if using a large folder tree
//auto = Depending on theme it may switch between the two depending on the screen size
//left empty = Set based on user settings
//$home = HTML to insert for home button
//$prev = HTML to insert for prev button
//$sep = HTML to insert for seperator
$output = "";
if ($mode == "") {
$mode = $this->settings['nav_menu_style'];
}
if ($mode == "auto" || $mode == "new") {
$new_output = "<ul><li class=\"nav-home\">" . $home . "</li>";
$url = "?";
if ($this->vars['dir']['req']['full'] !== "") {
$new_output .= "<li class=\"nav-sep\">" . $sep . "</li>";
$i = 1;
foreach ($this->vars['dir']['req']['split'] as $value) {
if ($i < (count($this->vars['dir']['req']['split']))) {
$url .= $value . "/";
$new_output .= "<li>" . $value . "</li>";
$new_output .= "<li class=\"nav-sep\">" . $sep . "</li>";
} else {
$new_output .= "<li class=\"nav-curr\"><div class=\"title\">" . $value . "</div></li>";
}
$i++;
}
}
$new_output .= "</ul>";
}
if ($mode == "auto" || $mode == "classic")
{
$url = "?";
if ($this->vars['dir']['req']['parent'] !== "") {
$i = 1;
foreach ($this->vars['dir']['req']['split'] as $value) {
if ($i < (count($this->vars['dir']['req']['split']))) {
$url .= $value . "/";
}
$i++;
}
$url = substr($url, 0, -1);
}
$classic_output = "<ul><li class=\"nav-prev\">" . $prev . "</li>";
if ($this->vars['dir']['req']['curr'] !== "") {
$classic_output .= "<li class=\"nav-sep\">" . $sep . "</li>";
$classic_output .= "<li class=\"nav-curr\"><div class=\"title\">" . $this->vars['dir']['req']['curr'] . "</div></li>";
}
$classic_output .= "</ul>";
}
if ($mode == "auto") {
$output .= "<div class=\"nav-menu-new\">" . $new_output . "</div>";
$output .= "<div class=\"nav-menu-classic\">" . $classic_output . "</div>";
} else if ($mode == "new") {
$output = $new_output;
} else if ($mode == "classic") {
$output = $classic_output;
}
//0 = Output nav
//1 = Return nav as string
if ($format == 0)
{
echo $output;
} else if ($format == 1) {
return $output;
}
}
function showPage()
{
require($this->showThemeURL(1) . 'pages/' . $this->vars['page_requested'] . '.php');
}
function resizedSize($width, $height, $return = 2)
{
//Returns width, height or an array of width and height for the thumbnail size of a full sized image
if ($width > $height)
{
$new_height = $this->settings['thumb_size_' . $this->vars['thumb_size']];
$new_width = $width * ($this->settings['thumb_size_' . $this->vars['thumb_size']] / $height);
} else if ($width < $height) {
$new_height = $height * ($this->settings['thumb_size_' . $this->vars['thumb_size']] / $width);
$new_width = $this->settings['thumb_size_' . $this->vars['thumb_size']];
} else if ($width == $height) {
$new_width = $this->settings['thumb_size_' . $this->vars['thumb_size']];
$new_height = $this->settings['thumb_size_' . $this->vars['thumb_size']];
}
if ($return == 0)
{
//Return width
return floor($new_width);
} else if ($return == 1) {
//Return height
return floor($new_height);
} else if ($return == 2) {
//Return array with width and height
return array(floor($new_width), floor($new_height));
}
}
function insertHeadInfo()
{
echo "
<!--
PHP Picture Index " . $this->vars['version'] . "
Created by: Brendan Ryan (http://www.pixelizm.com/)
Site: http://phppi.pixelizm.com/
Licence: GNU General Public License v3
http://www.gnu.org/licenses/
-->\n\n";
echo "<meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; user-scalable = no; maximum-scale=1.0;\">\n";
if (isset($_GET['view']) && !isset($this->vars['error'])) {
echo "<script type=\"text/javascript\" src=\"phppi/scripts/jquery/jquery.js\"></script>";
} elseif ($this->settings['use_popup_image_viewer'] == true) {
echo "<script type=\"text/javascript\" src=\"phppi/scripts/jquery/jquery.js\"></script>\n";
}
if (isset($_GET['view']) && !isset($this->vars['error']))
{
if ($this->settings['page_title_show_full_path'] == true) { $temp_title_full_path = '1'; } else { $temp_title_full_path = '0'; }
if ($this->settings['enable_hotkeys']) { $enable_hotkeys = 1; } else { $enable_hotkeys = 0; }
if ($this->settings['enable_up_hotkey']) { $enable_up_hotkey = 1; } else { $enable_up_hotkey = 0; }
echo "
<script type=\"text/javascript\" src=\"phppi/scripts/phppi_js.js\"></script>
<script type=\"text/javascript\">
$(document).ready(function() { phppi.initialize(); });
phppi.image_width = " . $this->vars['file_list'][$this->vars['current_image_id']]['data'][0] . ";
phppi.image_height = " . $this->vars['file_list'][$this->vars['current_image_id']]['data'][1] . ";
phppi.up_folder = '" . $this->escapeString($this->showUpFolderURL(1)) . "';
phppi.prev_image = '" . $this->escapeString($this->showPrevImageURL(1)) . "';
phppi.next_image = '" . $this->escapeString($this->showNextImageURL(1)) . "';
phppi.title_full_path = " . $temp_title_full_path . ";
phppi.enable_hotkeys = " . $enable_hotkeys . ";
phppi.enable_up_hotkey = " . $enable_up_hotkey . ";";
if ($this->settings['use_javascript_navigation'] == true)
{
$file_list = "";
$x = 0;
$dir = $this->pathInfo($_GET['view'], 'dir_path');
foreach($this->vars['file_list'] as $file) {
$file_list .= "['" . $this->escapeString($dir) . "/" . $this->escapeString($file['file']) . "', '" . $this->escapeString($file['file']) . "', " . $file['data'][0] . ", " . $file['data'][1] . "]";
if ($x < (count($this->vars['file_list']) - 1)) { $file_list .= ","; }
$x++;
}
echo "
phppi.site_name = '" . $this->settings['site_name'] . "';
phppi.page_title = '" . $this->vars['page_title'] . "';
phppi.current_file = " . $this->vars['current_image_id'] . ";
phppi.files = [" . $file_list . "];";
}
echo "</script>\n";
}
if ($this->settings['use_popup_image_viewer'] == true)
{
echo "<script type=\"text/javascript\" src=\"phppi/scripts/fancybox/jquery.fancybox.js\"></script>\n";
if ($this->settings['show_thumbs_under_viewer'] == true) { echo "<script type=\"text/javascript\" src=\"phppi/scripts/fancybox/jquery.fancybox-thumbs.js\"></script>\n"; }
if ($this->settings['enable_mousewheel'] == true) { echo "<script type=\"text/javascript\" src=\"phppi/scripts/fancybox/jquery.mousewheel-3.0.6.pack.js\"></script>\n"; }
if ($this->settings['show_thumbs_under_viewer'] == true) {
//Thumb Helper Version
echo "<script type=\"text/javascript\">
$(document).ready(function() {
$('.fancybox-thumbs').fancybox({
openEffect: '" . $this->settings['open_image_animation'] . "',
closeEffect: '" . $this->settings['close_image_animation'] . "',
prevEffect: '" . $this->settings['nextprev_image_animation'] . "',
nextEffect: '" . $this->settings['nextprev_image_animation'] . "',
closeBtn: false,
arrows: false,
nextClick: true,
helpers: {
thumbs: {
width: " . $this->settings['popup_thumb_size'] . ",
height: " . $this->settings['popup_thumb_size'] . "
}
}
});
});
</script>\n";
} else {
//Normal Version
echo "<script type=\"text/javascript\">
$(document).ready(function() {
$('.fancybox').fancybox({
openEffect: '" . $this->settings['open_image_animation'] . "',
closeEffect: '" . $this->settings['close_image_animation'] . "',
prevEffect: '" . $this->settings['nextprev_image_animation'] . "',
nextEffect: '" . $this->settings['nextprev_image_animation'] . "'
});
});
</script>\n";
}
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"phppi/scripts/fancybox/jquery.fancybox.css\">\n";
if ($this->settings['show_thumbs_under_viewer'] == true) { echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"phppi/scripts/fancybox/jquery.fancybox-thumbs.css\">\n"; }
}
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"phppi/css/global.css\">\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"phppi/themes/thumbnail/" . $this->settings['thumbnail_theme'] . "/style.css\">\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $this->showThemeURL(1) . "style.css\">\n";
}
function initialize()
{
//Debug Mode
if ($this->settings['debug_mode'] == true)
{
error_reporting(E_ALL);
ini_set('display_errors', '1');
}
ini_set('memory_limit', $this->settings['php_memory'] . 'M');
//Set Thumb Size if changed
if (isset($_POST['thumb_size'])) {
if ($_POST['thumb_size'] == 0) {
$this->setThumbSize('small');
} else if ($_POST['thumb_size'] == 1) {
$this->setThumbSize('medium');
} else if ($_POST['thumb_size'] == 2) {
$this->setThumbSize('large');
}
} else {
$this->setThumbSize(NULL);
}
//GZIP Compression
ini_set('zlib.output_compression', $this->settings['use_gzip_compression']);
ini_set('zlib.output_compression_level', $this->settings['gzip_compression_level']);
//Theme Mode
$this->setThemeMode();
if ($this->settings['allow_mobile_theme'] == true)
{
if (!is_file('phppi/themes/gallery/' . $this->settings['theme'] . '/' . $this->vars['theme_mode'] . '/template.php'))
{
$this->vars['theme_mode'] = 'standard';
}
} else {
$this->vars['theme_mode'] = 'standard';
}
//Load Variables
$this->loadVars();
//Load Blacklists/Whitelists
$this->loadLists();
//Display Content
if (isset($_GET['thumb']))
{
//Show thumbnail only
$this->genThumbnail($_GET['thumb']);
exit;
} else if (isset($_GET['image'])) {
//Show image
if ($this->checkExploit('/' . $_GET['image']) == true) {
$file_ext = strtolower($this->pathInfo($_GET['image'], 'file_ext'));
if ($file_ext == 'jpg' or $file_ext == 'jpeg')
{
$format = 'jpeg';
} else if ($file_ext == 'png') {
$format = 'png';
} else if ($file_ext == 'gif') {
$format = 'gif';
}
header("Content-length: " . filesize($this->vars['dir']['gallery'] . '/' . $_GET['image']));
header("Content-type: image/" . $format);
readfile($this->vars['dir']['gallery'] . '/' . $_GET['image']);
} else {
echo "File doesn't exist.";
}
exit;
} else if (isset($_GET['view'])) {
//Show full image view
$req_path = $this->pathInfo($_GET['view'], 'dir_path');
if ($req_path !== "") { $req_path = "/" . $req_path; }
if ($this->checkExploit($req_path) == true) {
if (!$this->getDir($req_path . '/'))
{
$this->vars['error'] = 'Folder doesn\'t exist';
$this->vars['page_title'] = 'Error';
$this->vars['page_requested'] = 'error';
$this->logs("access", "add", "Folder not found (/" . $_GET['view'] . ")");
} else if (!is_file($this->vars['dir']['gallery'] . '/' . $_GET['view'])) {
$this->vars['error'] = 'File doesn\'t exist';
$this->vars['page_title'] = 'Error';
$this->vars['page_requested'] = 'error';
$this->logs("access", "add", "File not found (/" . $_GET['view'] . ")");
} else {
for($i = 0; $i < count($this->vars['file_list']); $i++)
{
if ($this->vars['file_list'][$i]['file'] == $this->pathInfo($_GET['view'], 'full_file_name'))
{
$this->vars['current_image_id'] = $i;
$this->vars['previous_image_id'] = NULL;
$this->vars['next_image_id'] = NULL;
if ($i > 0)
{
$this->vars['previous_image_id'] = $i - 1;
}
if ($i < (count($this->vars['file_list']) - 1))
{
$this->vars['next_image_id'] = $i + 1;
}
break;
}
}
if ($this->settings['page_title_show_full_path'] == true) {
$this->vars['page_title'] = $this->settings['site_name'] . " - " . str_replace("/", " \ ", $_GET['view']);
} else {
$this->vars['page_title'] = $this->settings['site_name'] . " - " . $this->pathInfo($_GET['view'], 'full_file_name');
}
$this->vars['page_requested'] = 'image';
$this->logs("access", "add", "Viewed image (/" . $_GET['view'] . ")");
}
} else {
$this->vars['error'] = 'File doesn\'t exist';
$this->vars['page_title'] = 'Error';
$this->vars['page_requested'] = 'error';
$this->logs("access", "add", "Possible exploit attempt, blocked access (/" . $_GET['view'] . ")");
}
require('phppi/themes/gallery/' . $this->settings['theme'] . '/' . $this->vars['theme_mode'] . '/template.php');
if ($this->settings['debug_show_vars'] == true) { $this->outputVarsArray(); }
if ($this->settings['debug_show_settings'] == true) { $this->outputSettingsArray(); }
} else {
//Show folder view
if ($this->vars['dir']['req']['full'] == '')
{
$dir_req = "";
} else {
$dir_req = $this->vars['dir']['req']['full'] . '/';
}
if ($this->vars['dir']['req']['full'] == '' || $this->checkExploit('/' . $this->vars['dir']['req']['full']) == true) {
if (!$this->getDir($dir_req))
{
$this->vars['error'] = 'Folder doesn\'t exist';
$this->vars['page_title'] = 'Error';
$this->vars['page_requested'] = 'error';
$this->logs("access", "add", "Folder not found (/" . $dir_req . ")");
} else {
if ($this->settings['page_title_show_full_path'] == true) {
if ($this->vars['dir']['req']['full'] == "") { $sep = ""; } else { $sep = " - "; }
$this->vars['page_title'] = $this->settings['site_name'] . $sep . str_replace("/", " \ ", $this->vars['dir']['req']['full']);
} else {
if ($this->vars['dir']['req']['full'] == "") { $sep = ""; } else { $sep = " - "; }
$this->vars['page_title'] = $this->settings['site_name'] . $sep . $this->vars['dir']['req']['curr'];
}
$this->vars['page_requested'] = 'folder';
$this->logs("access", "add", "Viewed folder (/" . $dir_req . ")");
}
} else {
$this->vars['error'] = 'Folder doesn\'t exist';
$this->vars['page_title'] = 'Error';
$this->vars['page_requested'] = 'error';
$this->logs("access", "add", "Folder not found or exploit attempt, blocked access (/" . $dir_req . ")");
}
require('phppi/themes/gallery/' . $this->settings['theme'] . '/' . $this->vars['theme_mode'] . '/template.php');
if ($this->settings['debug_show_vars'] == true) { $this->outputVarsArray(); }
if ($this->settings['debug_show_settings'] == true) { $this->outputSettingsArray(); }
}
}
}
?>
How to add or turn this jQuery or Javascript code into php to modify this fancybox to open images outside of the iframe?
<script>
/* <![CDATA[ */
$(document).ready(function() {
$('.imagen').click(function(e){
e.preventDefault();
parent.$.fancybox([
{href:'img/sample-9.jpg', title: '01'},
{href:'img/sample-9.jpg', title: '02'},
{href:'img/sample-9.jpg', title: '03'}
],{
// href: this.href,
helpers: {
overlay: {
opacity: 0.3
} // overlay
//, buttons: {}
} // helpers
}); // fancybox
}); // click
//or in this way using another way or option
$('.image').click(function(e){
e.preventDefault();
parent.$.fancybox({
href: this.href,
width: 560,
height: 315,
type: 'iframe',
helpers: {
overlay: {
opacity: 0.3
} // overlay
} // helpers
}); // fancybox
}); // click
beforeClose: function() {
$(".fancybox-inner").unwrap();
},
helpers: {
overlay: {
opacity: 0.3
} // overlay
}
}); //fancybox
return false;
}); //click
}); // ready
/* ]]> */
</script>
This problem is similar to this example:Example Demo
I am in the iframed page 01 situation and I want to do something similar to
iframed page 02.
Your page inside <iframe> is limited to the shape of iframe. Period.
First what comes to my mind is this. In order to display something bigger than iframe you would have to have some script outside your iframe, and then have some communication between iframe contents and page with iframe (most likely with postMessage).
Other idea would be going with your gallery full screen with FullscreenAPI, and then you would have all screen to yourself. In case of gallery that could lead to some nice effect. Just remember, to be able to do that, <iframe> that displays your gallery has to has attribute allowfullscreen (no value needed).
In both cases you will need to be able to either add additional JavaScript outside iframe, or control how iframe is added to page. This is security measure so the contents of iframe will not abduct the parent page.
I am working on a admin panel which is going to add data on a SQLite DB using AngularJS and PHP and then show it in HTML. All good with data as arrays text date etc. The problem that I have is to upload an Image in a specified folder and store the path in my DB.
This is my PHP which store data in DB
<?php
try {
if (
empty($_POST['item']) ||
empty($_POST['description']) ||
empty($_POST['release']) ||
empty($_POST['demo']) ||
empty($_POST['type']) ||
empty($_POST['live']) ||
empty($_POST['client'])
) {
throw new PDOException("Invalid Request");
}
$item = $_POST['item'];
$description = $_POST['description'];
$release = $_POST['release'];
$demo = $_POST['demo'];
$type = $_POST['type'];
$live = $_POST['live'];
$client = $_POST['client'];
$objDb = new PDO('sqlite:../database/database');
$objDb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO 'items'
('id', 'item', 'description', 'release', 'demo', 'type', 'live', 'client')
VALUES (null, ?, ?, ?, ?, ?, ?, ?)";
$statement = $objDb->prepare($sql);
if (!$statement->execute(array($item, $description, $release, $demo, $type, $live, $client))) {
throw new PDOException("The execute method failed");
}
And this is my PHP which upload Images in a specified folder
<?php
if (isset($_POST['submit'])) {
$validextensions = array("jpeg", "jpg", "png");
$temporary = explode(".", $_FILES["file"]["name"]);
$file_extension = end($temporary);
if ((($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg")
) && ($_FILES["file"]["size"] < 1000000)
&& in_array($file_extension, $validextensions)) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br/><br/>";
} else {
echo "<span>Your File Uploaded Succesfully...!!</span><br/>";
echo "<br/><b>File Name:</b> " . $_FILES["file"]["name"] . "<br>";
echo "<b>Type:</b> " . $_FILES["file"]["type"] . "<br>";
echo "<b>Size:</b> " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "<b>Temp file:</b> " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " <b>already exists.</b> ";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
echo "<b>Stored in:</b> " . "upload/" . $_FILES["file"]["name"];
}
}
} else {
echo "<span>***Invalid file Size or Type***<span>";
}
}
?>
And this is my insert function from angular
$scope.insert = function() {
if ($scope.goodToGo()) {
var thisData = "item=" + $scope.item;
thisData += "&description=" + $scope.description;
thisData += "&release=" + $scope.release;
thisData += "&demo=" + $scope.demo;
thisData += "&client=" + $scope.client;
thisData += "&type=" + $scope.type;
thisData += "&live=" + $scope.live;
thisData += "&image=" + $scope.image;
$http({
method : 'POST',
url : urlInsert,
data : thisData,
headers : {'Content-Type' : 'application/x-www-form-urlencoded'}
})
.success(function(data){
if(_recordAddedSuccessfully(data)){
$scope.items.push({
id : data.item.id,
item : data.item.item,
description : data.item.description,
release : data.item.release,
demo : data.item.demo,
client : data.item.client,
client_name : data.item.client_name,
type : data.item.type,
type_name : data.item.type_name,
live : data.item.live,
live_name : data.item.live_name,
image : data.item.image,
done : data.item.done
});
$scope.clear();
}
})
.error(function(data, status, headers, config){
throw new Error('Something went wrong with inserting');
});
}
};
Have anyone any idea how to do this?
If you are uploading image then content type should be set to multipart/form-data i.e
headers : {'Content-Type' : 'multipart/form-data'}
rest looks fine.
I need the errors on a form to show up from the submit.php onto the form page at contact.php
I have tried with Session_Start, but it is not working. This is what I have so far.
Contact.php
<?php
ob_start();
session_start();
if ($_SESSION["error"] != "") {
echo $_SESSION["error"];
$_SESSION["error"] = "";
}
?>
<?php echo $error; ?>
Submit.php
<?php
ob_start();
session_start();
?>
<?php
//fields
$link_address = 'contact'; // page to redirect to
$honeypot = '';
$error = '';
$name = 'Name';
$email = 'Email';
$comments = 'Message';
if(isset($_POST['contactus'])) {
$honeypot = $_POST['email_confirm'];
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
// honeypot
if($honeypot)
exit(1);
<?php
//error messages
if(trim($name) == 'Name') {
$error = '<div class="error_message">Need your Name</div>';
} else if(trim($name) == '') {
$error = '<div class="error_message">Need your Name</div>';
} else if(trim($email) == 'Email') {
$error = '<div class="error_message">Need your Email</div>';
} else if(trim($email) == '') {
$error = '<div class="error_message">Need your Email</div>';
} else if(!isEmail($email)) {
$error = '<div class="error_message">Need a valid email</div>';
} else if(trim($comments) == 'Message') {
$error = '<div class="error_message">A Message is required</div>';
} else if(trim($comments) == '') {
$error = '<div class="error_message">A Message is required</div>';
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
//email address
$address = "mail#example.com";
//email message
$e_subject = 'Web Message from: ' . $name . '.';
$e_body = "From: $name\nEmail: $email \r\n\nMessage:\n$comments\n\n\n";
$msg = $e_body . $e_content . $e_reply;
if(mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n"))
{
//success html page response
echo "<div id='succsess_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you. The following was sent to us. <br/><br/>$name<br/><br/>$email<br/><br/>$comments</p>";
echo "<a href='$link_address'>CLOSE THIS MESSAGE</a>";
echo "</div>";
} else echo "Error. Mail not sent";
}
}
if(!isset($_POST['contactus']) || $error != '') // Do not edit.
{
?>
<?php }
function isEmail($email) { // Email address verification, do not edit.
return(preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,12})$/",$email));
}
?>
As you can see, the $error from the inputs required should show up when the user does not enter in their $name, etc on the contact.php page where it says:
<?php echo $error; ?>
How can I have the $error(s) from the submit.php code show up on the contact.php page if a user does not fill in the required input fields?
Try this as your Submit.php added $_SESSION['error'] = $error; //if $error is not empty. Also removed extra php tag
<?php
ob_start();
session_start();
//fields
$link_address = 'contact'; // page to redirect to
$honeypot = '';
$error = '';
$name = 'Name';
$email = 'Email';
$comments = 'Message';
if(isset($_POST['contactus'])) {
$honeypot = $_POST['email_confirm'];
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
// honeypot
if($honeypot)
exit(1);
//error messages
if(trim($name) == 'Name') {
$error = '<div class="error_message">Need your Name</div>';
} else if(trim($name) == '') {
$error = '<div class="error_message">Need your Name</div>';
} else if(trim($email) == 'Email') {
$error = '<div class="error_message">Need your Email</div>';
} else if(trim($email) == '') {
$error = '<div class="error_message">Need your Email</div>';
} else if(!isEmail($email)) {
$error = '<div class="error_message">Need a valid email</div>';
} else if(trim($comments) == 'Message') {
$error = '<div class="error_message">A Message is required</div>';
} else if(trim($comments) == '') {
$error = '<div class="error_message">A Message is required</div>';
}
if (isset($error) && !empty($error)){
$_SESSION['error'] = $error; //SET errors for contact.php page to display
echo $error;
}else {
$_SESSION['error'] = '';
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
//email address
$address = "mail#example.com";
//email message
$e_subject = 'Web Message from: ' . $name . '.';
$e_body = "From: $name\nEmail: $email \r\n\nMessage:\n$comments\n\n\n";
$msg = $e_body . $e_content . $e_reply;
if(mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n"))
{
//success html page response
echo "<div id='succsess_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you. The following was sent to us. <br/><br/>$name<br/><br/>$email<br/><br/>$comments</p>";
echo "<a href='$link_address'>CLOSE THIS MESSAGE</a>";
echo "</div>";
} else echo "Error. Mail not sent";
}
}
if(!isset($_POST['contactus']) || $error != '') // Do not edit.
{
?>
<?php
}
function isEmail($email) { // Email address verification, do not edit.
return(preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,12})$/",$email));
}
?>
I do not understand why this ajax request is returning an error even though the error status is OK (200), any thoughts? It seems like I am missing something very obvious but I have been tearing myself apart trying to find an answer! I am new to ajax and therefore have little experience with it! Thanks for the help.
This is my ajax request:
var dataString = $('#cform').serialize();
$.ajax({
type: "POST",
url: 'contact.php',
data: dataString,
dataType: 'json',
success: function (data) {
if (data.success == 0) {
var errors = '<ul><li>';
if (data.name_msg != '')
errors += data.name_msg + '</li>';
if (data.email_msg != '')
errors += '<li>' + data.email_msg + '</li>';
if (data.godaddyemail_msg != '')
errors += '<li>' + data.godaddyemail_msg + '</li>';
if (data.godaddyuser_msg != '')
errors += '<li>' + data.godaddyuser_msg + '</li>';
$("div#output").removeClass('alert-success').addClass('alert-error').show().html('<button type="button" class="close" data-dismiss="alert">x</button><p> Could not complete your request. See the errors below!' + errors + '</p>');
}
else if (data.success == 1) {
$("div#output").removeClass('alert-error').addClass('alert-success').show().html('<button type="button" class="close" data-dismiss="alert">x</button><p>You message has been sent successfully!</p>');
}
},
error: function (error) {
$("div#output").removeClass('alert-success').addClass('alert-error').show().html('<button type="button" class="close" data-dismiss="alert">x</button><p> Could not complete your request. The Function returned an error!</p>' + error.statusText); }
});
return false;
}
This is contact.php (where the request is sent to):
<?php
$send_email_to = "My Email";
$message = 'message';
$subject = 'subject';
function send_email($name,$email,$godaddyusername,$godaddyemail)
{
global $send_email_to;
if($message=='message')$message='';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$email. "\r\n";
$message = "<strong>Email = </strong>".$email."<br>";
$message .= "<strong>Name = </strong>".$name."<br>";
$message .= "<strong>GoDaddy Username = </strong>".$godaddyusername."<br>";
$message .= "<strong>GoDaddy Email = </strong>".$godaddyemail."<br>";
mail($send_email_to, $subject, $message,$headers);
return true;
}
function validate($name,$email,$godaddyusername,$godaddyemail)
{
$return_array = array();
$return_array['success'] = '1';
$return_array['name_msg'] = '';
$return_array['email_msg'] = '';
$return_array['godaddyuser_msg'] = '';
$return_array['godaddyemail_msg'] = '';
if($email == '')
{
$return_array['success'] = '0';
$return_array['email_msg'] = 'Email is required';
}
else
{
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$return_array['success'] = '0';
$return_array['email_msg'] = 'Enter valid emmail.';
}
}
if($name == '')
{
$return_array['success'] = '0';
$return_array['name_msg'] = 'Name is required';
}
else
{
$string_exp = "/^[A-Za-z .'-]+$/";
if (!preg_match($string_exp, $name)) {
$return_array['success'] = '0';
$return_array['name_msg'] = 'Enter valid Name.';
}
}
if($godaddyusername == '')
{
$return_array['success'] = '0';
$return_array['godaddyuser_msg'] = 'GoDaddy Username is required';
}
if($godaddyemail == '')
{
$return_array['success'] = '0';
$return_array['godaddyemail_msg'] = 'GoDaddy Email is required';
}
else
{
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$godaddyemail)) {
$return_array['success'] = '0';
$return_array['godaddyemail_msg'] = 'Enter a valid GoDaddy email.';
}
}
return $return_array;
}
$name = $_POST['name'];
$email = $_POST['email'];
$godaddyemail = $_POST['gde'];
$godaddyusername = $_POST['gdu'];
$return_array = validate($name,$email,$godaddyusername,$godaddyemail);
if($return_array['success'] == '1')
{
send_email($name,$email,$godaddyusername,$godaddyemail);
}
header('Content-type: text/json');
echo json_encode($return_array);
die();
?>
That is because you have two undefined variables on your send_email() function.
Here you have this if statement..
if($message=='message')$message=''; // $message is not available inside this function.
and here
mail($send_email_to, $subject, $message,$headers); //$subject is also undefined.
I have a simple contact form that uses js to post via php, and read the response to do some simple appending/css to list errors and a successful send. It normally pops up an error on the field if you have left it blank / if it is not a proper address, and when succesful, removes the form and appends a thank you note.
The problem is, while it works perfectly on my own server, it sends the mail without giving error/success on the production
I'm not using cross-domain requests, and I have tried disabling compression to no avail. Caching is enabled, though it should not matter.
The javascript
$('.contact-us').submit(function(e) {
e.preventDefault();
$('.contact-us input, .contact-us textarea').removeAttr('style');
$('.error').remove();
var postdata = $('.contact-us').serialize();
$.ajax({
type: 'POST',
url: 'contact2.php',
data: postdata,
dataType: 'json',
success: function(returned_data) {
var j = 0;
var submit_ok = true;
$.each(returned_data, function(key, value) {
if(value != '') {
$('.contact-us .' + key).attr('style', 'border-color: #e67632; -moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none;');
$('.contact-us .' + key).focus();
$('.contact-us').append('<div class="error"> ' + value + '</div>');
$('.error').css('top', (j*52) + 'px');
$('.error').fadeIn('slow');
submit_ok = false;
return false;
}
j++;
});
if(submit_ok) {
$('.contact-us').append('<p style="display: none;">Thanks for contacting us! We will get back to you very soon.</p>');
$('.contact-us input, .contact-us textarea, .contact-us button').remove();
$('.contact-us p').fadeIn('slow');
}
}
});
});
The php
<?php
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]* [[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email));
}
if($_POST) {
$emailTo = 'myemail#gmail.com';
$clientName = trim($_POST['name']);
$clientEmail = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
$errors_array = array('name' => '', 'email' => '', 'subject' => '', 'message' => '');
if($clientName == '') {
$errors_array['name'] = 'Please enter your name!';
}
if(!isEmail($clientEmail)) {
$errors_array['email'] = 'Insert a valid email address!';
}
if($subject == '') {
$errors_array['subject'] = 'Please enter the subject!';
}
if($message == '') {
$errors_array['message'] = 'Please enter your message!';
}
if($clientName != '' && isEmail($clientEmail) && $message != '' && $subject != '') {
// Send email
$headers = "From: " . $clientName . " <" . $clientEmail . ">" . "\r\n" . "Reply-To: " . $clientEmail;
mail($emailTo, $subject, $message, $headers);
}
echo json_encode($errors_array);
}
?>