Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

chrissyg

Members
  • Joined

  • Last visited

Everything posted by chrissyg

  1. Hi all, When I'm trying to add a category the "Add Category" button does absolutely nothing. I'm using WP 3.2.1. Any ideas on what WP files to look for? Chris
  2. Sorry Jock that answer was mint. +1 accordingly.
  3. Hi guys, if (!preg_match('/^[a-zA-Z]+$/i',$this->name2 )) { $this->setError('Surname contains invalid characters, only letters allowed'); } How do I amend this to allow a single quote: ' and a backslash / Cheers, Chris
  4. Cheers, been staring at PHP for so long I've had code-blindness for the basics. +1 to you.
  5. <input type="radio" name="q1" value="A" /> A<br /> <input type="radio" name="q1" value="B" /> B<br /> <input type="radio" name="q1" value="C" /> C<br /> <input type="radio" name="q1" value="D" /> D<br />
  6. chrissyg posted a topic in Frontend
    Hi all, My website is at completion level aside from some content but I'm having a real hard time trying to change the font for each radio button choice. It seems stuck on Times New Roman as a default. How would I call this in CSS to edit it? Cheers, Chris
  7. Beeble = craigpetit For what it's worth, webdesigner93 and rallport are a couple of helpful dudes (dudettes?) and have both helped me at some point.
  8. I'm guessing his username might be his e-mail address. Using a session variable when returning comment is daft as every different user will only see their own e-mail in the comments section. You already have the email in the database and being selected in the query, what's wrong with just adding this field to what you're trying to do?
  9. chrissyg replied to chrissyg's topic in Server Side
    That looks like it should work. I'll give it a shot when I get in. $data = $this->input->post('smeg'); For this bit^, would I need to have a different variable for each post item being used? Ex. $data1 = $this->input->post('username'); $data1 = $this->input->post('email'); $data3 = $this->input->post('password'); +1 by the way.
  10. What's your schema for your comments table?
  11. Session would be a pretty rubbish way to do it. A session variable is unique to machine that runs the script unless you are going to initialise every e-mail address in your database as a session variable. That would suck.
  12. chrissyg posted a topic in Server Side
    Hi guys, I'm having a bit of an issue with giving a model user input for a query. Say the query is something like: $q = $this->db->query("SELECT * FROM table_name WHERE column_name = '$myInput'"); Returns an error with the variable, if I hard code the string it works fine. So, how do we pass input from the user or predefined session variables to the model? Cheers, Chris
  13. I have solved the problem, the variables were not initialised. I'm not sure I'm making myself clear so.... Name Email Password These fields have different constraints (ex. in Name, only a-zA-Z) and require different classes for different constraints.
  14. I have seperate classes for different kinds of field. eg. Name Email Password The validation seems to let anything through... :-/
  15. Hi everyone, I'm having a bit of trouble trying to implement this design pattern for form validation. Here is my code. index.php <?php if (isset( $_POST['register'] )) { //check for existing records $con = mysql_connect("stuff") or die(mysql_error()); mysql_select_db("db", $con) or die(mysql_error()); $result1 = mysql_query("SELECT * FROM blah WHERE username = '$userName'") or die(mysql_error()); $row1 = mysql_fetch_array( $result1 ); $result2 = mysql_query("SELECT * FROM blah WHERE email = '$email1'") or die(mysql_error()); $row2 = mysql_fetch_array( $result2 ); $result3 = mysql_query("SELECT * FROM blah WHERE email = '$email2'") or die(mysql_error()); $row3 = mysql_fetch_array( $result3 ); require_once('validator.php'); // Register the subclasses to use $v['u']=new ValidateUser($userName, $row1); $v['p']=new ValidatePassword($passWord1, $passWord2); $v['e']=new ValidateEmail($email1, $email2, $row2); $v['n']=new ValidateName($firstName, $lastName); // Perform each validation foreach($v as $validator) { if (!$validator->isValid()) { while ($error=$validator->getError()) { $errorMsg.="<li>".$error."</li>"; } } } if (isset($errorMsg)) { echo 'row1 = ' . $row1; echo 'row2 = ' . $row2; print ("<p>There were errors:<ul>".$errorMsg."</ul>"); } else { print ('<h2>Form Valid!</h2>'); } } else { echo' <h2>Create New Account</h2> <form action="http://www.iamcg.co.uk/tests/index.php" method="POST"> <tr> <td><span class="formText">UserName:</span></td> <td><input type="text" name="userName" size="27" /></td> </tr> <tr> <td><span class="formText">First Name:</span></td> <td><input type="text" name="firstName" size="27" /></td> </tr> <tr> <td><span class="formText">Last Name:</span></td> <td><input type="text" name="lastName" size="27" /></td> </tr> <tr> <td><span class="formText">E-mail:</span></td> <td><input type="text" name="email1" size="27" /></td> </tr> <tr> <td><span class="formText">Confirm E-mail:</span></td> <td><input type="text" name="email2" size="27" /></td> </tr> <tr> <td><span class="formText">Password:</span></td> <td><input type="password" name="passWord1" size="27" /></td> </tr> <tr> <td><span class="formText">Confirm Password:</span></td> <td><input type="password" name="passWord2" size="27" /></td> </tr> <tr> <td> </td> </tr> <input type="submit" name="register" value=" Register "> </form> </table> </form>'; } ?> And validator.php <?php /** * Validator superclass for form validation */ class Validator { /** * Private * $errorMsg stores error messages if not valid */ var $errorMsg; //! A constructor. /** * Constucts a new Validator object */ function Validator () { $this->errorMsg=array(); $this->validate(); } //! A manipulator /** * @return void */ function validate() { // Superclass method does nothing } //! A manipulator /** * Adds an error message to the array * @return void */ function setError ($msg) { $this->errorMsg[]=$msg; } //! An accessor /** * Returns true is string valid, false if not * @return boolean */ function isValid () { if ( isset ($this->errorMsg) ) { return false; } else { return true; } } //! An accessor /** * Pops the last error message off the array * @return string */ function getError () { return array_pop($this->errorMsg); } } /** * ValidatorUser subclass of Validator * Validates a username */ class ValidateUser extends Validator { /** * Private * $user the username to validate and the size of our result */ var $userName; var $row1; //! A constructor. /** * Constucts a new ValidateUser object * @param $user the string to validate */ function ValidateUser ($userName, $row1) { $this->user=$userName; $this->size1=$row1; Validator::Validator(); } //! A manipulator /** * Validates a username * @return void */ function validate() { /* if (!preg_match('/^[a-zA-Z0-9]+$/i',$this->user )) { $this->setError('Username contains invalid characters'); } */ if (strlen($this->user) < 5 ) { $this->setError('Username is too short'); } if (strlen($this->user) > 20 ) { $this->setError('Username is too long'); } if ($this->size1 > 0) { $this->setError('Username already in use, please try another'); } } } /** * ValidatorName subclass of Validator * Validates a firstname and surname */ class ValidateName extends Validator { /** * Private * $user the first and last names to validate */ var $firstName; var $lastName; //! A constructor. /** * Constucts a new ValidateUser object * @param $firstName and $lastName the strings to validate */ function ValidateName ($firstName, $lastName) { $this->name1=$firstName; $this->name2=$lastName; Validator::Validator(); } //! A manipulator /** * Validates names * @return void */ function validate() { if (!preg_match('/^[a-zA-Z]+$/i',$this->name1 )) { $this->setError('First name contains invalid characters, only letters allowed'); } if (!preg_match('/^[a-zA-Z]+$/i',$this->name2 )) { $this->setError('Surname contains invalid characters, only letters allowed'); } if (strlen($this->name1) < 2 ) { $this->setError('First name is too short'); } if (strlen($this->name2) < 2 ) { $this->setError('Surname is too short'); } if (strlen($this->name1) > 20 ) { $this->setError('First name is too long'); } if (strlen($this->name2) > 20 ) { $this->setError('Surname is too long'); } } } /** * ValidatorPassword subclass of Validator * Validates a password */ class ValidatePassword extends Validator { /** * Private * $pass the password to validate */ var $passWord1; /** * Private * $conf to confirm the passwords match */ var $passWord2; //! A constructor. /** * Constucts a new ValidatePassword object subclass or Validator * @param $pass the string to validate * @param $conf to compare with $pass for confirmation */ function ValidatePassword ($passWord1,$passWord2) { $this->pass=$passWord1; $this->conf=$passWord2; Validator::Validator(); } //! A manipulator /** * Validates a password * @return void */ function validate() { if ($this->pass!=$this->conf) { $this->setError('Passwords do not match'); } if (!preg_match('/^[a-zA-Z0-9_]+$/',$this->pass)) { $this->setError('Password contains invalid characters'); } if (strlen($this->pass) < 6 ) { $this->setError('Password is too short'); } if (strlen($this->pass) > 20 ) { $this->setError('Password is too long'); } } } /** * ValidatorEmail subclass of Validator * Validates an email address */ class ValidateEmail extends Validator { /** * Private * $email the email address to validate */ var $email1; /** * Private * $email the confirm mail address to validate */ var $email2; /** * Private * query size to checked for duplicates */ var $row2; //! A constructor. /** * Constucts a new ValidateEmail object subclass or Validator * @param $email the string to validate */ function ValidateEmail ($email1, $email2, $row2){ $this->email1=$email1; $this->email2=$email2; $this->size2=$row2; Validator::Validator(); } //! A manipulator /** * Validates an email address * @return void */ function validate() { $pattern= "/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/"; if(!preg_match($pattern,$this->email1)){ $this->setError('Invalid email address'); } if ($this->email1!=$this->email2) { $this->setError('Emails do not match'); } if (strlen($this->email)>30){ $this->setError('Address is too long'); } if ($this->size2 > 0) { $this->setError('Email address already in use, please try another'); } } } ?> I have validation that works perfectly without using the pattern but as soon as I try and implement it with Strategy, it stops working. I can only imagine I'm doing it incorrectly. Any ideas? Cheers, Chris
  16. This looks like a winner. I'll give it a bash over the weekend and post feedback. +1
  17. I am using PHP. It's not so much the actual comparison between inputs and table data - that's easy. It's finding an elegant way of doing it without having to have a conditional statement for every answer.
  18. Hi all, Looking for a bit of advice regarding comparing user answers to test questions with the correct answers in the database. I'm struggling to think of a better way than something along the lines of comparing each answer to a new query. Schema is currently: testID | answer1 | answer2 ........ | answerx Any thougths?
  19. Can you post the paragraph that was causing it? I'd wager there will be some sort of escape character issue.
  20. Remember to include a test at the start of each script to make sure the user is logged in Example, in myprofile.php session_start(); if (!isset($_SESSION["userName"])){ header( "Location: http://www.blahblag/login" ); }
  21. Jock, can work sessions ok and will need to brush up on security outside of timeouts, MD5 and input sanitising. sunwukung, did a software architecture class so pretty clued up on design patterns. Will have to brush up on the rest of the stuff you mentioned. My *nix experience is pretty limited so I feel quite week in that area.
  22. Cheers Jock. Anything else to be able to demonstrate on top of forms, scraping and database linking?
  23. Yep, working with session stuff at the moment and I try to make sure that session_start(); is the first line of all my PHP session scripts.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.