Urgent.. passing variables ..
Hello you all !! need your help here ...
I have a form collecting user details , I use the $php_self submitting techniqe so I can validate the required information with built in functions ,and if there is a problem so the form is redisplyed with echoed info and mistakes . I got it from ZEND
Now .. I want to post the data to a scond form .. how to do this without the form action=post because it allready has a self submitting parameter ? sessions or hiddens ? please be specific I'm weak .. (if you know what I mean )..!!
Suzanne posted this at 04:19 — 23rd May 2004.
She has: 5,507 posts
Joined: Feb 2000
Er... Use a condition for the initial form element.
i.e.
<?php
if ((isset($_POST['submit']) && !$error) {
// write the form with the action that sends it elsewhere
echo \"<form ...>\";
else {
// write the form with the $php_self
echo \"<form ...>\";
}
?>
g4ce posted this at 07:36 — 23rd May 2004.
They have: 10 posts
Joined: Dec 2003
Suzanne ,
didn't understand what you ment .. I tried some things but it keeps taking me to an empty page . sorry .. can you be more specific.
Thnk you ...
Suzanne posted this at 16:04 — 23rd May 2004.
She has: 5,507 posts
Joined: Feb 2000
... it was an example to help guide you, not actual code to use!
What things did you try? Do you have the source online? Can you attach the source here?
You can use hidden fields as well, but you'd have to still get it to the other form?
g4ce posted this at 22:21 — 23rd May 2004.
They have: 10 posts
Joined: Dec 2003
Hi Suzanne ,
I know you ment an example , But I followd your thechniqe (which seems excellent ) , and something goes wrong , don't know why but it never choose the second "if statement .. Here is the two choices I made :
<?php
<FORM ACTION=\" if ((isset($_POST['submit'])) && !$errors){
echo \"proccess.php\";
} else {
echo $PHP_SELF ; } \" METHOD=\"POST\">
?>
And the second based on the same "if<>echoing" method to create a form needed to proccess if neccessery , But this one "echos" the whole "form" line :
<?php
if ((isset($_POST['submit'])) && !$errors){
echo \"<form action=\"/proccess.php\"/;>\"
else
echo \"<form action=\"/$PHP_SELF\"/;>\"
?>
Is that what you ment .. Or I misunderstand you ..
Please tell me how to post the variables to another form without submitting it
if it can be done at all ..
Thanks .
Busy posted this at 22:32 — 23rd May 2004.
He has: 6,151 posts
Joined: May 2001
the second lot of code is wrong, to coment a quote use the other slash infront of the quote \" or \' also you need to close your double quote on the if echo part and the else echo part and also add the end curly bracket at the end.
echo " blah blah \"blah\" blah";
When I read your question I got a different idea of what your trying to do than what Suzanne has commented on (her idea would work thou), what are you actually trying to do, do you have two forms you want to send the data from one to the other, or have two forms and want to collect both forms data or just one form but goes/does something else before being done whatever it has to be done ??
g4ce posted this at 22:50 — 23rd May 2004.
They have: 10 posts
Joined: Dec 2003
Hi, Busy ..
Like I said above , I want to validate a form within it by $PHP_SELF , and then post it to another form then proccess it to DB, I'm stuck at the "post " level , the "check" goes fine , but I found that the "action" method was taken by the $php_self for the check procedure , Now -- How can I post those variables after I lost my action=proccess to action =$php_self ..?
<?php
<HTML>
<HEAD>
<TITLE>Zend Code Gallery Form</TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF>
$action =
($HTTP_POST_VARS['action'] == \"check\") ? \"check\" : \"display\";
if($action == \"check\") {
/* Begin Data validation section */
if(!empty($HTTP_POST_VARS['email'])) {
$action = \"process\";
} else {
if(!isset($HTTP_POST_VARS['email']))
$errors[] = \"Email address was never posted!\";
if($HTTP_POST_VARS['email'] == \"\")
$errors[] = \"An e-mail address is required!\";
}
/* End Data validation section */
if(count($errors)) $has_errors = true;
if($has_errors) $action=\"display\";
}
if($action == \"display\"):
<FORM ACTION=\" if ($action==\"process\"){
echo \"proccess.php\";
} else {
echo $PHP_SELF ; } \" METHOD=\"POST\">-
<INPUT TYPE=\"hidden\" NAME=\"action\" VALUE=\"check\">
if($has_errors) {
<FONT SIZE=4>Please Correct the Following Errors:</FONT><BR>
<UL>
foreach($errors as $val) {
echo \"<LI>$val</LI>\";
}
</UL>
} else {
Please fill out the fields below:<BR>
(required fields are marked with an *)<BR>
} // End of $has_errors if
<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=0>
<TR>
<TD>First Name:</TD>
<TD><INPUT TYPE=\"text\" NAME=\"first\" VALUE=\" echo $HTTP_POST_VARS['first']; \"></TD>
<TR>
<TD>Last Name:</TD>
<TD><INPUT TYPE=\"text\" NAME=\"last\" VALUE=\" echo $HTTP_POST_VARS['last']; \"></TD>
</TR>
<TR>
<TD><B>*</B>E-mail:</TD>
<TD><INPUT TYPE=\"text\" NAME=\"email\" VALUE=\" echo $HTTP_POST_VARS['email']; \"></TD>
</TR>
<TR>
<TD COLSPAN=2 ALIGN=CENTER><INPUT TYPE=\"submit\" VALUE=\"Submit Form\"></TD>
</TR>
</TABLE>
</FORM>
elseif ($action==\"process\"):
<!-- Successful processing web page here //-->
else:
<!-- Fatal Error page, unknown action //-->
endif;
</BODY>
</HTML>
?>
Suzanne posted this at 23:40 — 23rd May 2004.
She has: 5,507 posts
Joined: Feb 2000
You know that $errors is just a made up variable name to hold the place of you testing if there are errors in your form? Because if there are, you need to repeat the form with the fields filled in, right?
Perhaps you could use something other than $php_self? Or set a hidden variable?
g4ce posted this at 03:13 — 24th May 2004.
They have: 10 posts
Joined: Dec 2003
Thanks a lot , Maybe I didn't explain myself too good , I succeeded doing it with another form . and javascript autosubmission, The only problem is that a user can't go back now. any Ideas how to solve that ?
Suzanne posted this at 03:41 — 24th May 2004.
She has: 5,507 posts
Joined: Feb 2000
Quite a few, actually, however it seems that your current knowledge level isn't going to make it easy! I'd recommend that you learn more about PHP and polish up your skills before trying to hack further.
Best practice for procedural php:
1. The form is generated by the database or a file set up like:
<?php
// if the form value is set, it will be put in
<input type=\"text\" name=\"dbFieldName\" value=\"=isset($_POST['dbFieldName'])\" />
?>
2. In the event of any error on submission, the error is written to an array or variable and then the form is redisplayed. CSS may be used contextually to visually identify the problem.
3. When there are no errors, the form information is submitted to a database or mailed, then header() is used to redirect the user to a final page. At this point, you can point to another page, form pulling the information from the database.
***
Another option would be to pass the information each time to the next form.
I prefer not to have the form reload the same page.
g4ce posted this at 05:08 — 24th May 2004.
They have: 10 posts
Joined: Dec 2003
You right ,
I do have to improve my skills in PhP. But on the other hand , why to invest all resources on one target , when there are lots of them around, Every thing I allways needed to do get done (/c/c++/java/script/php/perl/html/vb...etc..all platforms) ,This way I also buy myself wide knowlege .
what you think ? Am I wrong ?
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.