Jump to content

Recommended Posts

Hi

 

I have a database which is connected via php to input mebers details. Despite my giving an example form to show how we prefer input, many entries are "all lowercase", "all uppercase", "mixed" etc. I know that in php you can format text using functions such as strtolower, upwords etc. My problem is how can I use these functions when referring to the contents of a field - whose content is of course specific to that individual record, but will likely be different in the next Member application.

 

I have a "joining" form in HTML and this then confirms their details on a .php file pre them submitting the record which then is inserted into the database. Here is an extract from the php file. You will see where I thought I could start "formatting" the entries pre insertion into the database

 

.........

<?php

   if (IsFieldEmpty("name"))                               // must provide forename
       ErrorRequires("Please enter your Forename(s)");
   if (IsFieldEmpty("surname"))                            // must provide surname
       ErrorRequires("Please enter your Surname");
   if (IsFieldEmpty("address"))                            // must provide address pre town
       ErrorRequires("Please enter your full address - pre your Town or Village");
   if (IsFieldEmpty("town"))                               // must provide town
       ErrorRequires("Please enter your Town");
   if (IsFieldEmpty("postcode"))                               // must provide post code
       ErrorRequires("Please enter your Post Code");	
   if (IsFieldEmpty("province"))                               // must provide province
       ErrorRequires("Please enter your Province or County if UK based");
   if (IsFieldEmpty("homephone"))                               // must provide homw phone
       ErrorRequires("Please enter your Home telephone number / if none type 1234");
   if (IsFieldEmpty("mobile"))                               // must provide mobile number
       ErrorRequires("enter your Mobile telephone number - if none type 1234");
   if (IsFieldEmpty("email"))                               // must provide mobile number
       ErrorRequires("Please enter a valid contact Email address");
   if (IsFieldEmpty("password"))                               // must provide secret password for security checks 
       ErrorRequires("Please enter your Secret password - minimum of 6 letters - maximum of 12");	

    // add any other "required fields" checks here

    //
    // Now check for specific abuse where the same value is inserted in
    // every field.
    // Note that the equality test is only valid for fields that are
    // required (as tested above).  For example, if two fields are tested
    // that can both be left blank, abuse will be falsely detected each time
    // these are both blank.
    
if ($_POST["name"] === $_POST["surname"])
    AbuseDetected("name and surname");
if ($_POST["name"] === $_POST["address"])
    AbuseDetected("name and address");
if ($_POST["surname"] === $_POST["address"])
    AbuseDetected("surname and address");
if ($_POST["address"] === $_POST["town"])
    AbuseDetected("address and town");
if ($_POST["name"] === $_POST["email"])
    AbuseDetected("name and email");
if ($_POST["province"] === $_POST["email"])
    AbuseDetected("province and email");
if ($_POST["surname"] === $_POST["email"])
    AbuseDetected("surname and email");

    //
    // End of abuse checking code
    //
/**************************************************/
//Formatting fields

function firstname([name]);
$firstname = [name]; 
$firstname = strtolower($firstname);
$firstname = ucfirst($firstname);
$firstname = [name]; 
return [name];

function lastname (surname);
$lastname = surname; 
$lastname = strtolower($lastname);
$lastname = ucfirst($lastname);
$lastname = surname; 
return surname;

function addressline (address);
$addressline = address; 
$addressline = strtolower($addressline);
$addressline = ucfirst($addressline);
$addressline = address; 
return address;


function townline (town);
$townline = town; 
$townline = strtolower($townline);
$townline = ucwords($townline);
$townline = town; 
return town; 

function postcodeline (postcode);
$postcodeline = postcode; 
$postcodeline = strtolower($postcodeline);
$postcodeline = ucwords($postcodeline);
$postcodeline = postcode; 
return postcode; 


//define variables
$dbc = mysql_connect("ukgovabuse.dns-systems.net","ukgovabuse_data","labour1");
$db = ukgovabuse_data;
$tbl = "tblMembers";
$date = date("j,m,Y");
$today = date("Y,m,d");

if (!$dbc) {
echo "<p>Sorry you are unable to connect to the database server at this time.</p>";
exit();
}
mysql_select_db(ukgovabuse_data,$dbc);

// All checks have been passed, insert user in membership database
$sql = "INSERT INTO tblMembers(ref, name, surname, address, town, postcode, province, homephone, mobile, email, password, assist, specialty, contact, recruit, subscribe, joined) 
VALUES('','$_POST[name]','$_POST[surname]','$_POST[address]', '$_POST[town]','$_POST[postcode]','$_POST[province]','$_POST[homephone]','$_POST[mobile]','$_POST[email]','$_POST[password]','$_POST[assist]','$_POST[specialty]','$_POST[contact]','$_POST[recruit]','$_POST[subscribe]','$today')";    

...........................................

 

You will be able to readily identify the field names e.g. name, surname, address, town etc

 

If anyone would be kind enough to offer some code to facilitate my desire, I would be very grateful.

 

Regards

 

Cheyanne

Link to comment
https://forums.phpfreaks.com/topic/52105-formatting-members-input/
Share on other sites

I agree with taith, I generally deal with the formatting in the display section.

 

But, to give you some help here...

 

<?php ucwords(strtolower($name)); ?> 

you can nest formatting functions like this. This takes the string to lower first, then it applies the ucwords to the string.

 

Your functions are not correct in their syntax.

 

<?php

$fname='BoB';
$lname='MaRKowiTZ';

function name($fn)
{
$firstname = ucfirst(strtolower($fn));
return $firstname;
}

echo name($fname).' ' .name($lname);

?>

 

This returns Bob Markowitz

 

Hope this helps.

 

Functions need to be in the format of

<?php

function function_name($var_to_pass) 
{
  // do function stuff inside here
}

?>

 

I do believe that a function has to have the {} brackets to enclose the code executed by the function.

 

Nate

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.