validation close but no cigar

  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

is it possible to send information from a htm file to a php file even tho the php file actions itself?

i have 2 files.
send.htm
getstarted.php

i want to pass values from send.htm to getstarted.php without the getstartedform.php being submitted. the only thing is that when getstarted.php is filled out, it then performs the action on itself because all the database info and check are in the same file.

anyway round this at all?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i have this javascript validation working a few days ago. now, it is only part working. one if statement does a check on fields entered like name, email address, postcode etc. the other if statement deals with radio buttons. now the radio button script doesnt work at all. does anyone know how that can be?
Code: [ Select ]
if (mainform.contactpostcode.value=='')
        {
        alert('Your contact postcode is a required field. Please try again.');
        event.returnValue=false;
        }
    if (!(mainform.doyouneed[0].checked || mainform.doyouneed[1].checked || mainform.doyouneed[2].checked || mainform.doyouneed[3].checked))
        {
        alert('Your need is a required field. Please try again.');
        event.returnValue=false;
        }
  1. if (mainform.contactpostcode.value=='')
  2.         {
  3.         alert('Your contact postcode is a required field. Please try again.');
  4.         event.returnValue=false;
  5.         }
  6.     if (!(mainform.doyouneed[0].checked || mainform.doyouneed[1].checked || mainform.doyouneed[2].checked || mainform.doyouneed[3].checked))
  7.         {
  8.         alert('Your need is a required field. Please try again.');
  9.         event.returnValue=false;
  10.         }
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

this is the whole javascript code

Code: [ Select ]
<SCRIPT>
function validate() {
    if (mainform.name.value=='')
        {
        alert('Your name is a required field. Please try again.');
        event.returnValue=false;
        }
    if (mainform.email.value=='')
        {
        alert('Your email is a required field. Please try again.');
        event.returnValue=false;
        }
    if (mainform.contactaddress.value=='')
        {
        alert('Your contact address is a required field. Please try again.');
        event.returnValue=false;
        }
    if (mainform.workhometel.value=='')
        {
        alert('Your work / home telephone number is a required field. Please try again.');
        event.returnValue=false;
        }
    if (mainform.contactpostcode.value=='')
        {
        alert('Your contact postcode is a required field. Please try again.');
        event.returnValue=false;
        }
    if (!(mainform.doyouneed[0].checked || mainform.doyouneed[1].checked || mainform.doyouneed[2].checked || mainform.doyouneed[3].checked))
        {
        alert('Your need is a required field. Please try again.');
        event.returnValue=false;
        }
    if (!(mainform.designstyle[0].checked || mainform.designstyle[1].checked || mainform.designstyle[2].checked || mainform.designstyle[3].checked))
        {
        alert('Your design style is a required field. Please try again.');
        event.returnValue=false;
        }
    if (!(mainform.project[0].checked || mainform.project[1].checked || mainform.project[2].checked || mainform.project[3].checked))
        {
        alert('Your project is a required field. Please try again.');
        event.returnValue=false;
        }
    if (!(mainform.uses[0].checked || mainform.uses[1].checked || mainform.uses[2].checked || mainform.uses[3].checked))
        {
        alert('Your uses is a required field. Please try again.');
        event.returnValue=false;
        }
    if (!(mainform.programtimecompletion[0].checked || mainform.programtimecompletion[1].checked || mainform.programtimecompletion[2].checked || mainform.programtimecompletion[3].checked))
        {
        alert('Your program time completion is a required field. Please try again.');
        event.returnValue=false;
        }
    if (!(mainform.budgetcost[0].checked || mainform.budgetcost[1].checked || mainform.budgetcost[2].checked || mainform.budgetcost[3].checked))
        {
        alert('Your budget cost is a required field. Please try again.');
        event.returnValue=false;
        }
    if (!(mainform.projectdeadline[0].checked || mainform.projectdeadline[1].checked || mainform.projectdeadline[2].checked || mainform.projectdeadline[3].checked))
        {
        alert('Your project deadline is a required field. Please try again.');
        event.returnValue=false;
        }
    if (!(mainform.whybuild[0].checked || mainform.whybuild[1].checked || mainform.whybuild[2].checked || mainform.whybuild[3].checked))
        {
        alert('Your reason to build is a required field. Please try again.');
        event.returnValue=false;
        }
}
</SCRIPT>

