|
Posted by Kimmo Laine on 11/13/58 11:20
"Jay" <goofyfish@gmail.com> kirjoitti
viestissδ:1120344469.430289.220610@g14g2000cwa.googlegroups.com...
> Hi everybody!
>
> Please help me with this problem. I try to write code for server side
> data validation. Initially, I have a html file called "form.html" which
> just contains all the necessary fields for user to submit their contact
> info (name, phone, email, address.....etc...). All user's input will be
> sent to "processForm.php" using POST. In processForm.php, I want to be
> able to re-display the form in "form.html" with valid user's input and
> error message on top of the form in case user enter invalid data.
> Currently, a simple code that I could think of is the following:
>
> <?php
>
> if (!empty($_POST['submit']))
> {
> $isAllValid = false;
>
>
> //Check for invalid data
> //Code for checking data will be written here.
>
> //Invalid data occur.
> if(!$isAllValid)
> {
> include("form.html");
>
> //set user's input in the form's fields. How to access
> //form's field form here ?
> }
> }
> else
> {
> echo "User not submit";
> }
>
> ?>
>
>
> My questions are:
>
> 1. Is there a way to access the form's fields in "form.html" to set
> their values ? (given all the form's fields in form.html have unique
> name)
>
> 2. If (1) is not doable, then how would I this in PHP ?
Simply set the value attribute of each field.
<input type="text" name="foo" value="<?= $_GET['foo'] ?>">
I'd say it works even though the file is called form.html, since you are
including the page, not passing it thru. In that case php tags should be
executed...
--
"I am pro death penalty. That way people learn
their lesson for the next time." -- Britney Spears
eternal.erectionN0@5P4Mgmail.com
Navigation:
[Reply to this message]
|