Form validation and save the form

Form validation and save the form

am 11.01.2010 06:37:06 von aditya shukla

--0016e6d7e6818c2f68047cdced15
Content-Type: text/plain; charset=ISO-8859-1

Hello Guys,

I am trying to validate a form for user input , such that when something is
missing load the form again by focusing on the wrong field.Say i don not
enter my address so when the form loads everything else is saved and the
form points to address field.

Thanks

Aditya

--0016e6d7e6818c2f68047cdced15--

Re: Form validation and save the form

am 11.01.2010 07:40:29 von Paul M Foster

On Sun, Jan 10, 2010 at 11:37:06PM -0600, aditya shukla wrote:

> Hello Guys,
>
> I am trying to validate a form for user input , such that when something is
> missing load the form again by focusing on the wrong field.Say i don not
> enter my address so when the form loads everything else is saved and the
> form points to address field.

Typically, you would direct the form back to itself. Then at the top of
the form, you'd put a test to determine if the form has been processed
before or if this is the first time through. Then you make your decision
about missed fields, etc. Like this:

== someform.php ==

if (empty($_POST)) {
load_some_values_or_not();
}
else { // form has entered data
$okay = process_for_errors();
if ($okay) {
store_the_data();
header("Location: success.php");
exit();
}
}
?>
HTML crap goes here...

== end of someform.php ==

You'll notice that if there are entry errors, execution falls through.
In that case, you'll need to do something like this for fields:



so that the entered data shows up in the fields. First time through, the
value attribute will yield nothing.

Paul

--
Paul M. Foster

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Form validation and save the form

am 11.01.2010 15:53:54 von angelo

-----Original Message-----
From: aditya shukla [mailto:adityashukla1983@gmail.com]
Sent: 11 January 2010 07:37 AM
To: php-general
Subject: [PHP] Form validation and save the form

Hello Guys,

I am trying to validate a form for user input , such that when something is
missing load the form again by focusing on the wrong field.Say i don not
enter my address so when the form loads everything else is saved and the
form points to address field.

Thanks

Aditya

You need Javascript for that not PHP. PHP is server side, javascript is
client side (browser).

Regards
Angelo
http://www.elemental.co.za
http://www.wapit.co.za




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Form validation and save the form

am 11.01.2010 15:58:06 von Robert Cummings

Angelo Zanetti wrote:
>
> -----Original Message-----
> From: aditya shukla [mailto:adityashukla1983@gmail.com]
> Sent: 11 January 2010 07:37 AM
> To: php-general
> Subject: [PHP] Form validation and save the form
>
> Hello Guys,
>
> I am trying to validate a form for user input , such that when something is
> missing load the form again by focusing on the wrong field.Say i don not
> enter my address so when the form loads everything else is saved and the
> form points to address field.
>
> Thanks
>
> Aditya
>
> You need Javascript for that not PHP. PHP is server side, javascript is
> client side (browser).

He doesn't say anything about not reloading the form... in fact he
explicitly says "when something is missing load the form again". This
suggests a server request and not JavaScript. Either way... validation
can occur either in JavaScript or PHP... but it should ALWAYS occur in
PHP regardless of any JavaScript validation.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Form validation and save the form

am 11.01.2010 16:02:49 von aditya shukla

--0016e6d7e32db6c43f047ce4d441
Content-Type: text/plain; charset=ISO-8859-1

Thanks for the reply guys.Do you guys know a good resource where i can read
from about form validation through PHP.There a lot on google but please
suggest something if you guys know.


Thanks

Aditya

--0016e6d7e32db6c43f047ce4d441--

RE: Form validation and save the form

am 11.01.2010 16:18:12 von angelo

-----Original Message-----
From: aditya shukla [mailto:adityashukla1983@gmail.com]
Sent: 11 January 2010 05:03 PM
To: Robert Cummings
Cc: Angelo Zanetti; php-general
Subject: Re: [PHP] Form validation and save the form

Thanks for the reply guys.Do you guys know a good resource where i can read
from about form validation through PHP.There a lot on google but please
suggest something if you guys know.


Thanks

Aditya

I think just do some form validation tutorials (google for them).
These will help you to understand the validation process in more detail.

Regards
Angelo
http://www.elemental.co.za
http://www.wapit.co.za



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Form validation and save the form

am 11.01.2010 17:06:38 von Phpster

On Mon, Jan 11, 2010 at 10:18 AM, Angelo Zanetti wrote:
>
>
> -----Original Message-----
> From: aditya shukla [mailto:adityashukla1983@gmail.com]
> Sent: 11 January 2010 05:03 PM
> To: Robert Cummings
> Cc: Angelo Zanetti; php-general
> Subject: Re: [PHP] Form validation and save the form
>
> Thanks for the reply guys.Do you guys know a good resource where i can read
> from about form validation through PHP.There a lot on google but please
> suggest something if you guys know.
>
>
> Thanks
>
> Aditya
>
> I think just do some form validation tutorials (google for them).
> These will help you to understand the validation process in more detail.
>
> Regards
> Angelo
> http://www.elemental.co.za
> http://www.wapit.co.za
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


I still like


// includes go here

if(isset($_POST['submit'])){
process_form();
}else{
show_form();
}//end if

function process_form()
{
//receive the data, validate and store the data in the db goes here
//feel free to add more functions that you could re-use in other parts
//of the app


}

function show_form($data='', $errors='')
{
//code to show the form goes here
//$data and $errors could be passed in from the above function if
//there are issues with the data validation (no image, data missing etc)


}

for simple pages. Its a mini MVC where the code could post the data
back to the form with error message to indicate to the user what
should be done.
--

Bastien

Cat, the other other white meat

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php