Page 1 of 1
want to show a message on the same (form) page.
Posted: Sun Jun 26, 2011 1:59 am
by nadeem14375
Dear all,
I have signup form, on clicking the submit button, the control goes to "process.php". where i check the form's required fields are filled or not, if not filled it come back to signup.php and show the message. "Please fill all the required fields".
1. Is this right way to do it?
2. I want to show the message bellow the submit button, but couldn't succeed.
Regards:
Re: want to show a message on the same (form) page.
Posted: Sun Jun 26, 2011 8:35 am
by social_experiment
The form can be called on the same page and the code you want to run on failure (or success) below that
Code: Select all
<?php
// leave the action attribute blank
<form action="" method="post" >
</form>
// below the form goes the code that sends the email
// pseudo code
if ($sentMail)
{
echo 'Sent';
}
else
{
echo 'Not sent';
}
?>
Re: want to show a message on the same (form) page.
Posted: Sun Jun 26, 2011 11:48 am
by califdon
nadeem14375 wrote:I have signup form, on clicking the submit button, the control goes to "process.php". where i check the form's required fields are filled or not, if not filled it come back to signup.php and show the message. "Please fill all the required fields".
1. Is this right way to do it?
2. I want to show the message bellow the submit button, but couldn't succeed.
social_experiment explained how to do it in the same script, but I just wanted to point out that unless you need to validate data with a database on the server, you can (and generally should) use Javascript to perform simple validation in the browser. If all you want to do is check that required fields are not blank, this can be done in Javascript faster and without extra processing at the server. It is possible that some browsers will have Javascript disabled, but that's probably only a tiny percent of browsers, since an overwhelming number of websites depend on Javascript and very few people disable it in their browsers, I believe.
Re: want to show a message on the same (form) page.
Posted: Sun Jun 26, 2011 12:35 pm
by Idri
califdon wrote:
social_experiment explained how to do it in the same script, but I just wanted to point out that unless you need to validate data with a database on the server, you can (and generally should) use Javascript to perform simple validation in the browser. If all you want to do is check that required fields are not blank, this can be done in Javascript faster and without extra processing at the server. It is possible that some browsers will have Javascript disabled, but that's probably only a tiny percent of browsers, since an overwhelming number of websites depend on Javascript and very few people disable it in their browsers, I believe.
I'll just drop another 2 cents in here because I felt they needed to be there.
Though javascript can be used for simple validation of input fields and whatnots, you should not neglect to check these values in your processing logic. Addons/Tools such as Firebug allow users to alter HTMl on pages, though this is just clientside.
Take for example this simple code.
Code: Select all
<html>
<head>
<script>
function keypress(){
alert('Test');
}
</script>
</head>
<body>
<input type="text" onkeypress="keypress();"/>
</body>
</html>
Using firebug, one can alter the onkeypress event to not call any javascript functions. Now consider the keypress() function being your validation logic, if I´d just remove the function call I wouldn´t have to be worried about what I put into the field seeing as there´s no longer a check. This is why you should not rely on client-side checks alone. Always make sure that you check submitted values, regardless of whether or not you´ve checked them upon input.
Re: want to show a message on the same (form) page.
Posted: Mon Jun 27, 2011 1:44 am
by phazorRise
nadeem14375 wrote:Dear all,
I have signup form, on clicking the submit button, the control goes to "process.php". where i check the form's required fields are filled or not, if not filled it come back to signup.php and show the message. "Pleasefill all the required fields".
1. Is this right way to do it?
2. I want to show the message bellow the submit button, but couldn't succeed.
Regards:
You can validate form either on client with javascript , rich
form validation plugins are available in jQuery .
Or it's better to do it on server.
You can use
php-form-validator-class .
You can customize it to suit your needs. Or you can go through above class and make your own.
Re: want to show a message on the same (form) page.
Posted: Mon Jun 27, 2011 6:52 am
by social_experiment
phazorRise wrote:Or it's better to do it on server.
It is probably better to do it on the server aswell because javascript can be disabled on the user's browser rendering all validations using javascript useless.