Re: PHP form port

From: Date: Sat, 10 Aug 2002 17:51:12 +0000
Subject: Re: PHP form port
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-111959@lists.php.net to get a copy of this message
>From: "Daniel Guerrier" <dan_guerrier@yahoo.com> >Sent: Saturday, August 10, 2002 12:14 PM >Subject: [PHP] PHP form port > How do i execute a form post with php? > I want to validate CCard info etc.. then perform the > post with no furtheraction from the user. > > Basically If not valid stay here and show whats wrong > ELSE post form to process.php Sorry, I mis-understood your question. PHP is server-side, so you have to post the form to validate. The way I handle the situation you have is to have the same script process the form for both the initial request (method=get) and the form post (method=post). If 'POST' == $_SERVER['REQUEST_METHOD'], then validate. If validation passes, process the transaction, and redirect with header() to a new page. if it fails, make use the prior supplied data in input values so you retain the input from the person using your form. Example: <?php if ('GET' == $_SERVER['REQUEST_METHOD']) $name=''; $location=''; } if ('POST' == $_SERVER['REQUEST_METHOD']) { $errors = validate(); if (empty($errors()) { process_form(); redirect(); } $name = trim($_POST['name']); $location = trim($_POST['location']); } ?> <form method="post" action="<?php echo {$_SERVER['PHP_SELF']}; ?> "> <input type="text" name="name" value="<?php echo $name; ?> "> <input type="text" name="location" value="<?php echo $location; ?> "> <input type="submit" name="submit" value="Submit"> </form> HTH

« previous php.general (#111959) next »