Jump to content

PHP Form , do not post blank fields


jmdostal

Recommended Posts

Good morning,

  I am a beginner at PHP, but trying to write a simple script to use at work and currently stuck on one part, looking for some advice!

 

I have a simple form here > http://jmdostal.com/route2.php (Feel free to use it to test), that returns data on the next page, in a format such as :

 

Jose F - Jose A - 285

Brenda L [Delivery] [Dallas] - Items

Job 2 [Pickup] [Arlington] - Items

[] [] -

[] [] -

[] [] -

[] [] -

[] [] -

 

Gustavo - +1 - 284/pickup

Jody W [Delivery] [Keller] - Items

[] [] -

[] [] -

[] [] -

[] [] -

[] [] -

[] [] -

 

My question is how can I get it not to show the fields that are empty, so I dont have a bunch of lines with  [] [] - formatting

 

Here is my coding you can view here > http://jmdostal.com/code.txt

 

A friend had suggested to me trying to use isset , so I tried it on a few lines, such as :

 

if(isset($_POST['items14'])){

$items14 = "- ". Trim(stripslashes($_POST['items14'])); 

}

 

But it didnt seem to change anything.

 

Im sure this is something simply,

Any suggestions are appreciated!

Thanks !

 

Link to comment
Share on other sites

Yes, I saw that as well, but perhaps I am just not using it correctly.

 

I just added :

if (empty($jobsite13)) {
    echo '';
}

if (empty($dp13)) {
    echo '';
}
if (empty($city13)) {
    echo '';
}
if (empty($item13)) {
    echo '';
}

$jobsite13 = "<br><font color=#0000ff><font size=3>".  Trim(stripslashes($_POST['jobsite13']));  
$dp13 = "</b>[". Trim(stripslashes($_POST['dp13'])) . "]"; 
$city13 = "[".  Trim(stripslashes($_POST['city13'])) . "]";
$items13 = "- ". Trim(stripslashes($_POST['items13']));

 

Then tested again and left the 3rd job field blank, but still returned the  [][]-

Link to comment
Share on other sites

Could you give me an example of what I would need to change my line of code to, to do this properly,

 

Instead of having ,

 

if (empty($dp13)) {

    echo '';

}

$dp13 = "[". Trim(stripslashes($_POST['dp13'])) . "]";

 

What should it say instead?

Thanks for your help.

 

 

Link to comment
Share on other sites

use your if()'s to dictate what is displayed:

