Jump to content

[SOLVED] Change blank form names


tqla

Recommended Posts

Hello. On my form when the Submit button is clicked my script checks for blank fields. If it finds blanks it shows a message. The problem is that it shows the blank fields in their variable name. I'd like to change the alert to show the same names on the form.

 

Here's the code:

 

     if(isset($blanks))                               
     {
        $message_new = "The following fields are blank. Please enter the required information:<br />  ";
        foreach($blanks as $value)
        {
           $message_new .= "$value<BR /> ";
        }
        extract($_POST);
        include("form.inc");
        exit();
     }

 

The problem is that the read out reads like this:

 

The following fields are blank. Please enter the required information:

firstName

lastName

title

company

street

city

state

zip

telephone

email

 

I'd like to change the message to show the names just like they are on the form. Like this:

 

Last Name

Title

Company

Street

City

State

Zip

Telephone

Email Address

 

The thing is that it can only SHOW it like this but it can't permanantly change the variable because it needs to stay in this form to populate the database.

 

firstName

lastName

title

company

street

city

state

zip

telephone

email

 

Ya know what I mean? Thanks.

Link to comment
https://forums.phpfreaks.com/topic/80322-solved-change-blank-form-names/
Share on other sites

You need to build an array that holds the Titles, and $blanks should be populated with corresponding keys. That way, you can just echo the Title array key using foreach. If you post the rest of the code, I can help you with it (need all of it, really).

 

PhREEEk

Here is an example of how you can do it

 

<?php

if (isset($_POST['submit'])){
   
   $message = "";
      
   //check for empty values
   if (!isset($_POST['f1']) || empty($_POST['f1'])) $message .= "<br>f1";
   if (!isset($_POST['f2']) || empty($_POST['f2'])) $message .= "<br>f2";
   if (!isset($_POST['f3']) || empty($_POST['f3'])) $message .= "<br>f3";
   
   if ($message != ""){
      echo "The following fields are blank. Please enter the required information:";
      echo $message;
   } else {
      echo "Everything was filled in";
   }
}

?>

<p>
<form method="post">
   <input type="text" name="f1"><br>
   <input type="text" name="f2"><br>
   <input type="text" name="f3"><br>
   <input type="submit" name="submit">
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.