Jump to content

Archived

This topic is now archived and is closed to further replies.

dc_jt

How to get rid of form?

Recommended Posts

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">&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>[/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]

Share this post


Link to post
Share on other sites
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">&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
}
?>
[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites
Thanks a lot, great help!

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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*

Share this post


Link to post
Share on other sites
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]

Regards
Huggie

Share this post


Link to post
Share on other sites
Done it using this:

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

Thanks

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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  :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.