Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Form processing questions
Old 02-04-2006, 07:55 AM Form processing questions
Average Talker

Posts: 20
Trades: 0
hello people,

Im new here - Hello!!!

I have a HTML form that passes data (post) to a PHP script. Now, at the moment the script checks to see if all fields are filled out, or whether the email address is valid and whether the image verification is valid. The problem is that when the error message is displayed there is a javascript:history back button that the user clicks to take them back. Once they go back all the data they originally posted has disappeared. This is very annoying. How do i make the form 'remember' the information already posted. Someone alreadt mentioned that i can post the values to the apge itself - but i never really understood where they were coming from.

The only way i can think of getting around this is by making the PHP script display the correct/valid information submitted, and if there are any errors it highlights this and allows the user to correct the problems using another form field and re-submit the information.
can anyone guide me of what i need to do here?

regards Jonathan
jpmad4it is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-04-2006, 08:01 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
With forms I usually create them all on one page (error handling, processing and the form itself.)
The first thing the page does is check if the form has been submitted. If not, it echoes the form and stops.
If it has then it checks the data. If it's OK, then it processes the form in whatever way is needed. If it's not OK, then PHP will echo out the form, possibly with an error message and a highlight, and fill in the fields with the old data values so the user can edit them.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 02-04-2006, 08:44 AM
Average Talker

Posts: 20
Trades: 0
yeah i know i just realised this.

