kenwvs Posted July 22, 2006 Share Posted July 22, 2006 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 ' <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"'; ?> Item Category:<select size="1" name="item_category"><?php disp_options($categories,'item_category','',true) ?> </select> <? if (isset($err_msg['item_category'])) echo ' <span class="error">' . $err_msg['item_category'] . '</span>'; ?></p></div> <br />[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15323-not-a-difficult-a-problem-i-dont-think/ Share on other sites More sharing options...
shocker-z Posted July 22, 2006 Share Posted July 22, 2006 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"'; ?>> Item Category:<select size="1" name="item_category"><?php disp_options($categories,'item_category','',true) ?> </select> <? if (isset($err_msg['item_category'])) echo ' <span class="error">' . $err_msg['item_category'] . '</span>'; ?></p></div> <br />[/code]Well atleast that's how i think it should be :)RegardsLiam Quote Link to comment https://forums.phpfreaks.com/topic/15323-not-a-difficult-a-problem-i-dont-think/#findComment-62015 Share on other sites More sharing options...
kenwvs Posted July 22, 2006 Author Share Posted July 22, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/15323-not-a-difficult-a-problem-i-dont-think/#findComment-62090 Share on other sites More sharing options...
mainewoods Posted July 22, 2006 Share Posted July 22, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/15323-not-a-difficult-a-problem-i-dont-think/#findComment-62206 Share on other sites More sharing options...
kenwvs Posted July 22, 2006 Author Share Posted July 22, 2006 Is the missing semicolon causing the errors not to be displayed in red or is that a different issue?Ken Quote Link to comment https://forums.phpfreaks.com/topic/15323-not-a-difficult-a-problem-i-dont-think/#findComment-62207 Share on other sites More sharing options...
kenrbnsn Posted July 22, 2006 Share Posted July 22, 2006 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"'; ?> Item Category:<select size="1" name="item_category"><?php disp_options($categories,'item_category','',true) ?> </select> <? if (isset($err_msg['item_category'])) echo ' <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 Quote Link to comment https://forums.phpfreaks.com/topic/15323-not-a-difficult-a-problem-i-dont-think/#findComment-62233 Share on other sites More sharing options...
kenwvs Posted July 23, 2006 Author Share Posted July 23, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/15323-not-a-difficult-a-problem-i-dont-think/#findComment-62243 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.