|
-
October 4th, 2008, 03:14 AM
#1
REGEX in PHP forms
I need a regex expression that verifies if a user inputs a valid name (letters and spaces only). However, it doesn't budge.
Code:
<?php
function validateInputs(){
$status_form = "OK"; $msg="";
$fname=$_GET['fname']; $lname=$_GET['lname'];
$number=$_GET['number']; $subdivision=$_GET['subdivision'];
$street=$_GET['street']; $districtcity=$_GET['districtcity'];
$phonenum=$_GET['phonenum']; $cellnum=$_GET['cellnum'];
if(!preg_match("/[^A-Za-z\s]/i", $lname)){
$status_form="NOTOK";
$msg .= "Name format is invalid. Use only alphabets and/or a dash<br>";
}
if($status_form!="OK"){
while (list ($key, $val) = each ($_POST)) $pd .= "$key=".urlencode($val)."&";
header ("Location: addentry.php?msg=$msg&$pd");
} else return true;
}
if (array_key_exists('add_submit', $_POST)) {
if (validateInputs()){
}
echo "New contact inserted. Details:<br />";
echo "<b>FIRST NAME:</b> {$_POST['fname']}<br />";
echo "<b>LAST NAME:</b> {$_POST['lname']}<br />";
echo "<b>ADDRESS:</b> $addressstring<br />";
echo "<b>MOBILE:</b> {$_POST['phonenum']}<br />";
echo "<b>PHONE:</b> {$_POST['cellnum']}";
} else echo "You can't see this page without submitting the form.";
?>
Last edited by Feebz; October 4th, 2008 at 03:19 AM.
-
October 4th, 2008, 08:12 AM
#2
Re: REGEX in PHP forms
It doesn't work because you haven't told it to do anything if a problem is found. Also you have mixed up $_GET and $_POST throughout your code.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
October 4th, 2008, 08:33 AM
#3
Re: REGEX in PHP forms
What specific problem? :|
-
October 4th, 2008, 05:48 PM
#4
Re: REGEX in PHP forms
First off, you are trying to validate it as boolean.
PHP Code:
if (validateInputs()) {
But, no where do you return false if there is a problem in the actual function.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
October 4th, 2008, 09:23 PM
#5
Re: REGEX in PHP forms
If it's false, it tries to send it back to the form with the error message attached. It also sends back the values that were filled in.
Code:
while (list ($key, $val) = each ($_POST)) $pd .= "$key=".urlencode($val)."&";
header ("Location: addentry.php?msg=$msg&$pd");
Do I still have to return false for this?
And... how do you make the PHP Codebox?
Last edited by Feebz; October 4th, 2008 at 09:41 PM.
Reason: Just aking how you do that
-
October 5th, 2008, 08:15 AM
#6
Re: REGEX in PHP forms
If the function is supposed to act boolean, as you have it, you must either return true or false.
You make the PHP tags the same way you use the code tags. At the bottom of this page on the left, you will find the "Posting Rules" box. In there, you will find a link to all available BBCode possibilities.
[php]You're PHP code here[/php]
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|