PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I just want to built-in validation engine such as making an INPUT required,
or ensuring the value is an Integer or Date.
I coded below but it doesnot work.
[thispage.php]
--------------------------------
<html>
<body>
<form action=<?php if($_POST["name"]==null||$_POST["address"]==null){echo "thispage.php";}
else{echo "nextpage.php";} ?> method='post'>
Name:<input type='text' name='name'><br>
<?php if($_POST["name"]==null){echo "You have to type your name!!";} ?>
Address:<input type='text' name='address'><br>
<?php if($_POST["address"]==null){echo "Where do you live? tell me!!";} ?>
<input type='submit'>
</form>
</body>
</html>
--------------------------------
*What i want to do is if the forms in 'thispage.php' is filled, the page goes to next page,
but if not, the page cannot go to next page and the message such as 'you have to type your name'
has to be showed up on the browser.
If you have time, please copy and paste the code and test it.
You will have some problems......
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I just want to built-in validation engine such as making an INPUT required,
or ensuring the value is an Integer or Date.
I coded below but it doesnot work.
[thispage.php]
--------------------------------
<html>
<body>
<form action=<?php if($_POST["name"]==null||$_POST["address"]==null){echo "thispage.php";}
else{echo "nextpage.php";} ?> method='post'>
Name:<input type='text' name='name'><br>
<?php if($_POST["name"]==null){echo "You have to type your name!!";} ?>
Address:<input type='text' name='address'><br>
<?php if($_POST["address"]==null){echo "Where do you live? tell me!!";} ?>
<input type='submit'>
</form>
</body>
</html>
--------------------------------
*What i want to do is if the forms in 'thispage.php' is filled, the page goes to next page,
but if not, the page cannot go to next page and the message such as 'you have to type your name'
has to be showed up on the browser.
If you have time, please copy and paste the code and test it.
You will have some problems......
Thank you in advance.
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color][/quote]
I think the problem is that you in the action= part of the form, you need to change the string that is echo'd out to make that the string contains quotation marks.
Try this:
volka,
thank you for quick replay.
I read the tutorial but for me it is difficult to undersand because i have
never learned php with CLASS. I have to study that but for now it is quite difficult.
Do you know any other tutorial about the basic validation? if you know, please let me know.
blackbread,
Thank you for quick reply.
i tried your code but the result was the same thing....
if you have any other solutiona about this, please let me know.
The problem is; 1. when i open 'thispage.php', the error message 'you have to type your name!!' and 'where do you live' are
already showed up on the browser. cos when i open 'thispage.php', the value'$_POST["name"]' and '$_POST["address"]'
is NULL. that is why i got this problems.
2. Even though i do not fill the forms, the page goes to 'nextpage.php'. the page is supposed to be the same page if i donot fill in the form.
but your code still does not work....
At first when i donot type anything and then click submit button, the page does not go
the next page. that is fine.
But even when i type name and address and then click submit button,
the page does not go the nextpage.php. that is a problem.
if i type name and address and then click submit button, the page should go to the nextpage.php.
BUT!!!!
After that, When i click submit button, the page goes to the next page even though i did not
type anything. Do you get what i mean? If possible, I' d like you to try your code and then
you realize what i want to say.
Sorry my English is not good so i am afraid that people cannot get what i want to say.
When the page is first loaded, your $_POST variables are null, which means the action= attribute is going to be "thispage.php". When the user hit's submit the first time, it going to go to thispage.php.
Now, when the page is loaded the second time with the $_POST variables set, if they are not set to an empty string, then the action= will be set to "nextpage.php". This is why it works on the second time around.
To honest, you'd be better off using Javascript to do the form validation. If you want, I can show you.
To honest, you'd be better off using Javascript to do the form validation. If you want, I can show you.
Yep and just tell me what the URL to the site is so I can hack it to pieces
I'm sorry, that might have sounded rude. What I am trying to say is that JavaScript is easily bypassed, in fact you can completely bypass the form entirely and send any data to the server, any n000b script kiddy can and will do this. Always validate your data server. If you want client side validation you should do this in addition to server side validation.
Actually Javascript seems to be easier to make this kind of validation and
i have some Javascript documents about this so probably i can make it by javascipt.
but I just want to know how i should code for that by PHP.
so All i can do is to wait until somebody figure out this problem or try to figure out by myself.
If you figure out, please let me know. and if i figure out, i post here.
Pimptastic wrote:For the love of God, WHATEVER you do, DO NOT do this in Javascript
agreed. The decisive validation must be server side.
You might add a client side (javascript) validation for the user's convenience but it must never be authoritative.