Jump to content


Photo

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


  • Please log in to reply
6 replies to this topic

#1 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 22 July 2006 - 09:31 AM

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)
<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>

Here is the same code that doesn't work (again, a couple of lines)
<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 />


#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 22 July 2006 - 11:22 AM

I *think* this should work :)

<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 />


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

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 22 July 2006 - 04:22 PM

I am having troubles figuring out what change you have made, other than adding a > in here echo 'class="error"';?>>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

#4 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 22 July 2006 - 10:22 PM

You are missing some semicolons at the end of php statements.  You code reads:

<?php echo  disp_val('id') ?>


should read:

<?php echo  disp_val('id'); ?>

--you have other statements missing semicolons

#5 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 22 July 2006 - 10:30 PM

Is the missing semicolon causing the errors not to be displayed in red or is that a different issue?

Ken

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 July 2006 - 11:42 PM

When you have only one statement between the opening "<?php" and closing "?>" the terminating semi-colon is not needed.
This line
<?php echo "anything" ?>
is fine.

The problem lies in the fact when there is an error the attribute class="error" 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:
<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 />
When there is no error, then the <span> tag doesn't do anything.

Ken

#7 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 23 July 2006 - 01:04 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users