Jump to content

Form Issues with Form Code: I hope this help. Any suggestions welcome


Recommended Posts

The first foreach block of code works like it should, but

the second "foreach" search block doesn't. Being that the 2 blocks are almost identical I have no clue.

 

It's suppose to go through the $_POST array and check if the format isn't equal to the pattern. And if it isn't it's suppose to display "that field only" but it echos out all the $_POST values of the array instead?? Where am I going wrong?

 

View output after the code.

 

 

$label_array = array ("conName" => "Consumer Name",

"conAddress" => "Consumer Address",

"conCity" => "Consumer City",

"conState" => "Consumer State",

"conZip" => "Consumer Zip Code",

"conPhone" => "Consumer Phone",

"schName" => "School Name",

"schAddress" => "School Address",

"schCity" => "School City",

"schState" => "School State",

"schZip" => "School Zip Code",

"strName" => "Store Name",

"strCity" => "Store City",

"strState" => "Store State");

 

//check data fields for correct data

foreach($_POST as $field => $value)

{

if ($value == "")

{

$blank_array[$field] = "blank";

}

 

}

 

if(@sizeof($blank_array) > 0)

echo "<div class='ermess1'>*You didn't fill in one or more required fields.</div>"; 

 

foreach($blank_array as $field => $value)

{

echo "  <div>{$label_array[$field]}</div>";

}

}

else

{

echo "Thank You for Entering";

}

 

 

//======================================================================

 

foreach($_POST as $field => $value)

if (!ereg("^[0-9]{5}(\-[0-9]{4})?$",$_POST['conState'])) // I only want to check this variable for now

// even when I insert $value as the variable output is the same

{

$format[$field] = "bad";

}

 

if(@sizeof($format) > 0)

{

echo "<div class='ermess1'>*The following fields looks to have the wrong format:</div>";

 

foreach($format as $field => $value)

{

echo "  <div>{$label_array[$field]}</div>";

}

 

 

//=========================From Begin=======================================

 

echo " <link href='css/SOS.css' rel='stylesheet' type='text/css' />

<form id='sosSweepstakes' method='post' action=''>

<label for='select'></label>

<label for='conName'><span class='style2'>Consumer Information</span><br />

<br />

*Name:</label>

<input type='text' name='conName' id='formPosition' size='100' class='nameAddressCity_pos' value='{$_POST['conName']}'/>

    <br />

    <br />

<label for='conAddress'>*Address:</label>

<input name='conAddress' type='text' class='nameAddressCity_pos' id='textfield' value='{$_POST['conAddress']}' size='100' />

    <br />

    <br />

<label for='conCity'>*City:</label>

<input name='conCity' type='text'  class='nameAddressCity_pos' id='textfield' value='{$_POST['conCity']}' />

 

<label for='conState' class='stateLabel'> *State:</label>

<input name='conState' type='text'  class='state' id='textfield' value='{$_POST['conState']}' />

 

<label for='conZip' class='zipLabel'>*Zip:</label>

<input name='conZip' type='text' class='zip' id='textfield' value='{$_POST['conZip']}' />

  <br />

  <br />

<label for='conPhone'>*Phone:</label>

<input name='conPhone' type='text' class='nameAddressCity_pos' id='textfield' value='{$_POST['conPhone']}' />

  <br />

  <br />

  <br />

    <span class='style2'>School Nomination Information </span><br />

  <br />

    <label for='schName'>*Name:</label>

<input name='schName' type='text' class='nameAddressCity_pos' id='textfield' value='{$_POST['schName']}' size='100' />

  <br />

  <br />    

    <label for='schAddress'>*Address:</label>

<input name='schAddress' type='text' class='nameAddressCity_pos' id='textfield' value='{$_POST['schAddress']}' size='100' />

  <br />

  <br />   

    <label for='schCity'>*City:</label>

<input name='schCity' type='text' class='nameAddressCity_pos' id='textfield' value='{$_POST['schCity']}' />

   

    <label for='schState' class='stateLabel'>*State:</label>

<input name='schState' type='text' class='state' id='textfield' value='{$_POST['schState']}'/>

   

    <label for='schZip' class='zipLabel'>*Zip:</label>

<input name='schZip' type='text' class='zip' id='textfield' value='{$_POST['schZip']}' />

  <br />

  <br />

    <span class='style2'><br />

    Store Shopped At<br />

    <br />

</span>

    <label for='strName'>*Name:</label>

<input name='strName' type='text' class='nameAddressCity_pos'  id='textfield' value='{$_POST['strName']}' size='100'/>

  <br />

  <br />

  <br />

    <label for='strCity'>*City:</label>

<input name='strCity' type='text'class='nameAddressCity_pos'  id='textfield' value='{$_POST['strCity']}' />

   

    <label for='strStat' class='stateLabel'>*State:</label>

<input name='strState' type='text' class='state'  id='textfield' value='{$_POST['strState']}' />

  <br />

  <br />

  <br />

<label for='Reset'></label>

<input type='reset' name='reset' value='Reset' id='Submit'/>

 

<label for='Sumbit'></label>

<input type='submit' name='submit' value='Submit' id='Reset'/>

</form>";

 

 

//This is the output when I hit submit:

//begin output

*You didn't fill in one or more required fields.

 

Store State //I left this field blank so it’s working right

 

*The following fields looks to have the wrong format:

 

//Below out is where it's wrong it should only return the Consumer Zip field not all of them.

Consumer Name

 

Consumer Address

 

Consumer City

 

Consumer State

 

Consumer Zip Code

 

Consumer Phone

 

School Name

 

School Address

 

School City

 

School State

 

School Zip Code

 

Store Name

 

Store City

 

Store State

Notice: Undefined index: submit in C:\htdocs\folder\folder.php on line 75

// don’t know why I’m getting this notice

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.