<form method="POST" name="mainform" action="getstartedform.php" onsubmit="validate();">
  1. <SCRIPT>
  2. function validate() {
  3.     if (mainform.name.value=='')
  4.         {
  5.         alert('Your name is a required field. Please try again.');
  6.         event.returnValue=false;
  7.         }
  8.     if (mainform.email.value=='')
  9.         {
  10.         alert('Your email is a required field. Please try again.');
  11.         event.returnValue=false;
  12.         }
  13.     if (mainform.contactaddress.value=='')
  14.         {
  15.         alert('Your contact address is a required field. Please try again.');
  16.         event.returnValue=false;
  17.         }
  18.     if (mainform.workhometel.value=='')
  19.         {
  20.         alert('Your work / home telephone number is a required field. Please try again.');
  21.         event.returnValue=false;
  22.         }
  23.     if (mainform.contactpostcode.value=='')
  24.         {
  25.         alert('Your contact postcode is a required field. Please try again.');
  26.         event.returnValue=false;
  27.         }
  28.     if (!(mainform.doyouneed[0].checked || mainform.doyouneed[1].checked || mainform.doyouneed[2].checked || mainform.doyouneed[3].checked))
  29.         {
  30.         alert('Your need is a required field. Please try again.');
  31.         event.returnValue=false;
  32.         }
  33.     if (!(mainform.designstyle[0].checked || mainform.designstyle[1].checked || mainform.designstyle[2].checked || mainform.designstyle[3].checked))
  34.         {
  35.         alert('Your design style is a required field. Please try again.');
  36.         event.returnValue=false;
  37.         }
  38.     if (!(mainform.project[0].checked || mainform.project[1].checked || mainform.project[2].checked || mainform.project[3].checked))
  39.         {
  40.         alert('Your project is a required field. Please try again.');
  41.         event.returnValue=false;
  42.         }
  43.     if (!(mainform.uses[0].checked || mainform.uses[1].checked || mainform.uses[2].checked || mainform.uses[3].checked))
  44.         {
  45.         alert('Your uses is a required field. Please try again.');
  46.         event.returnValue=false;
  47.         }
  48.     if (!(mainform.programtimecompletion[0].checked || mainform.programtimecompletion[1].checked || mainform.programtimecompletion[2].checked || mainform.programtimecompletion[3].checked))
  49.         {
  50.         alert('Your program time completion is a required field. Please try again.');
  51.         event.returnValue=false;
  52.         }
  53.     if (!(mainform.budgetcost[0].checked || mainform.budgetcost[1].checked || mainform.budgetcost[2].checked || mainform.budgetcost[3].checked))
  54.         {
  55.         alert('Your budget cost is a required field. Please try again.');
  56.         event.returnValue=false;
  57.         }
  58.     if (!(mainform.projectdeadline[0].checked || mainform.projectdeadline[1].checked || mainform.projectdeadline[2].checked || mainform.projectdeadline[3].checked))
  59.         {
  60.         alert('Your project deadline is a required field. Please try again.');
  61.         event.returnValue=false;
  62.         }
  63.     if (!(mainform.whybuild[0].checked || mainform.whybuild[1].checked || mainform.whybuild[2].checked || mainform.whybuild[3].checked))
  64.         {
  65.         alert('Your reason to build is a required field. Please try again.');
  66.         event.returnValue=false;
  67.         }
  68. }
  69. </SCRIPT>
  70. <form method="POST" name="mainform" action="getstartedform.php" onsubmit="validate();">


now it doesnt work at all. well the radio button code doesnt work at all

can someone test it and let me know what is going on?
  • Banjer
  • Novice
  • Novice
  • Banjer
  • Posts: 21

Post 3+ Months Ago

Nevermind i didn't read it very well..
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

show code please.
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

the code is pretty self explanitory. i can see that the getstartedform performs its own action and therefore the send.htm will act in a similar way. here is the send.htm code:
Code: [ Select ]
<body>
<form name="form1" id="form1" method="post" action="getstartedform.php">
 <table width="410" border="0">
  <tr>
   <td width="139">name</td>
   <td width="261"><input type="text" name="name" /></td>
  </tr>
  <tr>
   <td>email</td>
   <td><input type="text" name="email" /></td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td><input type="submit" name="submit" value="submit" /></td>
  </tr>
 </table>