if(!empty($_POST['jobsite13']){
$jobsite13 = "<br><font color=#0000ff><font size=3>".  Trim(stripslashes($_POST['jobsite13']));  

if (empty($dp13)) {
    $dp13 = '';
}
else {$dp13 = "</b>[". Trim(stripslashes($_POST['dp13'])) . "]"; }
if (empty($city13)) {
    city13 = '';
}
else {$city13 = "</b>[". Trim(stripslashes($_POST['dp13'])) . "]"; }
if (empty($item13)) {
    item13 =  '';
}
else {$dp13 = "</b>[". Trim(stripslashes($_POST['dp13'])) . "]"; }
}
else{
$jobsite13 = '';
}
if(($jobsite13 != '')&&($dp13 != '')&&($city13 != '')){
echo "<table><tr><td colspan=2>$jobsite13</td></tr><tr><td>DP</td><td>$dp</td></tr><tr><td>CITY</td><td>$city13</td></tr></table>;
else{ echo '';}

 

 

 

Link to comment
Share on other sites

Err sorry, getting closer I think ,

 

Ive put the code such as :

 

 

 

if (!empty($driver1)) {
$driver1 = "<font color=#0000FF><font size=5>". Trim(stripslashes($_POST['driver1']));
}
if (!empty($h1)) {
$h1 =  "- ".  Trim(stripslashes($_POST['h1'])); 
}
if (!empty($t1)) {
$t1 = "- ". Trim(stripslashes($_POST['t1'])) . "<br>"; 
}


if (!empty($jobsite11)) {
    $dp12 = "<br><font color=#0000ff><font size=3>". Trim(stripslashes($_POST['jobsite11'])) . "]"; 
}
if (!empty($dp11)) {
    $dp12 = "[". Trim(stripslashes($_POST['dp11'])) . "]"; 
}
if (!empty($city11)) {
    $dp12 = "[". Trim(stripslashes($_POST['city11'])) . "]"; 
}
if (!empty($items11)) {
    $dp12 = "[". Trim(stripslashes($_POST['items11'])) . "]"; 
}

 

But now when I enter something into the field, nothing is showing up on the page at all, as if its counting everything as a blank .

 

 

^ tried the code above but gave error

Link to comment
Share on other sites

The code I have for the display is :

 

 

print "

<table width=70% bgcolor=#ffffff>
<tr><td>
<font color=#0000FF>

<B>$driver1 $h1 $t1</b>  
<B>$jobsite11</b>  $dp11 $city11  $items11 
<B>$jobsite12</b>  $dp12 $city12  $items12 
<B>$jobsite13</b>  $dp13 $city13  $items13 
<B>$jobsite14</b>  $dp14 $city14  $items14 
<B>$jobsite15</b>  $dp15 $city15  $items15 
<B>$jobsite16</b>  $dp16 $city16  $items16 
<B>$jobsite17</b>  $dp17 $city17  $items17 

 

that was displaying before, but now nothing will show.

 

The full code is

 


if (!empty($driver1)) {
$driver1 = "<font color=#0000FF><font size=5>". Trim(stripslashes($_POST['driver1']));
}
if (!empty($h1)) {
$h1 =  "- ".  Trim(stripslashes($_POST['h1'])); 
}
if (!empty($t1)) {
$t1 = "- ". Trim(stripslashes($_POST['t1'])) . "<br>"; 
}


if (!empty($jobsite11)) {
    $dp12 = "<br><font color=#0000ff><font size=3>". Trim(stripslashes($_POST['jobsite11'])) . "]"; 
}
if (!empty($dp11)) {
    $dp12 = "[". Trim(stripslashes($_POST['dp11'])) . "]"; 
}
if (!empty($city11)) {
    $dp12 = "[". Trim(stripslashes($_POST['city11'])) . "]"; 
}
if (!empty($items11)) {
    $dp12 = "[". Trim(stripslashes($_POST['items11'])) . "]"; 
}


if (!empty($jobsite12)) {
    $dp12 = "<br><font color=#0000ff><font size=3>". Trim(stripslashes($_POST['jobsite12'])) . "]"; 
}
if (!empty($dp12)) {
    $dp12 = "[". Trim(stripslashes($_POST['dp12'])) . "]"; 
}
if (!empty($city12)) {
    $dp12 = "[". Trim(stripslashes($_POST['city12'])) . "]"; 
}
if (!empty($items12)) {
    $dp12 = "[". Trim(stripslashes($_POST['items12'])) . "]"; 
}



print "

<table width=70% bgcolor=#ffffff>
<tr><td>
<font color=#0000FF>

<B>$driver1 $h1 $t1</b>  
<B>$jobsite11</b>  $dp11 $city11  $items11 
<B>$jobsite12</b>  $dp12 $city12  $items12 
<B>$jobsite13</b>  $dp13 $city13  $items13 
<B>$jobsite14</b>  $dp14 $city14  $items14 
<B>$jobsite15</b>  $dp15 $city15  $items15 
<B>$jobsite16</b>  $dp16 $city16  $items16 
<B>$jobsite17</b>  $dp17 $city17  $items17 


<b>$driver2 $h2 $t2</b>  
<b>$jobsite21</b>  $dp21 $city21  $items21 
<b>$jobsite22</b> $dp22 $city22  $items22 
<b>$jobsite23</b>  $dp23 $city23  $items23 
<b>$jobsite24</b>  $dp24 $city24  $items24 
<b>$jobsite25</b>  $dp25 $city25  $items25
<b>$jobsite26</b>  $dp26 $city26  $items26
<b>$jobsite27</b>  $dp27 $city27  $items27 

Link to comment
Share on other sites

if (!empty($jobsite11)) {
    $dp12 = "<br><font color=#0000ff><font size=3>". Trim(stripslashes($_POST['jobsite11'])) . "]"; 
}
if (!empty($dp11)) {
    $dp12 = "[". Trim(stripslashes($_POST['dp11'])) . "]"; 
}
if (!empty($city11)) {
    $dp12 = "[". Trim(stripslashes($_POST['city11'])) . "]"; 
}
if (!empty($items11)) {
    $dp12 = "[". Trim(stripslashes($_POST['items11'])) . "]"; 
}

 

is $dp11, etc getting set prior to this? if not, it needs to be, if it is.. why are you then using $_POST['dp11'] instead?

and do you want to keep replacing whatever is in $dp12?

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.