Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
| Search | Today's Posts | Mark Forums Read
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 27th, 2004, 02:02 PM
Registered User
Join Date: Dec 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Truncated Form Values.

Subject: Your basic PHP shopping cart system with back-end mailer.

Does it work?: Yes, if all client fields are filled correctly and simultaneously.

What's my problem?:

One, the form validates/submits on page load. Validation is conditional on:

if(isset($_REQUEST["submit"])) {
//validation, blah blah blah
"submit" is the name of the input type, which is also "submit". I've tried this with "$_POST" as well, and using various permutations of PHP like:

if($_POST['submit'] == 1)
And so forth.

This is ignored and the validation code is parsed. Validation errors pop on page load, etc. Simple enough.

Two: Not so simple. If entry is valid, the form should echo the value on the form line and store it in a PHP-echo'd hidden input just below (if invalid, display text field and error message). It does. However, if this value is separated by a whitespace, then it doesn't validate AGAIN once the person hits Submit after correcting other errors. I think this is a problem with my regular expressions, since all single-word values without whitespace are parsed and stored correctly on the page until the form is complete and valid.

Regex Examples:
$namepattern = '/^\b[A-Za-z]+\b\s\b[A-Za-z\-]+\b$/';
$titlepattern = '/^(Local\sBody\sMaster|Body\sMaster|Deputy\sBody\sMaster|Deputy\sMaster|Secretary|Initiation\sSecretary|Treasurer|LBM|DBM])$/';
Display Code:
                    if ($valid[1] == 0) {
                        if ($message[1] != "") {
                        echo "<span class=\"error\">" . $message[1] . "<//span><br>\n"; }
                        echo "<input type=\"text\" width=\"200\" name=\"name\" value=" . $_POST["name"] . ">"; }
                    elseif ($valid[7] == 1) { 
                    echo $_POST["name"];
                    echo "<input type=\"hidden\" name=\"name\" value=" . $_POST["name"] . ">"; } ?>
$message is an empty array with null values for each field.
$valid is filled with zero values for each field.

Validation Code:
if (preg_match($namepattern, $_POST["name"]) > 0) {
    $message[0] = 0;
    $valid[0] = 1;
    } else {
    $valid[0] = 0;
    $message[0] = "Please enter your full name.";
    $class = "error"; }
Problem Example:

Person enters their name and hits Submit. Name is accepted and displayed. Person fills the rest of the form correctly and hits Submit. Form returns error and Name with last name and separating whitespace chopped. Person fixes Name and Submits. Form returns errors with the first words of every other string in place of the actual, already-validated string, but Name is valid. Rinse, wash, repeat, with any combination.

Of course, if it's filled right the first time then everything works great. If anything is a single-value, the variable is stored and displayed properly. I have a feeling that the two problems are ultimately related to each other.

Is there a difference between the data as entered by the user and the data as displayed by 'echo $_POST["name"];'? Do I need to use a preg_replace somewhere?

A related question:

Explain the difference in using "=", "==", and "===" here, especially in relation to the validation trigger. I've managed to confuse myself nicely between all this.

ANY assistance would be appreciated. Heavy emphasis on the ANY.

  #2 (permalink)  
Old December 27th, 2004, 02:53 PM
Registered User
Join Date: Dec 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Noted the lack of an additional escaped quote on the hidden inputs, which should solve the loss of data.

Automatic form submittal continues to be a problem.

Similar Threads
Thread Thread Starter Forum Replies Last Post
get the values of form field values crmpicco Perl 2 March 16th, 2007 10:57 AM
Truncated field when copying Tachyophan Access VBA 3 November 16th, 2006 08:23 AM
Querying against truncated dates John Pennington SQL Server 2000 3 October 16th, 2006 11:55 PM
Long Name truncated with SendMail echovue Excel VBA 0 May 12th, 2005 03:05 PM
need to be truncated PatrickH SQL Server ASP 2 April 15th, 2004 10:48 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.