</form>
</body>
  1. <body>
  2. <form name="form1" id="form1" method="post" action="getstartedform.php">
  3.  <table width="410" border="0">
  4.   <tr>
  5.    <td width="139">name</td>
  6.    <td width="261"><input type="text" name="name" /></td>
  7.   </tr>
  8.   <tr>
  9.    <td>email</td>
  10.    <td><input type="text" name="email" /></td>
  11.   </tr>
  12.   <tr>
  13.    <td>&nbsp;</td>
  14.    <td><input type="submit" name="submit" value="submit" /></td>
  15.   </tr>
  16.  </table>
  17. </form>
  18. </body>


now here is the coding part of the getstartedform.php

Code: [ Select ]
<?php

//extract($_REQUEST);

if ($_POST['submit'])
{
$user="";
$host="";
$password="";
$database="";
$connection=mysql_connect($host,$user,$password) or die ("could not connect to server");
$db=mysql_select_db($database,$connection);
$sql = "insert into gstrialforma(my_date, name, email, contactaddress, mobile, workhometel, contactpostcode, projectpostcode, doyouneed, designstyle, project, uses, engineer, partywall, architect, projectmanager, design, lifestyle, structural, planning, buildingregs, otherhelp, wheelchair, partialeyesight, terraced, familychildern, semidetached, aged, allergy, detached, other, otherneeds, specifyneeds, programtimecompletion, budgetcost, projectdeadline, whybuild, otherpreferences) values ('{$_POST['my_date']}','{$_POST['name']}','{$_POST['email']}','{$_POST['contactaddress']}','{$_POST['mobile']}','{$_POST['workhometel']}','{$_POST['contactpostcode']}','{$_POST['projectpostcode']}','{$_POST['doyouneed']}','{$_POST['designstyle']}','{$_POST['project']}','{$_POST['uses']}','{$_POST['engineer']}','{$_POST['partywall']}','{$_POST['architect']}','{$_POST['projectmanager']}','{$_POST['design']}','{$_POST['lifestyle']}','{$_POST['structural']}','{$_POST['planning']}','{$_POST['buildingregs']}','{$_POST['otherhelp']}','{$_POST['wheelchair']}','{$_POST['partialeyesight']}','{$_POST['terraced']}','{$_POST['familychildern']}','{$_POST['semidetached']}','{$_POST['aged']}','{$_POST['allergy']}','{$_POST['detached']}','{$_POST['other']}','{$_POST['otherneeds']}','{$_POST['specifyneeds']}','{$_POST['programtimecompletion']}','{$_POST['budgetcost']}','{$_POST['projectdeadline']}','{$_POST['whybuild']}','{$_POST['otherpreferences']}')";
$result = mysql_query($sql) or print(mysql_error());
//mail($to, $subject, $msg, $additional_headers);
mail($_POST['email'],'Building Doctors','Hello '.$_POST['name'].', thank you for your enquirey on '.$_POST['my_date'].'. We will be following up your request shortly. You have said that: Your preferred Design Style is '.$_POST['designstyle'].'. Your approximate Construction Budget is £'.$_POST['budgetcost'].'. Please review the useful links about Profesional and our Duty of care policy located at the bottom right of the site. In the meantime wait for our call. Regards, Building Doctor', "From: athompson@building-doctors.com");
echo "<table border=1 cellpadding=2 cellspacing=2 class=biggertext><tr><td>";
echo "</tr></td><tr><td><img src=images/cr_header.gif></tr></td><tr><td>";
echo 'Hello '.$_POST['name'].', thank you for your enquirey on '.$_POST['my_date'].'.<br>We will be following up your request shortly. <br><br>You have said that: <br>Your preferred Design Style is '.$_POST['designstyle'].'. <br>Your approximate Construction Budget is £'.$_POST['budgetcost'].'.<br><br>Please review the useful links about Profesional and our Duty of care policy located at the bottom right of the site. <p>In the meantime wait for our call. <p><p>Regards, <br>Building Doctor';
echo "</tr></td></table>";
echo "<body onLoad=redirect() text=#000000 link=#00FFFF vlink=#C0C0C0>";
}
else
{
?>
<body leftmargin="0" topmargin="0">//start of the html form
<table width="400" align="center"height="246" border="0" cellpadding="0" cellspacing="0" class="biggertext">
 <tr>
  <td height="30" valign="top" ><form method="POST" name="mainform" action="getstartedform.php" onsubmit="validate();">
  1. <?php
  2. //extract($_REQUEST);
  3. if ($_POST['submit'])
  4. {
  5. $user="";
  6. $host="";
  7. $password="";
  8. $database="";
  9. $connection=mysql_connect($host,$user,$password) or die ("could not connect to server");
  10. $db=mysql_select_db($database,$connection);
  11. $sql = "insert into gstrialforma(my_date, name, email, contactaddress, mobile, workhometel, contactpostcode, projectpostcode, doyouneed, designstyle, project, uses, engineer, partywall, architect, projectmanager, design, lifestyle, structural, planning, buildingregs, otherhelp, wheelchair, partialeyesight, terraced, familychildern, semidetached, aged, allergy, detached, other, otherneeds, specifyneeds, programtimecompletion, budgetcost, projectdeadline, whybuild, otherpreferences) values ('{$_POST['my_date']}','{$_POST['name']}','{$_POST['email']}','{$_POST['contactaddress']}','{$_POST['mobile']}','{$_POST['workhometel']}','{$_POST['contactpostcode']}','{$_POST['projectpostcode']}','{$_POST['doyouneed']}','{$_POST['designstyle']}','{$_POST['project']}','{$_POST['uses']}','{$_POST['engineer']}','{$_POST['partywall']}','{$_POST['architect']}','{$_POST['projectmanager']}','{$_POST['design']}','{$_POST['lifestyle']}','{$_POST['structural']}','{$_POST['planning']}','{$_POST['buildingregs']}','{$_POST['otherhelp']}','{$_POST['wheelchair']}','{$_POST['partialeyesight']}','{$_POST['terraced']}','{$_POST['familychildern']}','{$_POST['semidetached']}','{$_POST['aged']}','{$_POST['allergy']}','{$_POST['detached']}','{$_POST['other']}','{$_POST['otherneeds']}','{$_POST['specifyneeds']}','{$_POST['programtimecompletion']}','{$_POST['budgetcost']}','{$_POST['projectdeadline']}','{$_POST['whybuild']}','{$_POST['otherpreferences']}')";
  12. $result = mysql_query($sql) or print(mysql_error());
  13. //mail($to, $subject, $msg, $additional_headers);
  14. mail($_POST['email'],'Building Doctors','Hello '.$_POST['name'].', thank you for your enquirey on '.$_POST['my_date'].'. We will be following up your request shortly. You have said that: Your preferred Design Style is '.$_POST['designstyle'].'. Your approximate Construction Budget is £'.$_POST['budgetcost'].'. Please review the useful links about Profesional and our Duty of care policy located at the bottom right of the site. In the meantime wait for our call. Regards, Building Doctor', "From: athompson@building-doctors.com");
  15. echo "<table border=1 cellpadding=2 cellspacing=2 class=biggertext><tr><td>";
  16. echo "</tr></td><tr><td><img src=images/cr_header.gif></tr></td><tr><td>";
  17. echo 'Hello '.$_POST['name'].', thank you for your enquirey on '.$_POST['my_date'].'.<br>We will be following up your request shortly. <br><br>You have said that: <br>Your preferred Design Style is '.$_POST['designstyle'].'. <br>Your approximate Construction Budget is £'.$_POST['budgetcost'].'.<br><br>Please review the useful links about Profesional and our Duty of care policy located at the bottom right of the site. <p>In the meantime wait for our call. <p><p>Regards, <br>Building Doctor';
  18. echo "</tr></td></table>";
  19. echo "<body onLoad=redirect() text=#000000 link=#00FFFF vlink=#C0C0C0>";
  20. }
  21. else
  22. {
  23. ?>
  24. <body leftmargin="0" topmargin="0">//start of the html form
  25. <table width="400" align="center"height="246" border="0" cellpadding="0" cellspacing="0" class="biggertext">
  26.  <tr>
  27.   <td height="30" valign="top" ><form method="POST" name="mainform" action="getstartedform.php" onsubmit="validate();">

there you see that the getstartedform.php performs a check on itself then submits.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

im still not quite sure what you are trying to do all im getting is this:

you have a form and you want to submit it to this php that checks the form and then submits it to the database??
  • Cafu
  • Student
  • Student
  • Cafu
  • Posts: 97

Post 3+ Months Ago

That code worked for me in IE.

Is it getting through the whole function? I was thinking that maybe if you are referencing an invalid form object the function could be dying before it reaches the radio button validation.

For example, if "workhometel" is mispelled or doesn't exist in the form, you may not be getting to the radio button validation.

Also, your code doesn't work for me in Netscape (v7.1). You should be referencing the form as document.mainform, not just mainform.
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

ok. the first code is a form that submits the info to the 2nd form. the 2nd form actually submits all the info to the database. but because the 1st and 2nd form use the second form as the action, both submit data to the database
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

instead of having something like:

PHP Code: [ Select ]
 
'{$_POST['my_date']}'
 
 
  1.  
  2. '{$_POST['my_date']}'
  3.  
  4.  


use

PHP Code: [ Select ]
 
$_POST['my_date']
 
 
  1.  
  2. $_POST['my_date']
  3.  
  4.  
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

send.htm is a form that sends the info to the getstartedform.php
send.htm isnt a php file so i cannot have $_post['my_date'] at all. what i want to do is send the info that is filled out in the send.htm to the getstartedform.php

the action is getstartedform.php but on the actual getstartedform.php the action is also getstartedform.php so maybe it cannot be done then
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

Code: [ Select ]
<script language="JavaScript" type="text/javascript">
<!--
function x(){
return;
}
function validate(){
    if ((document.getstartedform.name.value=='') || (document.getstartedform.email.value=='') || (document.getstartedform.mobile.value=='')){
        alert('Please check all fields again before submitting as there are some missing entries');
        return false;
        }
    
     if ((document.getstartedform.doyouneed[0].checked == false ) && ( document.getstartedform.doyouneed[1].checked == false ) && ( document.getstartedform.doyouneed[2].checked == false ) && ( document.getstartedform.doyouneed[3].checked == false ))
    {
     alert ( "Please register your type of need" );
     return false;
    }
        else {
        return true;
        }
    }
//-->
</script>
  1. <script language="JavaScript" type="text/javascript">
  2. <!--
  3. function x(){
  4. return;
  5. }
  6. function validate(){
  7.     if ((document.getstartedform.name.value=='') || (document.getstartedform.email.value=='') || (document.getstartedform.mobile.value=='')){
  8.         alert('Please check all fields again before submitting as there are some missing entries');
  9.         return false;
  10.         }
  11.     
  12.      if ((document.getstartedform.doyouneed[0].checked == false ) && ( document.getstartedform.doyouneed[1].checked == false ) && ( document.getstartedform.doyouneed[2].checked == false ) && ( document.getstartedform.doyouneed[3].checked == false ))
  13.     {
  14.      alert ( "Please register your type of need" );
  15.      return false;
  16.     }
  17.         else {
  18.         return true;
  19.         }
  20.     }
  21. //-->
  22. </script>


part of this code works and part does not.

this part works:

Code: [ Select ]
if ((document.getstartedform.name.value=='') || (document.getstartedform.email.value=='') || (document.getstartedform.mobile.value=='')){
        alert('Please check all fields again before submitting as there are some missing entries');
        return false;
        }
  1. if ((document.getstartedform.name.value=='') || (document.getstartedform.email.value=='') || (document.getstartedform.mobile.value=='')){
  2.         alert('Please check all fields again before submitting as there are some missing entries');
  3.         return false;
  4.         }


but this part does not:
Code: [ Select ]
if ((document.getstartedform.doyouneed[0].checked == false ) && ( document.getstartedform.doyouneed[1].checked == false ) && ( document.getstartedform.doyouneed[2].checked == false ) && ( document.getstartedform.doyouneed[3].checked == false ))
    {
     alert ( "Please register your type of need" );
     return false;
    }
  1. if ((document.getstartedform.doyouneed[0].checked == false ) && ( document.getstartedform.doyouneed[1].checked == false ) && ( document.getstartedform.doyouneed[2].checked == false ) && ( document.getstartedform.doyouneed[3].checked == false ))
  2.     {
  3.      alert ( "Please register your type of need" );
  4.      return false;
  5.     }


the top one is for a text field. the botton one is for a checkbox (i assume it can work for a radio button or checkbox) or radio button. either way it doesnt work at all. can someone adjust this so they both work?
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

send -> getstartedform -> getstartedform

getstartedform.php submits to a database right?
so why dont you just do something like this so the form in getstartedform.php has to be filled out along with form (not sure if this works still dont get it sorry dude)

PHP Code: [ Select ]
if($getstartedform == submit && $form == submit) {
 
//database stuff
 
}
  1. if($getstartedform == submit && $form == submit) {
  2.  
  3. //database stuff
  4.  
  5. }
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

Code: [ Select ]
var i=0;
form = document.getstartedform;
    
for (i=0;i < form.doyouneed.length; i++){
    if (form.doyouneed[i].checked == false){
        alert("Please register your type of need");
        return false;
    }
}
  1. var i=0;
  2. form = document.getstartedform;
  3.     
  4. for (i=0;i < form.doyouneed.length; i++){
  5.     if (form.doyouneed[i].checked == false){
  6.         alert("Please register your type of need");
  7.         return false;
  8.     }
  9. }

***this code just addresses your code that doesn't work***


first of all try this loop it should be more efficient then concatenating everything in a long if. Plus if you don't know loops you might study this...b/c in the future if you have more than 4 options to check this could save you a lot of coding & run time.

Lastly, i'm pretty tired so I can't think right now...but I'm trying to remember if arrays work for check boxes. My guess is yet. But, it could be that arrays don't work for them. I'll think about it some more...and post when my brain has woken up some!
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

thank you so much for that.
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

woke up this morning and tried the code. the code doesn't work at all. it just goes ahead and sends the email off. is there another javascript i can use, or better still, a php validation code that just returns a message 'you have not filled out.....'

one thing: with php validation, do u have to use the back button to get back to the form? cannot an alert box appear or is that just for javascript validation? i have php code validation but it doesnt work right at all. any advance on this please?
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

Code: [ Select ]
$required_fields  = array('name','email','contactaddress','mobile','workhometel','contactpostcode','projectpostcode','designstyle','programtimecompletion','budgetcost','feeconstraint','projectdeadline','whybuild');

for($i=0;$i<count($required_fields);$i++) {
  if(!isset($_POST[$required_fields[$i]]) || $_POST[$required_fields[$i]]=='') {
    $err[]='You must provide a '.$_POST[$required_fields[$i]];
  }
}
if(count($err)>0) {
  //there were errors, re-display the form with bad values highlighted or something like that
$err[]='The email field does not appear to be in the correct format';
  1. $required_fields  = array('name','email','contactaddress','mobile','workhometel','contactpostcode','projectpostcode','designstyle','programtimecompletion','budgetcost','feeconstraint','projectdeadline','whybuild');
  2. for($i=0;$i<count($required_fields);$i++) {
  3.   if(!isset($_POST[$required_fields[$i]]) || $_POST[$required_fields[$i]]=='') {
  4.     $err[]='You must provide a '.$_POST[$required_fields[$i]];
  5.   }
  6. }
  7. if(count($err)>0) {
  8.   //there were errors, re-display the form with bad values highlighted or something like that
  9. $err[]='The email field does not appear to be in the correct format';
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

PHP Code: [ Select ]
 
    if(!isset($_POST[$required_fields[$i]]) || $_POST[$required_fields[$i]]=='') {
 
        $err[]='You must provide a '.$_POST[$required_fields[$i]];
 
    }
 
 
  1.  
  2.     if(!isset($_POST[$required_fields[$i]]) || $_POST[$required_fields[$i]]=='') {
  3.  
  4.         $err[]='You must provide a '.$_POST[$required_fields[$i]];
  5.  
  6.     }
  7.  
  8.  

Having established, using the if, that there is nothing
in the variable $_POST[$required_fields[$i]],
you then try to echo it? Try altering the code to this:

PHP Code: [ Select ]
$required_fields    = array('name','email','contactaddress','mobile','workhometel','contactpostcode','projectpostcode','designstyle','programtimecompletion','budgetcost','feeconstraint','projectdeadline','whybuild');
 
 
 
$err=array();    //always initiate vars
 
 
 
for($i=0;$i<count($required_fields);$i++) {
 
    if(!isset($_POST[$required_fields[$i]]) || $_POST[$required_fields[$i]]=='') {
 
        $err[]='You must provide a '.$required_fields[$i];     //you want to echo the required fieldname NOT the empty post variable
 
    }
 
}
 
if(count($err)>0) {
 
    //there were errors, re-display the form with bad values highlighted or something like that
 
$err[]='The email field does not appear to be in the correct format';
 
 
  1. $required_fields    = array('name','email','contactaddress','mobile','workhometel','contactpostcode','projectpostcode','designstyle','programtimecompletion','budgetcost','feeconstraint','projectdeadline','whybuild');
  2.  
  3.  
  4.  
  5. $err=array();    //always initiate vars
  6.  
  7.  
  8.  
  9. for($i=0;$i<count($required_fields);$i++) {
  10.  
  11.     if(!isset($_POST[$required_fields[$i]]) || $_POST[$required_fields[$i]]=='') {
  12.  
  13.         $err[]='You must provide a '.$required_fields[$i];     //you want to echo the required fieldname NOT the empty post variable
  14.  
  15.     }
  16.  
  17. }
  18.  
  19. if(count($err)>0) {
  20.  
  21.     //there were errors, re-display the form with bad values highlighted or something like that
  22.  
  23. $err[]='The email field does not appear to be in the correct format';
  24.  
  25.  


I tested it with $_GET[] but it all seems to work
fine for me. Also turn up your error reporting to
full for testing:

PHP Code: [ Select ]
 
error_reporting(2047);    //put this at line 1 of the php doc
 
 
  1.  
  2. error_reporting(2047);    //put this at line 1 of the php doc
  3.  
  4.  
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

ok. here goes. i have these files that dont work properly. the validation brings up the errors but then blanks out the whole form so they user has to begin again which is not what i want at all. this is the closest to good validation i have. please can you look at it for me and either correct it or let me know what the problem is.
  • Cafu
  • Student
  • Student
  • Cafu
  • Posts: 97

Post 3+ Months Ago

First of all, you probably shouldn't post code that has your database username/password in it.


It looks like you are displaying error messages and telling the user to hit their back button to go back and correct the errors. You are probably encountering the IE bug described here: http://www.experts-exchange.com/Web/Web ... 35573.html

adding
Code: [ Select ]
header("Cache-Control: private");

should solve the problem.

Personally, I don't think this is the best way to go about validation. It would be better if you returned the error messages with the form as they previously filled it out.

for example, on your form you could do the input elements like this:

Code: [ Select ]
<input type="text" name="name" id="name" value="<?= $frm["name"] ?>" class="textstyle"/>


the first time through, the value for this element will be blank because you haven't created an array called $frm yet.

then, when you receive the form put all the data received into this $frm array like this:


Code: [ Select ]
$frm = $HTTP_POST_VARS;


so, when you return the form to them with error messages, all the elements will be filled out. Its a little more involved with checkboxes, radios and selects, but it works.

Another benefit of using a technique like this is that you can use the same form include for modifying existing data, like a form to update an existing user's data.. You just do your query, put the data in the $frm array and send them the form with all the elements already filled out.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Since theese topics were all about problems validating the same form I have merged them in cronological order. Topics are as follows,

javascript validation not really validating
Started : Thu Jul 15, 2004 5:16 pm
By : buzzby365

Javascript Not working
Started : Fri Jul 16, 2004 9:57 am
By : buzzby365

form actions on self
Started : Fri Jul 16, 2004 1:14 pm
By : buzzby365

i have this validation but it doesn't work
Started : Sat Jul 17, 2004 10:36 am
By : buzzby365

validation close but no cigar
Started : Sat Jul 17, 2004 1:14 pm
By : buzzby365

Buzzby365 Please keep any more problems with validating this form in this thread, there is no need to keep starting new topics about it.
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

PHP Code: [ Select ]
if (empty($_POST['name']) || empty($_POST['email']))
 
{
 
    echo "fill in all the required fields";
 
}
  1. if (empty($_POST['name']) || empty($_POST['email']))
  2.  
  3. {
  4.  
  5.     echo "fill in all the required fields";
  6.  
  7. }


i have this simple php code as the validation but i seem to be gettin errors. the form submits even tho the form hasnt been filled. what comes up is the error message and the confirmation
  • Cafu
  • Student
  • Student
  • Cafu
  • Posts: 97

Post 3+ Months Ago

How about this?

PHP Code: [ Select ]
if (empty($_POST['name']) || empty($_POST['email']))
 
{
 
    echo "fill in all the required fields";
 
    die;
 
}
  1. if (empty($_POST['name']) || empty($_POST['email']))
  2.  
  3. {
  4.  
  5.     echo "fill in all the required fields";
  6.  
  7.     die;
  8.  
  9. }
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

thats exactly what i am using. i could hace used DIE or EXIT. produced the same thing. i have adpated the validation to suit the form. brill tho

Post Information

  • Total Posts in this topic: 24 posts
  • Users browsing this forum: No registered users and 144 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.