Jump to content


  • Posts

  • Joined

  • Last visited


Profile Information

  • Gender
  • Location
    Portland, Oregon

OldWest's Achievements

Regular Member

Regular Member (3/5)



  1. Hello, I have a table that has 5 fields of data. In many cases, not all of the fields have data in them. Each time the View action of the Controller is requested, I would like to only display the fields that have content in them AND the tabular structure of the data will change based on the content as well. So basically, I think I will need a unique View file for each type of data schema. And there are 3 schemes. For example, Schema | 1 | 2 | 3 | 4 | 5 | A X X X X X B X X X C X X X As you can see, each schema has different data populated. This tells me I will need 3 View structures to accommodate these schema's. Can anyone make a recommendation on the best way to handle this in the CakePHP framework. I am thinking an if condition in the Controller, and then render() based on that, but its seems there would be a more conventional method. Thanks for any thoughts on this.
  2. I've been cracking at this for the part of 2 days now, and I cannot get my regex to work properly in my script. /^[A-Za-z][\w\-',.]*(?<![^A-Za-z][\w\-\'\,\.])$/i The above is for a last name field, and it needs to be able to accept: Roberts, Jr. (as an example)... As you can see in my regex, I am allowing all of these characters.. And it's still not validating it. You can test to see what I mean here: <?php $last_name = "Roberts, Jr."; if (!preg_match("/^[A-Za-z][\w\-',.]*(?<![^A-Za-z][\w\-\'\,\.])$/i", $last_name )) { echo "Sorry no dice!"; } ?>
  3. I volunteer maintain an old site that was created in early 2000 and the owners refuse to upgrade because of expenses ?!?! Basically the entire site php relies on all the security venerabilities of php4... So I guess some people learn the hard way.
  4. Nice idea. The double for loops seem like the best solution. . Thx.
  5. Yes. You are thinking correct. Read up on: variable variables Basically the variable variable works like this: $variable = "ABC"; $$variable = "CDE"; echo $ABC; // CDE The value assigned to $variable becomes the variable itself. So ABC becomes $ABC becomes CDE in that case when the variable variable $$variable is used. There are LOT of uses for the variable variable I am finding lately that really strip out code redundancy! I still have a lot to learn with it, but it's worth the time to read up on.
  6. I am doing some practice with classes. MY class below echoes out input and radio fields based on the instantiation of the Form class (the code below is working!), but I am trying to resolve how to get my form radio fields so they are not in between every other form field as they are supposed to be next to eachother. If you run the below, you will see what I mean. And also is my approach at all sensible? I am only doing this for learning experience, so any advice please. <?php class Form { private $fields = array(); private $radios = array(); private $actionValue; private $submit = "Submit Form"; private $Nradios = 0; private $Nfields = 0; function __construct($actionValue, $submit) { $this->actionValue = $actionValue; $this->submit = $submit; } function displayForm() { echo "<form action='{$this->actionValue}' method='post'>\n\n"; for ($j = 1, $i = 1; $j <= sizeof($this->fields), $i <= sizeof($this->radios); $j++, $i++) { echo "<p>\n<label>{$this->fields[$j-1]['label']} : </label>\n"; echo "<input type='text' name='{$this->fields[$j-1]['name']}'>\n</p>\n\n"; echo "<p>\n<label>{$this->radios[$i-1]['rlabel']} : </label>\n"; echo "\n<input type='radio' name='{$this->radios[$i-1]['rname']}' value='{$this->radios[$i-1]['rvalue']}'>\n</p>\n\n"; } echo "\n\n<input type='submit' value='{$this->submit}'>\n</form>"; } function addField($name, $label) { $this->fields[$this->Nfields]['name'] = $name; $this->fields[$this->Nfields]['label'] = $label; $this->Nfields = $this->Nfields + 1; } function addRadio($rname, $rvalue, $rlabel) { $this->radios[$this->Nradios]['rname'] = $rname; $this->radios[$this->Nradios]['rvalue'] = $rvalue; $this->radios[$this->Nradios]['rlabel'] = $rlabel; $this->Nradios = $this->Nradios + 1; } } ?> <?php $contact_form = new Form("process.php", "Submit Data >>"); $contact_form->addField("first_name", "First Name"); $contact_form->addField("last_name", "Last Name"); $contact_form->addRadio("gender", "male", "Male"); $contact_form->addRadio("gender", "femail", "Female"); $contact_form->displayForm(); ?>
  7. Hello, My script below IS finally working, but I was hoping for some aggressive, anal comments for critique. Keep in mind, I am developing for a php4 platform otherwise I would have used a newer php5 validation function. <?php if (isset($_POST['btnSubmit'])) { $first_name = mysql_real_escape_string($_POST['fname']); $last_name = mysql_real_escape_string($_POST['lname']); $title = mysql_real_escape_string($_POST['title']); $company = mysql_real_escape_string($_POST['company']); $address1 = mysql_real_escape_string($_POST['address1']); $address2 = mysql_real_escape_string($_POST['address2']); $city = mysql_real_escape_string($_POST['city']); $zip = mysql_real_escape_string($_POST['zip']); $phone = mysql_real_escape_string($_POST['phone']); $fax = mysql_real_escape_string($_POST['fax']); $email = mysql_real_escape_string($_POST['email']); if (!preg_match("/^[A-Za-z' -]{1,75}$/", $first_name)) { $error[] = "Please enter a valid first name."; } if (!preg_match("/^[A-Za-z' -]{1,75}$/", $last_name)) { $error[] = "Please enter a valid last name."; } if ($first_name === $last_name && $first_name != "") { $error[] = "First Name and Last Name cannot be the same."; } if (!preg_match("/^[A-Za-z' -]{1,150}$/", $company)) { $error[] = "Please enter a valid company name."; } if (!preg_match("/^[A-Za-z' -.]{1,150}$/", $title)) { $error[] = "Please enter a valid Title."; } if (!preg_match("/^[A-Za-z0-9' - . ]{1,150}$/", $address1)) { $error[] = "Please enter a valid mailing address."; } if (!preg_match("/^[A-Za-z0-9' - . ]{1,150}$/", $city)) { $error[] = "Please enter a valid city."; } if (!preg_match("/^[0-9' - . ( ) ]{1,150}$/", $phone)) { $error[] = "Please enter a valid phone number."; } if (!preg_match("/^[0-9' - . ( ) ]{1,150}$/", $fax)) { $error[] = "Please enter a valid fax number."; } if (!preg_match("/([a-z][a-z0-9_.-\/]*@[^\s\"\)\?<>]+\.[a-z]{2,6})/i", $email)) { $error[] = "Please enter a valid email address in the format: start@middle.end."; } if (is_array($error)) { echo "<div id='errorWrapper'><h2>There are errors in your input. Please correct the following fields:</h2>"; foreach ($error as $err_message) { echo "<span class='errorText'> >> $err_message" . "</span><br />"; } echo "</div>"; include('../includes/attendee_registration_form.php'); // this is the form exit(); } else { include('../includes/attendee_registration_mailer.php'); // this send the email and populates the table } } else { include('../includes/attendee_registration_form.php'); // this is the form exit(); } ?>
  8. My script IS working, but I can't get around a blank array error when no errors exist. Below is my code, and as you can see, I am being handed this: Notice: Undefined variable: error in C:\wamp\www\php\form_validation.php on line 19 as a result of my ... if (is_array($error)) { ... .. I could do if (@is_array($error)) { (note the @), but I hate using that thing... I've tried several things with no luck, so any ideas welcome at this point. <?php if (isset($_POST['set_test'])) { if (!preg_match("/^[A-Za-z' -]{1,50}$/", $_POST['first_name'])) { $error[] = "Please enter a valid First Name"; } if (!preg_match("/^[A-Za-z' -]{1,50}$/", $_POST['last_name'])) { $error[] = "Please enter a valid Last Name"; } if (is_array($error)) { foreach ($error as $err_message) { echo $err_message . "<br />"; } } } ?>
  9. I had a bunch of issue with my regex and script, but I think I am just about solved... Will post solved when there: <?php if(isset($_POST['set_test'])) { if(!preg_match("/^[A-Za-z' -]{1,50}$/",$_POST['first_name'])) { $error[] = "Please enter a valid First Name"; } else { $error[] = ""; } if(!preg_match("/^[A-Za-z' -]{1,50}$/",$_POST['last_name'])) { $error[] = "Please enter a valid Last Name"; } else { $error[] = ""; } if(is_array($error)) { foreach($error as $err_message) { echo $err_message . "<br />"; } } //exit(); } ?>
  10. Thanks for the tips. I am still working on this, but I was able to get this far with some results. I still have some mixed results though. What I don't understand is why preg_match seems to return TRUE if the results are met, and my errors are thrown then.. Does it seem like I am doing this efficiently? <?php if(isset($_POST['set_test'])) { if(preg_match('/[^A-Za-z]/',$_POST['first_name'])) { $error[] = "Please enter a valid First Name"; } else { $error[] = ""; } if(preg_match('/[^A-Za-z]/',$_POST['last_name'])) { $error[] = "Please enter a valid Last Name"; } else { $error[] = ""; } echo $error[0]; echo $error[1]; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> First Name:<br /> <input name="first_name" type="text" size="50" maxlength="50" /><br /><br /> Last Name:<br /> <input name="last_name" type="text" size="50" maxlength="50" /><br /><br /> <input name="set_test" type="hidden" value="" /> <input type="submit" /><br /><br /> </form>
  11. I realized I left out a bracket, but of course that solved nothing in relation to getting my error[] array to echo. Still hacking away at this trying variations... Any tips or advice is much appreciated.. Its as if the array is not holding the data.
  12. Yes. That's all of the code. Im not trying to do rocket science here. Just trying to figure out how to get an array echoing errors like I suggest.
  13. Been screwing around on Google for about 3 hours trying to find a tutorial on what I am trying to do with absolutely no luck! I am simply trying to get my test script to echo errors from an array when a form criteria does not validate. This is my final revision which is still not working! Can someone please tell me what I am doing wrong? No matter what I do, I can't get away from this error: Notice: Undefined variable: error in C:\wamp\www\php\form_validation.php on line 13 <?php $o = $error[]; // test echo $o; // test if(!preg_match('/[^0-9A-Za-z]/',$_POST['first_name'])) { $error[] = "Please enter a valid First Name"; ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> First Name:<br /> <input name="first_name" type="text" size="50" maxlength="50" /><br /><br /> <input type="submit" /><br /><br /> </form>
  14. So you want to print the results of the query data in the same order as the table holds the data? Can you clarify?
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.