473,385 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Input form

TJ
Dear PHP group,

First question:

I have an input form that upon pressing a button validates the values
entered into this form. I am using the following code recall this form if
there is an error in one of the requested fields:

<form name="form1" method="post" action= "InputForm.php" >

All works fine. However, if there is an error and this form is recalled, all
the fields are blanked out when you are brought back to the form. I'd like
for the form to retain the values that had been entered. How do I do this?

Second question:

For the fields that are in error, I'd like for the titles for the fields to
display an asterisk and change the text to red. Have any of you done this
and if so how do you implement it?

Thanks,
Jul 17 '05 #1
4 3529
TJ wrote:
I'd like
for the form to retain the values that had been entered. How do I do this?
You need to put the values that where transmitted by the form into the
"value" of the inputs like this:

<input type="text" name="firstname" value="<?php echo
$_POST['firstname'];?>" />
For the fields that are in error, I'd like for the titles for the fields to
display an asterisk and change the text to red. Have any of you done this
and if so how do you implement it?


<?php if (valid($_POST['firstname'], 'name')): ?>
<font color="#ff0000">*&nbsp;
<?php else: ?>
<font>
<?php endif; ?>
Firstname:
</font>

Somewhere you define a function:
<?php
function valid($value, $type){
if(type=='name'){
// return true if this is a valid name, false otherwise
}
}
?>

Of course, this is VERY simplistic....

Jochen

Jul 17 '05 #2
I noticed that Message-ID: <RRoGb.10873$JD6.5055@lakeread04> from TJ
contained the following:
Dear PHP group,

First question:

I have an input form that upon pressing a button validates the values
entered into this form. I am using the following code recall this form if
there is an error in one of the requested fields:

<form name="form1" method="post" action= "InputForm.php" >

All works fine. However, if there is an error and this form is recalled, all
the fields are blanked out when you are brought back to the form. I'd like
for the form to retain the values that had been entered. How do I do this?

Second question:

For the fields that are in error, I'd like for the titles for the fields to
display an asterisk and change the text to red. Have any of you done this
and if so how do you implement it?

Check this out - it simply checks if the field has been entered or not.
If the form is resubmitted it repopulates the textfields with the $_POST
variables.

<html>
<head>
<title>Check fields</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
..red { color: #FF0000}
-->
</style>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<?php
function error($field){
if (!$field && $_POST["Submit"]){
print"<p class=\"red\">* ";
}
else{
print"<p>";
}
}
?>
<form name="form1" method="post" action="">
<?php
error($_POST["textfield"]);
?>
First name <input type="text" name="textfield" value="<?php print
$_POST["textfield"];?>">
</p>
<?php
error($_POST["textfield2"]);
?>
Last name <input type="text" name="textfield2"value="<?php print
$_POST["textfield2"];?>"></p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
TJ
Thanks -- I'll review your solution.

"Jochen Buennagel" <za*********@buennagel.com> wrote in message
news:bs*************@news.t-online.com...
TJ wrote:
I'd like
for the form to retain the values that had been entered. How do I do this?

You need to put the values that where transmitted by the form into the
"value" of the inputs like this:

<input type="text" name="firstname" value="<?php echo
$_POST['firstname'];?>" />
For the fields that are in error, I'd like for the titles for the fields

to display an asterisk and change the text to red. Have any of you done this and if so how do you implement it?


<?php if (valid($_POST['firstname'], 'name')): ?>
<font color="#ff0000">*&nbsp;
<?php else: ?>
<font>
<?php endif; ?>
Firstname:
</font>

Somewhere you define a function:
<?php
function valid($value, $type){
if(type=='name'){
// return true if this is a valid name, false otherwise
}
}
?>

Of course, this is VERY simplistic....

Jochen

Jul 17 '05 #4
TJ
Thanks, I'll review this.

"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:gv********************************@4ax.com...
I noticed that Message-ID: <RRoGb.10873$JD6.5055@lakeread04> from TJ
contained the following:
Dear PHP group,

First question:

I have an input form that upon pressing a button validates the values
entered into this form. I am using the following code recall this form if
there is an error in one of the requested fields:

<form name="form1" method="post" action= "InputForm.php" >

All works fine. However, if there is an error and this form is recalled, allthe fields are blanked out when you are brought back to the form. I'd likefor the form to retain the values that had been entered. How do I do this?
Second question:

For the fields that are in error, I'd like for the titles for the fields todisplay an asterisk and change the text to red. Have any of you done this
and if so how do you implement it?

Check this out - it simply checks if the field has been entered or not.
If the form is resubmitted it repopulates the textfields with the $_POST
variables.

<html>
<head>
<title>Check fields</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.red { color: #FF0000}
-->
</style>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<?php
function error($field){
if (!$field && $_POST["Submit"]){
print"<p class=\"red\">* ";
}
else{
print"<p>";
}
}
?>
<form name="form1" method="post" action="">
<?php
error($_POST["textfield"]);
?>
First name <input type="text" name="textfield" value="<?php print
$_POST["textfield"];?>">
</p>
<?php
error($_POST["textfield2"]);
?>
Last name <input type="text" name="textfield2"value="<?php print
$_POST["textfield2"];?>"></p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: david | last post by:
HI! Im trying to make "HTML form" into automatic. 1. If I get 18 numbers like: A B C D E F . . . . 2. How can I put those 18 numbers automatically into 6 numbers format like: A B C D E F
3
by: Ben | last post by:
Here's my form: <form name="aForm" method='post'> <input type=file name=file1 onkeypress='KeyPress()'><br> <a id='attachMoreLink' href='javascript:AddFileInput()">Attach More Files </a> <input...
12
by: Randell D. | last post by:
Folks, I have a form called "ourTestForm". Its a test form - nothing special - it contains five input tags - they are named one, two, three, four and five. The input tags are of type...
6
by: Dennis Allen | last post by:
Hi. I got a checkbox in a form. When the form is submitted, an email is generated. In the email text is the field name: on or off. The client doesn't want to see on or off, but yes or no. ...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
1
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
2
by: Abneo | last post by:
Hi all, I am very new to Javascript and I am in some need of some help. I am creating a site that has a madlib. I got the madlib code but now I want the results of the madlib to display in...
1
by: tcertain | last post by:
I am totally duh at javascript although I have 2 books trying to learn it. I am trying to add values to a form and have a calculate total at end. this is my form script. I have hours at end of...
2
by: poreko | last post by:
I am trying to validate the inputs of a form using javascript. The validation is working but the form is not been submitted after the inputs have been checked. I have been unable to find any error....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.