Jump to content


Photo

How to get rid of form?


  • Please log in to reply
11 replies to this topic

#1 dc_jt

dc_jt
  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 17 October 2006 - 04:16 PM

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:

<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">&nbsp;</div><div class="formlabel">
				  <input name="Submit" type="submit" class="databut" value="Submit" />
				    <input type="hidden" name="mode" value="apply" />
				    	<br class="clear"/>
		</form>

This is class with the errors in by the way:

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);
	}
	
	
}
?>

Posted Image

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 17 October 2006 - 04:28 PM

Stick the form code inside the 'else' part of the 'if' statement...

<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">&nbsp;</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
}
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 dc_jt

dc_jt
  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 18 October 2006 - 08:01 AM

Thanks a lot, great help!

All I need now is a back button to get back to the form  :)

#4 dc_jt

dc_jt
  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 18 October 2006 - 08:13 AM

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?

#5 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 18 October 2006 - 08:14 AM

Sessions are going to be needed for that one, but don't worry, it shouldn't be too much overhead getting that done.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#6 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 18 October 2006 - 08:18 AM

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?


You can read my tutorial Multipage forms to get an idea of how to do it.

#7 dc_jt

dc_jt
  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 18 October 2006 - 08:20 AM

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

#8 dc_jt

dc_jt
  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 18 October 2006 - 08:29 AM

Ahh

I 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*

#9 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 18 October 2006 - 08:39 AM

Your back button isn't going back, it's reloading the page...

Try this:

<input class="databut" type="button" value="Back" onClick="history.back()"/>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#10 dc_jt

dc_jt
  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 18 October 2006 - 08:50 AM

Done it using this:

<input class="databut" type="button" value="Back" onClick='self.history.back();'>

Thanks

#11 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 18 October 2006 - 08:55 AM

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?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#12 dc_jt

dc_jt
  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 18 October 2006 - 09:06 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users