Jump to content

Archived

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

kenwvs

Not a difficult a Problem - - - I don't think

Recommended Posts

I have a form, written in html, with PHP for validation and had it all working.  I wanted to change the appearance of the form, and had to change a few things and now I have one small problem.

When there is an error in one of the form fields, it is suppose to highlight in red, so you know which fields to correct.  It was working, but now that I have changed the form outlay, and had to remove a > from the code, it is giving me an error instead.  Any ideas on what I need to do to correct this.

Here is the code that was working (a couple of lines anyways)
[code]
<form method="POST" action="uploadtrial.php">
<table>
<tr>
    <td valign="top" <?php if(in_array('id',$err)) echo 'class="error"'; ?>> User ID:</td>
    <td><input type="text" name="id" size="12" value="<?php echo  disp_val('id') ?>"><br>
    You must use the <span class="bold">same User ID</span> for all items you are uploading during this session.(It does not have to be your regular username.)</td>
</tr>
<tr>
    <td <?php if(in_array('item_title',$err)) echo 'class="error"'; ?>>  Item Title:</td>
    <td><input type="text" name="item_title" size="60" value="<?php echo  disp_val('item_title'); ?>"</td>
</tr>
<tr>
    <td <?php if(in_array('item_category',$err)) echo 'class="error"'; ?>>Item Category:</td> //line with change
    <td> <select size="1" name="item_category">
        <?php disp_options($categories,'item_category','',true) ?>
          </select>
          <? if (isset($err_msg['item_category'])) echo '&nbsp;<span
          class="error">' . $err_msg['item_category'] . '</span>'; ?>
          </td></p>
</tr>
[/code]

Here is the same code that doesn't work (again, a couple of lines)
[code]
<form method="POST" action="uploadtrial.php">
<div><?php if(in_array('id',$err)) echo 'class="error"';?>User ID:  //line with change
  <input type="text" name="id2" size="12" value="<?php echo  disp_val('id') ?>" />
  <span class="small">You must use the </span><span class="style1">same User ID</span><span class="small"> for
  all items you are uploading during this session.(It does not have to be your
  regular username.)</span></div><br />
<div><?php if(in_array('item_title',$err)) echo 'class="error"'; ?>Item Title:
<input type="text" name="item_title" size="60" value="<?php echo  disp_val('item_title') ?>" />
<?php if(in_array('item_category',$err)) echo 'class="error"'; ?>&nbsp;Item Category:
<select size="1" name="item_category">
<?php disp_options($categories,'item_category','',true) ?>
</select>
<? if (isset($err_msg['item_category'])) echo '&nbsp;<span
class="error">' . $err_msg['item_category'] . '</span>'; ?></p>
</div> <br />
[/code]

Share this post


Link to post
Share on other sites
I *think* this should work :)

[code]
<form method="POST" action="uploadtrial.php">
<div <?php if(in_array('id',$err)) echo 'class="error"';?>>User ID:  //line with change
  <input type="text" name="id2" size="12" value="<?php echo  disp_val('id') ?>" />
  <span class="small">You must use the </span><span class="style1">same User ID</span><span class="small"> for
  all items you are uploading during this session.(It does not have to be your
  regular username.)</span></div><br />
<div <?php if(in_array('item_title',$err)) echo 'class="error"'; ?>>Item Title:
<input type="text" name="item_title" size="60" value="<?php echo  disp_val('item_title') ?>" /></div>
<div <?php if(in_array('item_category',$err)) echo 'class="error"'; ?>>&nbsp;Item Category:
<select size="1" name="item_category">
<?php disp_options($categories,'item_category','',true) ?>
</select>
<? if (isset($err_msg['item_category'])) echo '&nbsp;<span
class="error">' . $err_msg['item_category'] . '</span>'; ?></p>
</div> <br />[/code]


Well atleast that's how i think it should be :)

Regards
Liam

Share this post


Link to post
Share on other sites
I am having troubles figuring out what change you have made, other than adding a > in here echo 'class="error"';?>[b][color=red]>[/color][/b]User ID:  which I did have in the original and removed.  When I have it there now, it shows on the form....

Am I missing something here...

Thanks,

Ken

Share this post


Link to post
Share on other sites
You are missing some semicolons at the end of php statements.  You code reads:

[quote]<?php echo  disp_val('id') ?> [/quote]
should read:
[quote]<?php echo  disp_val('id')[color=red];[/color] ?> [/quote]
--you have other statements missing semicolons

Share this post


Link to post
Share on other sites
Is the missing semicolon causing the errors not to be displayed in red or is that a different issue?

Ken

Share this post


Link to post
Share on other sites
When you have only one statement between the opening "<?php" and closing "?>" the terminating semi-colon is not needed.
This line [code]<?php echo "anything" ?>[/code] is fine.

The problem lies in the fact when there is an error the attribute [color=red]class="error"[/color] is not within a tag and will probably just display on the screen. It needs to be within a tag of some sort. Here your best bet is to put it wiithin a <span> tag:
[code]
<form method="POST" action="uploadtrial.php">
<div><span <?php if(in_array('id',$err)) echo 'class="error"';?>>User ID:</span>  //line with change
  <input type="text" name="id2" size="12" value="<?php echo  disp_val('id') ?>" />
  <span class="small">You must use the </span><span class="style1">same User ID</span><span class="small"> for
  all items you are uploading during this session.(It does not have to be your
  regular username.)</span></div><br />
<div><span <?php if(in_array('item_title',$err)) echo 'class="error"'; ?>>Item Title:</span>
<input type="text" name="item_title" size="60" value="<?php echo  disp_val('item_title') ?>" />
<?php if(in_array('item_category',$err)) echo 'class="error"'; ?>&nbsp;Item Category:
<select size="1" name="item_category">
<?php disp_options($categories,'item_category','',true) ?>
</select>
<? if (isset($err_msg['item_category'])) echo '&nbsp;<span
class="error">' . $err_msg['item_category'] . '</span>'; ?></p>
</div> <br />[/code]
When there is no error, then the <span> tag doesn't do anything.

Ken

Share this post


Link to post
Share on other sites
Thanks Ken.  I didn't see the other solution as correct, as I couldn't see how it would make the difference.  I am real close to having this working, and am getting quite excited.  One more hurdle  to overcome, and I think I will be there.

Thanks again,

Ken

Share this post


Link to post
Share on other sites

×

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.