Jump to content

How to get rid of form?


dc_jt

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]
Link to comment
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
Link to comment
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.
Link to comment
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
Link to comment
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*
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.