I am writing a rather large PHP application and I've come to a point where I would like some debugging output. I've successfully installed FireBug and FirePHP and I've managed to output one line of text to the console.
Here is the problem now. I have a php file called Register.php which contains basically code only to display the view and submit the form. This file calls a function in the SiteViewModel.php class to do the actually background work in registering the user. The SiteViewModel.php also calls other php files to connect to the DB and perform checks/inserts.
If I put the debugging line in the SiteViewModel.php file constructor I get an output to the Firebug console. If I put any other lines anywhere else I get nothing logged.
Some code
Register.php:
<?php
require_once("/xampp/htdocs/SiteConfig.php");
if(isset($_POST['submitted']))
{
if($rlrpgSite->RegisterUser())
{
$rlrpgSite->RedirectToURL("registrationthanks.php");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Register</title>
<link rel="STYLESHEET" type="text/css" href="../style/fg_membersite.css" />
<script type='text/javascript' src='../scripts/gen_validatorv31.js'></script>
<link rel="STYLESHEET" type="text/css" href="../style/pwdwidget.css" />
<script src="../scripts/pwdwidget.js" type="text/javascript"></script>
</head>
<body>
<!-- Form Code Start -->
<div id='fg_membersite'>
<form id='register' action='<?php echo $rlrpgSite->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
<fieldset >
<legend>Register</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<div class='short_explanation'>* required fields</div>
<input type='text' class='spmhidip' name='<?php echo $rlrpgSite->GetSpamTrapInputName(); ?>' />
<div><span class='error'><?php echo $rlrpgSite->GetErrorMessage(); ?></span></div>
<div class='container'>
<label for='firstname' >First Name*: </label><br/>
<input type='text' name='FirstName' id='FirstName' value='<?php echo $rlrpgSite->SafeDisplay('FirstName') ?>' maxlength="100" /><br/>
<span id='register_firstname_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='lastname' >Last Name*: </label><br/>
<input type='text' name='LastName' id='LastName' value='<?php echo $rlrpgSite->SafeDisplay('LastName') ?>' maxlength="100" /><br/>
<span id='register_lastname_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='email' >Email Address*:</label><br/>
<input type='text' name='EmailAddress' id='EmailAddress' value='<?php echo $rlrpgSite->SafeDisplay('EmailAddress') ?>' maxlength="512" /><br/>
<span id='register_email_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='username' >UserName*:</label><br/>
<input type='text' name='UserName' id='UserName' value='<?php echo $rlrpgSite->SafeDisplay('UserName') ?>' maxlength="255" /><br/>
<span id='register_username_errorloc' class='error'></span>
</div>
<div class='container' style='height:80px;'>
<label for='Password' >Password*:</label><br/>
<div class='pwdwidgetdiv' id='thepwddiv' ></div>
<noscript>
<input type='password' name='Password' id='Password' maxlength="50" />
</noscript>
<div id='register_password_errorloc' class='error' style='clear:both'></div>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form>
<!-- client-side Form Validations:
Uses the excellent form validation script from JavaScript-coder.com-->
<script type='text/javascript'>
// <![CDATA[
var pwdwidget = new PasswordWidget('thepwddiv','Password');
pwdwidget.MakePWDWidget();
var frmvalidator = new Validator("register");
frmvalidator.EnableOnPageErrorDisplay();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("firstname","req","Please provide your name");
frmvalidator.addValidation("lastname","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email address");
frmvalidator.addValidation("email","email","Please provide a valid email address");
frmvalidator.addValidation("username","req","Please provide a username");
frmvalidator.addValidation("Password","req","Please provide a password");
// ]]>
</script>
<!--
Form Code End (see html-form-guide.com for more info.)
-->
</body>
</html>
SiteConfig.php:
<?php
require_once('SiteViewModel.php');
$rlrpgSite = new siteviewmodel();
$rlrpgSite->SetWebsiteName('localhost.com');
$rlrpgSite->SetAdminEmail('rlrpg#localhost.com');
$rlrpgSite->SetRandomKey('Hng2XxIdNfp8EwO');
?>
SiteViewModel.php:
<?php
class siteviewmodel
{
...
function siteviewmodel()
{
ob_start();
fb("Instantiating");
//This works
}
RegistUser()
{
ob_start();
fb("Registering");
//doesn't work
}
}
?>
Related
I have a form on my website it works fine with nonwww.domain. if I try with www.domain in the same site
It won't go, Its keep on rotating after captcha, refresh page with new captcha and filled form is there.
Help me solve this error
I had this form earlier its work fine in other domain
This domain is under yahoo hosting
And
I have not any reply from them
Please find the code
Is this server error
<link rel="STYLESHEET" type="text/css" href="contact.css" />
<script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
<script type='text/javascript' src='scripts/fg_captcha_validator.js'></script>
<!-- Form Code Start -->
<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
<fieldset >
<legend>Contact us</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div class='short_explanation'>* required fields</div>
<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container'>
<label for='name' >Your Full Name*: </label><br/>
<input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
<span id='contactus_name_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='email' >Email Address*:</label><br/>
<input type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
<span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='message' >Message:</label><br/>
<span id='contactus_message_errorloc' class='error'></span>
<textarea rows="10" cols="50" name='message' id='message'><?php echo $formproc->SafeDisplay('message') ?></textarea>
</div>
<div class='container'>
<label for='photo' >Upload your photo:</label><br/>
<input type="file" name='photo' id='photo' /><br/>
<span id='contactus_photo_errorloc' class='error'></span>
</div>
<div class='container'>
<div><img alt='Captcha image' src='show-captcha.php?rand=1' id='scaptcha_img' /></div>
<label for='scaptcha' >Enter the code above here:</label>
<input type='text' name='scaptcha' id='scaptcha' maxlength="10" /><br/>
<span id='contactus_scaptcha_errorloc' class='error'></span>
<div class='short_explanation'>Can't read the image?
<a href='javascript: refresh_captcha_img();'>Click here to refresh</a>.</div>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form>
<!-- client-side Form Validations:
Uses the excellent form validation script from JavaScript-coder.com-->
<script type='text/javascript'>
// <![CDATA[
var frmvalidator = new Validator("contactus");
frmvalidator.EnableOnPageErrorDisplay();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email address");
frmvalidator.addValidation("email","email","Please provide a valid email address");
frmvalidator.addValidation("message","maxlen=2048","The message is too long!(more than 2KB!)");
frmvalidator.addValidation("photo","file_extn=jpg;jpeg;gif;png;bmp","Upload images only. Supported file types are: jpg,gif,png,bmp");
frmvalidator.addValidation("scaptcha","req","Please enter the code in the image above");
document.forms['contactus'].scaptcha.validator
= new FG_CaptchaValidator(document.forms['contactus'].scaptcha,
document.images['scaptcha_img']);
function SCaptcha_Validate()
{
return document.forms['contactus'].scaptcha.validator.validate();
}
frmvalidator.setAddnlValidationFunction("SCaptcha_Validate");
function refresh_captcha_img()
{
var img = document.images['scaptcha_img'];
img.src = img.src.substring(0,img.src.lastIndexOf("?")) + "?rand="+Math.random()*1000;
}
// ]]>
</script>
I'm working on a project where I am learning the importance of having a header file with a nav and including that header file in other files so that my nav will display the same in all other vies.
The problem I'm having is the css that I linked to my header file is not being applied to a certain page... I think it has to do with file paths but I'm not sure. Can someone take a look at what I have and give me some insight? Thanks!
css not being included
my file structure
Here is my header file:
<?php session_start();
$_SESSION['DOCUMENT_ROOT'] = 'login_system/';
?>
<!DOCTYPE html>
<html>
<head>
<link href="css/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<script scr="scripts/main.js"></script>
<title>Login page</title>
</head>
<body>
<div class="header">
<div class="nav">
<ul>
<li>Home</li>
<?php
if (isset($_SESSION['id']))
echo "<form action='includes/logout.php'>
<button>Log out</button>
</form>";
else
echo "<form action='includes/login.php' method='POST'>
<input type='text' name='username' placeholder='username'>
<input type='password' name='password' placeholder='Password'>
<button class='button-submit' type='submit'>Login</button>
</form>";
?>
<li>Sign up</li>
</ul>
</div>
</div>
and here is my signup code:
<?php require '../../includes/header.php'; ?>
<div class"container">
<?php
if (isset($_SESSION['id']))
echo 'You are already logged in!';
else
echo "<form action='../../includes/signup.php' method='POST'>
<label for='firstname'>First name:</label>
<input type='text' name='firstname' placeholder='First name'><br>
<label for='lastname'>Last name:</label>
<input type='text' name='lastname' placeholder='Last name'><br>
<label for='username'>Username:</label>
<input type='text' name='username' placeholder='username'><br>
<label for='lastname'>Desired Password:</label>
<input type='password' name='password' placeholder='Password'><br>
<button type='submit'>Sign up</button>
</form>";
?>
</div>
</body>
</html>
I am using php and CodeIgniter. I am a novice at both of these (career VB.Net and C# developer). However, trying to create a basic registration form, I'm having a hard time getting jQuery validation to work.
header.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?><!DOCTYPE html>
<html>
<head>
<?php if(isset($title)) {?>
<title>Discuss Cards - <?php echo $title ?></title>
<?php } else { ?>
<title>Discuss Cards</title>
<?php } ?>
<link rel="stylesheet" href="<?php echo base_url();?>styles/forum.css" type="text/css"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> </script>
<script src="<?php echo base_url();?>js/jquery.validate.min.js"></script>
</head>
<body>
<?php if(isset($title)) {?>
<h1><?php echo $title?></h1>
<?php } ?>
<?php if (isset($page_description)) {?>
<p id="page_description"><?php echo $page_description?></p>
<?php } ?>
create.php
<script>
$("#createaccount").validate();
</script>
<?php $attributes = array('id'=>'createaccount');
echo form_open('user/create_account',$attributes); ?>
<?php echo form_label('Email','txtEmail');?>
<br />
<?php $data = array('type'=>'email','name'=>'txtEmail','id'=>'txtEmail','maxlength'=>'50','minlength'=>'2');
echo form_input($data); ?>
<br /><br />
<?php echo form_label('Username','txtUsername');?>
<br />
<?php $data = array('name'=>'txtUsername','id'=>'txtUsername','maxlength'=>'50','minlength'=>'5');
echo form_input($data); ?>
<br /><br />
<?php echo form_label('Password','pswPassword');?>
<br />
<?php $data = array('name'=>'pswPassword','id'=>'pswPassword');
echo form_password($data); ?>
<br /><br />
<?php echo form_label('Confirm Password','pswConfirmPassword');?>
<br />
<?php $data = array('name'=>'pswConfirmPassword','id'=>'pswConfirmPassword');
echo form_password($data); ?>
<br /><br />
<input type="submit" value="Register" name="Register" />
<?php echo form_close();?>
footer.php
<strong>© 2016</strong>
</body>
</html>
result...
<!DOCTYPE html>
<html>
<head>
<title>Discuss Cards - Create New Account</title>
<link rel="stylesheet" href="http://[::1]/forum/styles/forum.css" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://[::1]/forum/js/jquery.validate.min.js"></script>
</head>
<body>
<h1>Create New Account</h1>
<script>
$("#createaccount").validate();
</script>
<form action="http://[::1]/forum/index.php/user/create_account" id="createaccount" method="post" accept-charset="utf-8">
<label for="txtEmail">Email</label>
<br>
<input type="email" name="txtEmail" value id="txtEmail" maxlength="50" minlength="2">
<br>
<br>
<label for="txtUsername"></label>
<br>
<input type="text" name="txtUsername" value id="txtUsername" maxlength="50" minlength="5">
<br>
<br>
<label for="pswPassword">Password</label>
<br>
<input type="password" name="pswPassword" value id="pswPassword">
<br>
<br>
<label for="pswConfirmPassword">Confirm Password</label>
<br>
<input type="password" name="pswConfirmPassword" value id="pswConfirmPassword">
<br>
<br>
<input type="submit" value="Register" name="Register">
</form>
<strong>© 2016</strong>
</body>
</html>
Now, the links to the js and css files are correct. I used the example from http://jqueryvalidation.org/documentation/:
<form class="cmxform" id="commentForm" method="get" action="">
<fieldset>
<legend>Please provide your name, email address (won't be published) and a comment</legend>
<p>
<label for="cname">Name (required, at least 2 characters)</label>
<input id="cname" name="name" minlength="2" type="text" required>
</p>
<p>
<label for="cemail">E-Mail (required)</label>
<input id="cemail" type="email" name="email" required>
</p>
<p>
<label for="curl">URL (optional)</label>
<input id="curl" type="url" name="url">
</p>
<p>
<label for="ccomment">Your comment (required)</label>
<textarea id="ccomment" name="comment" required></textarea>
</p>
<p>
<input class="submit" type="submit" value="Submit">
</p>
</fieldset>
</form>
<script>
$("#commentForm").validate();
</script>
However, I feel that I'm missing something because it's not working. When I use their demo (http://jqueryvalidation.org/files/demo/), a new label is created under the input area which displays the error. However, when I test my code (Notepadd++, latest version of Google Chrome, WAMPServer 2.5), I only get Chrome validation. Could someone point out to me what I'm doing incorrect? Thanks.
A bit too long for a comment, but not sure if it is the only problem. The first thing I see is that the
<script>
$("#createaccount").validate();
</script>
is located before the form with id="createaccount". This means this javascript code is parsed and run before the element exists inside the DOM.
In order to run this JS when the DOM is loaded, you then need to wrap it into this specific jquery part :
$( document ).ready( function( ) {
$("#createaccount").validate();
}
(And ideally you put all JS at the end of the page, before the closing </body> tag)
So I've put a contact form into my site but I can't seem to add a subject line. (I'm SUPER new to PHP so I'm only about 40% sure of what I'm doing. The rest of the time I'm just learning through trial and error).
Here's what I have for the form:
<?PHP
require_once("./include/fgcontactform.php");
$formproc = new FGContactForm();
$formproc->AddRecipient('email address');
$formproc->AddSubject('Website Communication:');
$formproc->SetFormRandomKey('boQQEtSLenwppBa');
if(isset($_POST['submitted']))
{
if($formproc->ProcessForm())
{
$formproc->RedirectToURL("thank-you.php");
}
}
?>
<!-- Form Code Start -->
<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
<fieldset >
<legend>Contact us</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div class='short_explanation'>* required fields</div>
<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container'>
<label for='name' >Your Full Name*: </label><br/>
<input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
<span id='contactus_name_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='email' >Email Address*:</label><br/>
<input type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
<span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='message' >Message:</label><br/>
<span id='contactus_message_errorloc' class='error'></span>
<textarea rows="10" cols="50" name='message' id='message'><?php echo $formproc->SafeDisplay('message') ?></textarea>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form>
I added the $formproc->AddSubject('Website Communication:'); segment but it doesn't seem to be working and I'm wondering if there's something I'm missing?
What you're really asking is how to use a specific library class that you've downloaded from the Internet! If you look into the code of the class you're including at the top (which I assume is the same as this?) then you'll see it's automatically generating a subject line here:
$this->mailer->Subject = "Contact form submission from $this->name";
The reason your AddSubject function doesn't work is because that behaviour doesn't exist within the class.
If you want to change this behaviour, you'll have to change the class. You'll want to change the above line to something like
$this->mailer->Subject = $this->getSubject();
and implement a getSubject() method, similar to the GetFromAddress() one.
Better yet, create your own mailer class! Look into the PHP mail function to get started!
I'm very new to web developing and PHP. I'm creating a website with a member area and would like to display a Welcome "username" message. In my actual code there is a Welcome message displaying the Full Name of user. Can someone help me here? Below I'm pasting the code I'm using for my login.php and login-home.php (member's area). Thank you
login.php
<?PHP
require_once("./include/membersite_config.php");
if(isset($_POST['submitted']))
{
if($fgmembersite->Login())
{
$fgmembersite->RedirectToURL("login-home.php");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Login</title>
<link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css" />
<script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
</head>
<body>
<!-- Form Code Start -->
<div class="logo_container"></div>
<div class='splash-container'>
<div id='fg_membersite'>
<form id='login' action='<?php echo $fgmembersite->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
<fieldset >
<legend>Orcaly</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<div><span class='error'><?php echo $fgmembersite->GetErrorMessage(); ?></span></div>
<div class='container'>
<label for='username' ></label><br/>
<input type='text' placeholder="UserName"name='username' id='username' value='<?php echo $fgmembersite->SafeDisplay('username') ?>' maxlength="50" /><br/>
<span id='login_username_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='password' ></label><br/>
<input type='password' placeholder="Password" name='password' id='password' maxlength="50" /><br/>
<span id='login_password_errorloc' class='error'></span>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
<div class='short_explanation'><a href='reset-pwd-req.php'>Forgot Password?</a></div>
<div class='register'><a href='register.php'>Register</a></div>
</fieldset>
</form>
<!-- client-side Form Validations:
Uses the excellent form validation script from JavaScript-coder.com-->
<script type='text/javascript'>
// <![CDATA[
var frmvalidator = new Validator("login");
frmvalidator.EnableOnPageErrorDisplay();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("username","req","Please provide your username");
frmvalidator.addValidation("password","req","Please provide the password");
// ]]>
</script>
</div>
</div>
<!--
Form Code End (see html-form-guide.com for more info.)
-->
</body>
</html>
login-home.php
<?PHP
require_once("./include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("login.php");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Home page</title>
<link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css">
</head>
<body>
<div class="logo_container"></div>
<div class='splash-container'>
<div id='fg_membersite'>
<fieldset>
<legend>Home Page</legend>
<div class='confirmation'>Welcome back <?= $fgmembersite->UserFullName(); ?>!</div>
<div class='confirmation'><a href='change-pwd.php'>Change password</a></div>
<div class='register'><a href='access-controlled.php'>A sample 'members-only' page</a></div>
<br>
<div class='register'><a href='logout.php'>Logout</a></div>
</fieldset>
</div>
</div>
</body>
</html>
The simple answer is you need to change this line of code:
<div class='confirmation'>Welcome back <?= $fgmembersite->UserFullName(); ?>!</div>
So that $fgmembersite->UserFullName(); becomes a variable that holds your username or a function that returns your username. Right now it is a function that returns the user's full name.
This might be a little bit beyond your current skills at programming. One thing that is very simple and feasible is to store the username as a session variable when the user logs in. Then you can replace $fgmembersite->UserFullName(); with $_SESSION["username"] or whatever you descide to call it.
Alternatively you can define your own function to return the username, or if the username isn't available for some reason, some other value (which is slightly better design).