robcrozier Posted November 9, 2006 Share Posted November 9, 2006 Can someone help!!!im trying to check if a form field is empty, though its always showing as not empty as im echoing a php session variable in the value attribute if the variable is present. Heres the form field:[code] <input name="page_name_<? echo $i; ?>" type="text" class="style183" size="40" value="<? echo $page_name_[$i]; ?> ">[/code]its also being displayed in a loop.Basically the problem is that having:[code] value="<? echo $page_name_[$i]; ?> "[/code]at the end always displays a couple of blank spaces in the form, when the variable $page_name if not present, so the return value never shows as empty.Any help appreciated!!!! Link to comment https://forums.phpfreaks.com/topic/26681-form-help/ Share on other sites More sharing options...
Orio Posted November 9, 2006 Share Posted November 9, 2006 I dont think I really understand you... You want to run the loop only if $page_num is not empty?That's how to do it-[code]<?phpif(isset($page_name) && !empty($page_name)){ //run loop}?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/26681-form-help/#findComment-122051 Share on other sites More sharing options...
robcrozier Posted November 9, 2006 Author Share Posted November 9, 2006 no mate the loops fine,what i want to do is either echo the valie of $page_name in the textfield or echo nothing at all, depending on whether $page_name has a value. The problem occurs when $page_name does not have a value set. The echo statement in the value attribute of the textfield then prints a few zero's, which stops the returning value of the text field showing as empty. Hope this makes it a bit clearer, its hard to describe. Link to comment https://forums.phpfreaks.com/topic/26681-form-help/#findComment-122054 Share on other sites More sharing options...
Orio Posted November 9, 2006 Share Posted November 9, 2006 Oh :)[code]<?php//this code is inside the loopif(!isset($page_name_[$i]) || empty($page_name_[$i])) $page_name_[$i]="";echo '<input name="page_name_'.$i.'" type="text" class="style183" size="40" value="'.$page_name_[$i].'">';?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/26681-form-help/#findComment-122063 Share on other sites More sharing options...
robcrozier Posted November 9, 2006 Author Share Posted November 9, 2006 spot on, cheers! Link to comment https://forums.phpfreaks.com/topic/26681-form-help/#findComment-122069 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.