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:
want to show a message on the same (form) page.
Moderator: General Moderators
-
nadeem14375
- Forum Newbie
- Posts: 23
- Joined: Sat Oct 30, 2010 2:11 am
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: want to show a message on the same (form) page.
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';
}
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: want to show a message on the same (form) page.
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.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.
Re: want to show a message on the same (form) page.
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>- phazorRise
- Forum Contributor
- Posts: 134
- Joined: Mon Dec 27, 2010 7:58 am
Re: want to show a message on the same (form) page.
You can validate form either on client with javascript , rich form validation plugins are available in jQuery .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:
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.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: want to show a message on the same (form) page.
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.phazorRise wrote:Or it's better to do it on server.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering