Forum Moderators: coopster

Message Too Old, No Replies

post after validate

         

jman11

2:34 am on Oct 16, 2009 (gmt 0)

10+ Year Member



i have a form where a user inputs data then presses submit when finished. i validate that each field is filled out with:


switch(true) {
case empty($_POST['field']):
echo 'blah blah';
case empty($_POST['field2']):
echo 'blah blah';
}

... you get the idea. i use default to go to next page using header("Location:..."); but i cant use the posted variables from the previous page when i use header location. i dont really wanna put all the data into a session or cookie or anything, is there another way to validate fields and post to next page still?

Pico_Train

4:45 am on Oct 16, 2009 (gmt 0)

10+ Year Member



Location:pagename.php?name=$_POST['name']&email=$_POST['email']

then value="<?php echo $_GET['name'];?>" etc...

jman11

5:10 am on Oct 16, 2009 (gmt 0)

10+ Year Member



yes i know i can use get but i want the input to be seperate because some of the data is an upload form and i want to keep a variable that holds the location of the file, because each directory is random numbers/letters so people dont hotlink them. anyways some the input needs to be hidden. any other ideas?

skinsey

9:19 am on Oct 16, 2009 (gmt 0)

10+ Year Member



Here is my suggestion, hope it helps just an idea. I think it would be better to write to a database and use a session to call the unique id. Anyway here you go.

Create two forms on the page one has all hidden fields with the same names. Have the first form submit to itself and due your validations and backend processes if passed.

set the variable

$formgood = 1;

Remove the header(Location:) php code

Have a second form with all hidden fields and set the value with the post from the first form. Then set the form action to whatever.
In this example use page.php.

There is an if statement that will do an automatic submit of your hidden fields at the bottom when $formgood = 1.

<form name="FormName" method="POST" action="page.php"
<input type="hidden" name="fieldname" value="<? echo $_POST["fieldname"];?>">
</form>

<script type="text/javascript" language="JavaScript">
<!--
<?

if($formgood = 1)
{
echo "document.FormName.submit();";
?>
//--></script>

skinsey

9:23 am on Oct 16, 2009 (gmt 0)

10+ Year Member



You'ld probably catch them but a couple of typos close the form tag and close the if statement.

jman11

1:57 pm on Oct 16, 2009 (gmt 0)

10+ Year Member



wow i like that idea a lot ill give it a try thanks man