Forum Moderators: coopster

Message Too Old, No Replies

PHP validate html form for processing

php validate html form for processing

         

tx_yank85

12:39 am on Aug 12, 2008 (gmt 0)

10+ Year Member



I am using an html page/form as a user registration for a site. I have php in the form for validation which works fine. My form posts to itself for validation so I can point out the areas that are wrong to the user.

What I am having trouble with is if the validation comes back fine how can I make the form submit to process.php. I have tried using <form action=$someVariable and on my final function for validation if it returns with no problems changing that variable to process.php but because I have multiple php breaks throughout the page because it is an html page it doesn't seem to pass the variable up.

As a test I put the variable in the form action and in the same php area as that I set the variable to process.php and it went to that page fine, my problem is that I want to set the variable at my last function and have it send it up.

Hope I didn't confuse anyone.
Thanks for the help

MattAU

1:08 am on Aug 12, 2008 (gmt 0)

10+ Year Member



There's no real easy to to submit $_POST data to another page.

What I suggest you do is have a think about how you can include it all in one page. Here's a bit of a pseudo layout to do that.

if(form is posted)
{
validate data
}

if(form is not posted or data is not valid)
{
display form
}
else
{
process data
redirect to or display the success page
}

tx_yank85

4:26 pm on Aug 12, 2008 (gmt 0)

10+ Year Member



Thanks Matt that does sounds like the most feasible way to do it.. I could just send it to validate on another page but prefer having that on the same page so its easier to show the form with the errors highlighted, but having it post to my mySQL db on the same page may be the only real way to do it.

ag_47

9:11 pm on Aug 12, 2008 (gmt 0)

10+ Year Member



If you *really* need to post to another page, here something that might help you:

<?php
..validate input
//use curl_lib:

$url = "http://localhost/process.php";
$params = "param1=".$_POST['input1']."&param2=".$_POST['input2'];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url); //append URL
curl_setopt($ch, CURLOPT_POST,TRUE);//We are using method POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);//append parameters

// results will be outputted to the browser directly
curl_exec($ch);
curl_close ($ch);
...
?>

This will replace you page with whatever process.php does..