Return/ ECho acutall Form Field NAme
Moderator: General Moderators
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
Return/ ECho acutall Form Field NAme
Hi,
I have a Validation function that validates a form field and if flase calls error function
the error function needs to take the Field Name as a paremeter to echo that "this" field is and Error (determined byt the field)
how do i print an acutal field name
any suggestion on how to better design this error function for the above purpose
here is the code
function ErrorGenerate($Field,$Error)
{
$file = "register.php";
include($file);
$Replacement = "<!--".$Field." Error-->";
return $Replacement;
return $Error;
}
havent quite figured it out yet
I have a Validation function that validates a form field and if flase calls error function
the error function needs to take the Field Name as a paremeter to echo that "this" field is and Error (determined byt the field)
how do i print an acutal field name
any suggestion on how to better design this error function for the above purpose
here is the code
function ErrorGenerate($Field,$Error)
{
$file = "register.php";
include($file);
$Replacement = "<!--".$Field." Error-->";
return $Replacement;
return $Error;
}
havent quite figured it out yet
- ~J~R~R
- Forum Newbie
- Posts: 20
- Joined: Wed Sep 18, 2002 12:19 pm
- Location: Amsterdam, the Netherlanda
In every case it isn't $Error isn't returned, because the function stops when you call return(). See http://www.php.net/manual/en/function.return.php for more info.
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
hi,
You can have some fixed pattern which will get replaced by the actual field name.
You can try this:
And call it like:
See php man:
http://www.php.net/manual/en/function.str-replace.php
You can have some fixed pattern which will get replaced by the actual field name.
You can try this:
Code: Select all
<?php
function ErrorGenerate($Field,$Error)
{
$file = "register.php";
include($file);
// ***
$Error = str_replace( "(-FIELD-)", $Field, $Error );
// ***
return $Error;
}
?>Code: Select all
<?php
ErrorGenerate( "Email Id", "Pls enter proper (-FIELD-) else you will not get emails !" );
?>See php man:
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
Returning VAlues
Well i have used it and it works the problem was that i need to get the acutal form field name to cross in order to get the right error
thus if i got the form field name EMail it will also return the corresponding error
But for advice what woud u have done?
thus if i got the form field name EMail it will also return the corresponding error
But for advice what woud u have done?
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
Echo Field Name Variables
Exactly what i did...well sort of
See the include file has some if statements at intervals in a html template
i used comments like <!---Name Error-->
so if the field was name
i used a string manipulation and then have the comment replaced by the Error in the included file
its a bit untidy though but it works !!
trying to neaten it up
See the include file has some if statements at intervals in a html template
i used comments like <!---Name Error-->
so if the field was name
i used a string manipulation and then have the comment replaced by the Error in the included file
its a bit untidy though but it works !!
trying to neaten it up
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
hi,
if u r problem is -- the field is NOT getting displayed in the browser, then
remove the html comment from the $Replacement:
Old:
New:
In the code provided by me, the error message is formatted more properly. Ok if u r error messages are of fixed format you can remove the str_replace() with use of concatenation (.) operator also, like:
$Error = $Field . " $Error";
I think u missed the '$' in the code provided by u, so i provided the code.
u wrote => $Replacement = "<!--".$Field." Error-->";
u might wanted to write => $Replacement = "<!--".$Field." $Error-->";
if u r problem is -- the field is NOT getting displayed in the browser, then
remove the html comment from the $Replacement:
Old:
Code: Select all
<?php
$Replacement = "<!--".$Field." Error-->";
?>New:
Code: Select all
<?php
$Replacement = $Field." Error";
?>In the code provided by me, the error message is formatted more properly. Ok if u r error messages are of fixed format you can remove the str_replace() with use of concatenation (.) operator also, like:
$Error = $Field . " $Error";
I think u missed the '$' in the code provided by u, so i provided the code.
u wrote => $Replacement = "<!--".$Field." Error-->";
u might wanted to write => $Replacement = "<!--".$Field." $Error-->";
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
Oops (Field Name)
Sorry,
what i meant to do was pass the field name in the Parameter
the comments are what is going to be replaced. so i had the comments syntax like <!-- FormFieldName Error-->.
Thus if we validating the email field
then
ErrorGenerate($Field,$error)
$Replace = "<!--".$Field."-->";
there fore int he included file we where the if statement said
if ($replacement == "<!--$Field Error-->")
echo $Error;
what i meant to do was pass the field name in the Parameter
the comments are what is going to be replaced. so i had the comments syntax like <!-- FormFieldName Error-->.
Thus if we validating the email field
then
ErrorGenerate($Field,$error)
$Replace = "<!--".$Field."-->";
there fore int he included file we where the if statement said
if ($replacement == "<!--$Field Error-->")
echo $Error;
Ok...
Will this work?
Will this work?
Code: Select all
<?php
foreach($_POST as $key => $value) {
echo "Key: $key, Value: $value";
}
function ErrorGenerate($field,$error) {
$string = "<!-- $field -->";
$fh = fopen($file,"r");
$content = fread($fh, filesize($file));
$content = str_replace($string, $error, $content);
return($content);
}
?>- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
get the
i have the following code that checkas for a empty field
---code----
CheckFields($requiredFields);
function CheckFields($requiredFields)
{
foreach ($requiredFields as $FieldName => $Value)
{
if ($Value == "")
{
$inValidFields = $FieldName;
}
}
}
---end-------
i want to pass it back into and array
who do i do dat?
Kendall
---code----
CheckFields($requiredFields);
function CheckFields($requiredFields)
{
foreach ($requiredFields as $FieldName => $Value)
{
if ($Value == "")
{
$inValidFields = $FieldName;
}
}
}
---end-------
i want to pass it back into and array
who do i do dat?
Kendall