Jump to content

Placing error messages in input form after submission


dc_jt

Recommended Posts

Hi

I have an input form which displays errors if one or more fields are not completed. E.g. Please enter name.

However, these appear above the input form which then moves the input form further down the page and out of place. Is there anyway, once the form is submitted, the error messages are shown inside the input form (well inside the outline of it) replacing the input values name, email etc, with a button to go back which then displays the input form with the missing input?

If you understood that, any help would be great thanks
Link to comment
Share on other sites

I did do that and when i click post it says:

The requested URL could not be retrieved

While trying to retrieve the URL: http://www.phpfreaks.com/forums/index.php?

The following error was encountered:

    * Read Error

The system returned:

    (104) Connection reset by peer

An error condition occurred while reading data from the network. Please retry your request.

Your cache administrator is root.
Link to comment
Share on other sites

I think there are sites out there that will host a script for others to view. You can try those. I have had the same problem in the past and it was a certain part of my code that the site did not like. Maybe you can break it up and post it that way till you come across the part that will not work.

Ray
Link to comment
Share on other sites

Well I dont actually have an error. When I say error messages, they are there on purpose because the user has not entered all their details correctly. For example, if they entered nothing it would say:

# Please enter your Name
# Please enter a valid Email address
# Please enter your Address
# Please enter your Business Name
# Please enter your Type of Business

However, this is displayed directly above the input form.

Instead I want it to be displayed INSIDE the form, replacing the Name, Email, Address etc fields and then having a back button which then brings these fields back for the user to input correctly??

Do you understand? Sorry its confusing, but is this possible?

Thanks
Link to comment
Share on other sites

This is the form in the index file

[code] <form name="myform" method="post" action="<?=$_SERVER['PHP_SELF']?>">
 
  <div class="home_text">
  <?php
if ($sMode == 'complete')
{
echo '<div class="complete">Thank You for submitting your details.</div>';

}
else
{
?>

<? if(is_array($aErrors) && count($aErrors) > 0)
{
?>

<ul>
<?
foreach($aErrors as $sError)
{
echo '<li>'.$sError.'<br></li>';
} // end foreach
?></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 the RCLTblClients class

[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]

Is that enough for you? (*Hope this works*)
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.