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
Share on other sites

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>

Link to comment
Share on other sites

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.