Im working on it now but im not getting very far :-(

how much do you want for your code

here is what i have already, but the three red error stars *** are being shown immediately.

PHP Code:
 
<? 
if(isset($_POST['submit'])){ 
$field1 $_POST['title']; 
$field2 $_POST['forename']; 
$field3 $_POST['surname']; 
$field4 $_POST['dob']; 
$field5 $_POST['gender']; 
$field6 $_POST['employment']; 
$field7 $_POST['drivingLicence']; 
$field8 $_POST['houseenumber']; 
$field9 $_POST['street']; 
$field10 $_POST['town']; 
$field11 $_POST['county']; 
$field12 $_POST['postcode']; 
$field13 $_POST['telephone']; 
$field14 $_POST['email']; 
$field15 $_POST['facilityRequired']; 
 
} else { 
$field1 ''
$field2 ''
$field3 ''
$field4 ''
$field5 ''
$field6 ''
$field7 ''
$field8 ''
$field9 ''
$field10 ''
$field11 ''
$field12 ''
$field13 ''
$field14 ''
$field15 ''

?>
<form method="post" action="">
<table width="87%" height="407" border="0" align="center" cellpadding="0" cellspacing="0">
<tr class="text">
<td height="24"><p><strong>ABOUT YOU:</strong></p></td>
<td></td>
</tr>
<tr class="text">
<td height="24"><p>Title</p></td>
<td><select name="title" value="<? echo $field1?>">
<option value="Mr">Mr
<option value="Mrs">Mrs
<option value="Ms">Ms
<option value="Dr">Dr
</select></td>
</tr>
<tr class="text">
<td height="22"><p>Forename(s):</p></td>
<td><input type="text" name="forename" value="<? echo $field2?>"></td>
<td>
<?php
if ($_POST['forename'] == ''){
echo 
"<font color='red'> *** </font>";
}
?>
</td>
</tr>
<tr class="text">
<td height="13"><p>Surname:</p></td>
<td><input type="text" name="surname" size="30" value="<? echo $field3?>"></td>
<td>
<?php
if ($_POST['surname'] == ''){
echo 
"<font color='red'> *** </font>";
}
?>
</td>
</tr>
<tr class="text">
<td height="13"><p>Date of birth (DD/MM/YYYY): </p></td>
<td><input type="text" name="dob" size="30" value="<? echo $field4?>"></td>
<td>
<?php
if ($_POST['dob'] == ''){
echo 
"<font color='red'> *** </font>";
}
?>
</td>
</tr>
<tr class="text">
<td height="13"><p>Gender:</p></td>
<td><select name="gender" value="<? echo $field5?>">
<option value="Male">Male
<option value="Female">Female
</select></td>
</tr>
<tr class="text">
<td height="13"><p>Type of Employment:</p></td>
<td><select name="employment" value="<? echo $field6?>">
<option value"Full-time">Working Full-time
<option value="Part-time">Working Part-time
<option value="Self-employed">Self-employed
<option value="Retired">Retired
<option value="Disability Benefit">Disability Benefits
</select></td>
</tr>
<tr class="text">
<td height="13"><p>Full UK Driving Licence:</p></td>
<td><select name="drivingLicence" value="<? echo $field7?>">
<option vlaue="Yes">Yes
<option value="No">No
</select></td>
</tr>
<tr class="text">
<td height="24"><p><strong>YOUR CONTACT INFORMATION:</strong></p></td>
<td>&nbsp;</td>
</tr>
<tr class="text">
<td height="13"><p>House/Number:</p></td>
<td><input type="text" name="houseNumber" size="30" value="<? echo $field8?>"></td>
<td>
<?php
if ($_POST['houseNumber'] == ''){
echo 
"<font color='red'> *** </font>";
}
?>
</td>
</tr>
<tr class="text">
<td height="13"><p>Street:</p></td>
<td><input type="text" name="street" size="30" value="<? echo $field9?>"></td>
<td>
<?php
if ($_POST['street'] == ''){
echo 
"<font color='red'> *** </font>";
}
?>
</td>
</tr>
<tr class="text">
<td height="13"><p>Town/City:</p></td>
<td><input type="text" name="town" size="30" value="<? echo $field10?>"></td>
<td>
<?php
if ($_POST['town'] == ''){
echo 
"<font color='red'> *** </font>";
}
?>
</td>
</tr>
<tr class="text">
<td height="13"><p>County:</p></td>
<td><input type="text" name="county" size="30" value="<? echo $field11?>"></td>
<td>
<?php
if ($_POST['county'] == ''){
echo 
"<font color='red'> *** </font>";
}
?>
</td>
</tr>
<tr class="text">
<td height="13"><p>Postcode:</p></td>
<td><input type="text" name="postcode" size="30" value="<? echo $field12?>"></td>
<td>
<?php
if ($_POST['postcode'] == ''){
echo 
"<font color='red'> *** </font>";
}
?>
</td>
</tr>
<tr class="text">
<td height="13"><p>Telephone Number:</p></td>
<td><input type="text" name="telephone" size="30" value="<? echo $field13?>"></td>
<td>
<?php
if ($_POST['telephone'] == ''){
echo 
"<font color='red'> *** </font>";
}
?>
</td>
</tr>
<tr class="text">
<td height="13"><p>Email Address:</p></td>
<td><input type="text" name="email" size="30" value="<? echo $field14?>"></td>
<td>
<?php
//lowercase email
$email strtolower($email);
 
if (!
valid_email($email))
{
echo 
"You have entered an invalid email address";
 

 
?> 
</td>
</tr>
<tr class="text">
<td height="23"><p><strong>WHAT YOU WANT FROM US: </strong></p></td>
<td>&nbsp;</td>
</tr>
<tr class="text">
<td height="13"><p>Facility Required:</p></td>
<td><select name="facilityRequired" value="<? echo $field15?>">
<option value="Hire Purchase">Hire Purchase
<option "Lease">Lease
<option "Contract Hire">Contract Hire
<option "Secured loan">Secured loan
<option "Personal loan">Personal loan
<option "Refinancing">Refinancing
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td class="text"><strong>IMAGE VERIFICATION: </strong></td>
</tr>
<tr>
<td valign=top><span class="text">Your Code Is:</span><br>
<br>
<?=printBotBlock("********""*******")?></td>
<td valign=top><span class="text"><b>Please type your code here:</b></span><br>
<br>
<input name="bb_codeword" size=40 maxlength=40 value="">
<br>
<span class="text">Please note that the letters are case sensitive. </span><br>
<font color=blue class="text">If the text is unclear, click on the image.</font></td>
<td>
<?php 
if (!validBotBlock())
{
echo 
"The image verification was incorrect"
}
?>
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr class="text">
<td>&nbsp;</td>
<td><input type="submit" value="Submit" name="submit">
&nbsp;&nbsp;
<input type="reset" value="Clear fields"></td>
</tr>
</table>
</form>
I need something that does the following:

on submit, if the entry is invalid then display an error message or the three stars ***, otherwise the data is valid so enter it into the database.

how can i do this? anyone got any ideas?

Last edited by jpmad4it; 02-04-2006 at 09:36 AM..
jpmad4it is offline
Reply With Quote
View Public Profile
 
Old 02-04-2006, 11:21 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
How about changing the checks on the data from this:
PHP Code:
if ($_POST['surname'] == ''){ 
into thios:

PHP Code:
if ($_POST['surname'] == '' && isset($_POST['submit'])){ 
That way it won't check the data the first time the page loads (when there is no data), than when the form is submitted it runs the checks.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 02-04-2006, 11:36 AM
Average Talker

Posts: 20
Trades: 0
thanks i will have a try with that and report back - thank you
jpmad4it is offline
Reply With Quote
View Public Profile
 
Old 02-05-2006, 12:59 PM Re: Form processing questions
Average Talker

Posts: 20
Trades: 0
hey again. I got most of the form sorted out, but the code above doesnt solve the problem i have.

At the moment the page is still checking if the data is valid when the page loads for the very first time. My code is:

PHP Code:
if ($_POST['forname'] == ' ' && isset($_POST['submit'])){   
echo 
"<font color='red'> *** </font>"
}  
 
//where the 3 *** highlight there is an error 
The 3 error stars are being displayed on the very first load of the page, but i dont want that. I only want them to appear when the page is submitted and contains errors.
jpmad4it is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Form processing questions
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.38878 seconds with 12 queries