Jump to content

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


kenwvs

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]
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
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.