dc_jt Posted October 17, 2006 Share Posted October 17, 2006 Looking at the picture I want the error messages shown without the input form. And then I am planning on creating a button in the error messages box to go back to the input form.Any ideas how to do this? My code is as follows:[code]<form name="myform" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <div class="home_text"> <?php if ($sMode == 'complete') { echo '<div class="complete"><div class="formwrapper">Thank You for submitting your details.</div>'; } else { ?> <? if(is_array($aErrors) && count($aErrors) > 0) { ?> <ul><div class="formwrapper"> <? foreach($aErrors as $sError) { echo '<li>'.$sError.'<br></li>'; } // end foreach ?><br /></ul><? } //end if (is_array($aErrors)... ?> <div class="formwrapper"> <div class="textlabel">Name*</div><div class="formlabel"> <input name="Name" type="text" class="dataform" value="<?=(stripslashes($_POST['Name']))?>" /> </div> <div class="textlabel">Email*</div> <div class="formlabel"> <input name="Email" type="text" class="dataform" value="<?=(stripslashes($_POST['Email']))?>"/> </div> <div class="textlabel">Address*</div> <div class="formlabel"> <textarea name="Address" rows="2" wrap="virtual" class="dataform"><?=(stripslashes($_POST['Address']))?></textarea> </div> <div class="textlabel">Business Name*</div> <div class="formlabel"> <input name="Business_Name" type="text" class="dataform" value="<?=(stripslashes($_POST['Business_Name']))?>"/> </div> <div class="textlabel">Type of Business*</div> <div class="formlabel"> <input name="Type_of_Business" type="text" class="dataform" value="<?=(stripslashes($_POST['Type_of_Business']))?>"/> </div> <div class="textlabel">Comments</div> <div class="formlabel"> <textarea name="Comments" rows="2" wrap="virtual" class="dataform"><?=(stripslashes($_POST['Comments']))?></textarea> </div> <div class="textlabel"> </div><div class="formlabel"> <input name="Submit" type="submit" class="databut" value="Submit" /> <input type="hidden" name="mode" value="apply" /> <br class="clear"/> </form>[/code]This is class with the errors in by the way:[code]private function ValidateClientData($aPostData) { $aErrors = array(); if(!$aPostData['Name']) { $aErrors['Name']='Please enter your Name'; } if(validateemail($aPostData['Email'])===false) { $aErrors['Email']='Please enter a valid Email address';} //if(validateemail(!$aPostData['Email'])===false) //{ // $aErrors['Email']='Please enter your Email'; //} if(!$aPostData['Address']) { $aErrors['Enquiry']='Please enter your Address'; } if(!$aPostData['Business_Name']) { $aErrors['Business_Name']='Please enter your Business Name'; } if(!$aPostData['Type_of_Business']) { $aErrors['Type_of_Business']='Please enter your Type of Business'; } if (count($aErrors) > 0) return array(false, $aErrors); return array(true); } }?>[/code][URL=http://img356.imageshack.us/my.php?image=picss2.png][IMG]http://img356.imageshack.us/img356/9508/picss2.th.png[/img][/URL] Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted October 17, 2006 Share Posted October 17, 2006 Stick the form code inside the 'else' part of the 'if' statement...[code]<form name="myform" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <div class="home_text"> <?php if ($sMode == 'complete') { echo '<div class="complete"><div class="formwrapper">Thank You for submitting your details.</div>'; } else { ?> <? if(is_array($aErrors) && count($aErrors) > 0) { ?> <ul><div class="formwrapper"> <? foreach($aErrors as $sError) { echo '<li>'.$sError.'<br></li>'; } // end foreach ?><br /></ul><? } else { ?> <div class="formwrapper"> <div class="textlabel">Name*</div><div class="formlabel"> <input name="Name" type="text" class="dataform" value="<?=(stripslashes($_POST['Name']))?>" /> </div> <div class="textlabel">Email*</div> <div class="formlabel"> <input name="Email" type="text" class="dataform" value="<?=(stripslashes($_POST['Email']))?>"/> </div> <div class="textlabel">Address*</div> <div class="formlabel"> <textarea name="Address" rows="2" wrap="virtual" class="dataform"><?=(stripslashes($_POST['Address']))?></textarea> </div> <div class="textlabel">Business Name*</div> <div class="formlabel"> <input name="Business_Name" type="text" class="dataform" value="<?=(stripslashes($_POST['Business_Name']))?>"/> </div> <div class="textlabel">Type of Business*</div> <div class="formlabel"> <input name="Type_of_Business" type="text" class="dataform" value="<?=(stripslashes($_POST['Type_of_Business']))?>"/> </div> <div class="textlabel">Comments</div> <div class="formlabel"> <textarea name="Comments" rows="2" wrap="virtual" class="dataform"><?=(stripslashes($_POST['Comments']))?></textarea> </div> <div class="textlabel"> </div><div class="formlabel"> <input name="Submit" type="submit" class="databut" value="Submit" /> <input type="hidden" name="mode" value="apply" /> <br class="clear"/> </form><?php}?>[/code]RegardsHuggie Quote Link to comment Share on other sites More sharing options...
dc_jt Posted October 18, 2006 Author Share Posted October 18, 2006 Thanks a lot, great help!All I need now is a back button to get back to the form :) Quote Link to comment Share on other sites More sharing options...
dc_jt Posted October 18, 2006 Author Share Posted October 18, 2006 Is it possible to create a button in the error form so that when the user presses this they are returned to the input form with the fields they entered correctly still input??Or is a session needed? Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted October 18, 2006 Share Posted October 18, 2006 Sessions are going to be needed for that one, but don't worry, it shouldn't be too much overhead getting that done.RegardsHuggie Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted October 18, 2006 Share Posted October 18, 2006 [quote author=dc_jt link=topic=111792.msg453617#msg453617 date=1161159188]Is it possible to create a button in the error form so that when the user presses this they are returned to the input form with the fields they entered correctly still input??Or is a session needed?[/quote]You can read my tutorial [url=http://www.phpfreaks.com/tutorials/145/0.php]Multipage forms[/url] to get an idea of how to do it. Quote Link to comment Share on other sites More sharing options...
dc_jt Posted October 18, 2006 Author Share Posted October 18, 2006 By pressing the back button in the browser, this returns the user to the input form with the correct details still entered. Therefore, surely I could just put a back button in my form without the use of a session, what do you think?Thanks Quote Link to comment Share on other sites More sharing options...
dc_jt Posted October 18, 2006 Author Share Posted October 18, 2006 AhhI have created a back button using<input class="databut" type="button" value="Back" onClick="document.location='<?=$_SERVER['PHP_SELF']?>';"/>This takes me back but the details arent still in the form. How come when the browser button is pressed they are but with this button theyre not?*edited* Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted October 18, 2006 Share Posted October 18, 2006 Your back button isn't going back, it's reloading the page...Try this:[code]<input class="databut" type="button" value="Back" onClick="history.back()"/>[/code]RegardsHuggie Quote Link to comment Share on other sites More sharing options...
dc_jt Posted October 18, 2006 Author Share Posted October 18, 2006 Done it using this:<input class="databut" type="button" value="Back" onClick='self.history.back();'>Thanks Quote Link to comment Share on other sites More sharing options...
.josh Posted October 18, 2006 Share Posted October 18, 2006 Howcome you want to have a seperate error page and then have the user go back to the form in the first place? Wouldn't it be more convenient for the user to have the error messages displayed next to the offending fields, or at least on the same page? Quote Link to comment Share on other sites More sharing options...
dc_jt Posted October 18, 2006 Author Share Posted October 18, 2006 Possibly, I did have that at first but it meant my form would move down and then be out of place and stuff. Rather than fiddle with the design I decided to do this.I know where your coming from though :) Quote Link to comment 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.