PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1847
Number of posts: 5013

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
validate php form on submit Posted by cmps_getch on 21 Sept 2006 at 8:51 AM
how do i go about validating that every field has something intered in it and if not rite when they hit the submit button it will pop up telling them what they need to enter?
Report
Re: validate php form on submit Posted by Eraser9486 on 21 Sept 2006 at 12:45 PM
If you want to do it without refreshing the page, using popups - you probably want to do it in javascript, instead of php as php is a server-side language.

: how do i go about validating that every field has something intered in it and if not rite when they hit the submit button it will pop up telling them what they need to enter?
:

Report
Re: validate php form on submit Posted by minhnguyena7 on 22 Sept 2006 at 12:04 AM
: If you want to do it without refreshing the page, using popups - you probably want to do it in javascript, instead of php as php is a server-side language.
:
Nope, if you do it it javascript, your script is not secured. data may be messed if somebody means it.
To do it in PHP, you should echo PHP variables rite on input feilds. While the form is not submited, they are null.
once the form is submited, if there is one which is not valid, set it to empty or null. Then the output would still be empty. Now you can output the error ms to your users.
Good luck
Report
Re: validate php form on submit Posted by cmps_getch on 22 Sept 2006 at 7:33 AM

could u give me an example of this?


: Nope, if you do it it javascript, your script is not secured. data may be messed if somebody means it.
: To do it in PHP, you should echo PHP variables rite on input feilds. While the form is not submited, they are null.
: once the form is submited, if there is one which is not valid, set it to empty or null. Then the output would still be empty. Now you can output the error ms to your users.
: Good luck
:

Report
Re: validate php form on submit Posted by minhnguyena7 on 22 Sept 2006 at 8:14 AM
This message was edited by minhnguyena7 at 2006-9-22 8:21:52

<form method="get" name="example_form">
  <p>Name :
    <input name="name" type="text" value="<? echo $name; ?>">
  </p>
  <p>Address:
    <input name="address" type="text" value="<? echo $address; ?>">
  </p>
  <p>City:
    <input name="city" type="text" value="<? echo $city; ?>">
	<input name="submit" type="submit" />
</p>
</form>

<? // form validation here 
	// create alert ms 
	
	if (this_is_not_name($_GET['name']))
	{
		 $name = ""; /// if name is not valid, set it to null
		 $ERROR_MS = $ERROR_MS ."NAME IS NOT VALID .... \n"; 
		 $valid_form = false; 
	}
?>
<? if ($valid_form){ ?>
<script language="javascript">
window.alert("<? echo $ERROR_MS; ?> "); 
</script>
<? } ?>





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.