Re: I dont know what to do here?

From: Date: Wed, 24 Jan 2001 00:41:15 +0000
Subject: Re: I dont know what to do here?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-36304@lists.php.net to get a copy of this message
Sefton didn't know what to do: > > I have a form in an htm file that is sending info to a cgi script > > (formmail.pl) but the confirmation page I am using is php3. I want to pass > > the value of a text box in the form to the php3 page. > > So I need the faq_confirm.php3 page to appear, plus have it send the > > variable $message that is one of the fields on the form. > > I thought you just added it like ?message > > But i already have a ? Joe suggested: > To pass more than one argument type: > http://foo.com/script.php?var1=hello&var2=foo&var3=bar But that won't help in this case. See, there are two different URL's. First, form.html calls the formmail cgi with the url in the FORM ACTION. Then the user is redirected by formmail with the URL in the redirect form element. Additions to the link to the formmail script are of course not seen by the following php3 page, because that's another link. Form.html has a textbox with the message and a hidden textbox with redirect URL. [form.html] | | <form action="http://~/formmail.pl"? V [formmail.pl] | | redirect V [faq_confirm.php3] show message here Formmail.pl does not need any addition to the link; it gets the form elements by magic (POST method defined in FORM tag), like php scripts would too, only with a different name. To pass the textbox message through as you ask, the message needs to be in the redirect URL. This addition of the message i can imagine can be done in the first page with javascript (suggestion D) , in the formmail.pl (B) or in formmail.php (C). However, I suggest to change your concept as in suggestion A. None is tested or claims to be complete. Just giving a direction and hints. ************************************************************* A. Make your own PHP script [form.html] | | form action="confirm.php3" V [faq_confirm.php3] with sendmail and print a HTML with $message I strongly suggest to abandone formmail.pl, make a php script instead that specifically sends a mail with the data from the form (use php function sendmail() ) and then shows the response page with the content of that specific text box. That's really the easiest way If you called the message box 'message' the text will be in variable $message . A is best because: - all is done in one script, - you will learn how to do this - no use of long url and no dangers of too long text in that box of yours. (this socalled GET method (with the ? and variables in the URL) is limited in some older browsers and maybe even servers to sometimes only 256 characters) - this is the only proposal where you can do some validation in php before sending the mail. Disadvantage to formmail: formmail doesn't care if you rename your own form element names. Your own php script will probably not catch all form elements, unless if you check for all element names in PHP_POST_VARS - see PHP manual function.each.html and language.variables.external.html. ************************************************************* B. Modify the Perl Script (hard) [form.html] | | form action="formmail.pl" V [formmail.pl] adapt redirect here | | redirect: .php3?message=bla V [faq_confirm.php3] If you have access to the script and nobody minds you changing it, find this line in the formmail.pl : print "Location: $Config{'redirect'}\n\n"; This one calls a page mentioned in your form's textbox named 'redirect' (see formmail documentation). Now somehow add the textbox you need. It MIGHT look like this (i forgot about scope and all kinds of perl details). print "Location: $Config{'redirect'}". '?nameofyourtextbox=' "$Config{'nameofyourtextbox'}". "\n\n"; And hopefully variable $nameofyourtextbox in your redirect page.php contains the text. MIND YOU i think you have to change the textbox contents to prevent the spaces in the textbox (space would end the URL and you;ll end up with only the 1st word), so you will have to find the Perl equivalent of urlencode like this: &urlencode($Config{'nameofyourtextbox'}). Perl is more difficult to debug than PHP and i only give this to help you going. I will not test it. I have many doubts about the way perl handles qquotes and whether it is needed to escape the ?-mark. Find Perl gurus to make it work. Also check if your textbox even ends up in $config, maybe check the part just after "# Define the configuration associative array. ". ************************************************************* C. Adapt formmail.php (easy) [form.html] | | form action="formmail.PHP" V [formmail.PHP] adapt redirect here | | redirect url?message=bla V [faq_confirm.php3] find formmail.php instead of formmail.pl. I saw it hanging out there somewhere, someone translated the perl script to a php version. It's free!? Now it's less difficult. In the script find the forwarding line: it is probably near the words header("location: $redirect"). Now to add the textbox i think it would be something like this: $redirect .= '?nameofyourtextbox='.urlencode($nameofyourtextbox)."\n\n"; header("Location: $redirect"); exit; (in your first form: <FORM METHOD = 'POST' Name='.....' ACTION='http://path/formmail.php'> <input type='hidden' name='redirect' value='http://www.ahost.org/jstump/faq_confirm.php3'> <input type='text' name='nameofyourtextbox'> </form> ) For C you can consider to study sessions() and make a session remember the variable instead of clipping it to the URL, with the disadvantage of the GET method mentioned in A. ************************************************************* D Javascript [form.html] change to redirect?var=message with javascript | | form action="formmail.pl" V [formmail.pl] | | redirect?var=message V [faq_confirm.php3] Make a javascript which executes on submit, which safely adds the textbox to the redirect. Only works if the javascript works in the users' browser, just wanted to mention it. Probably a dangerous idea. _like_ this: <script language="javascript"> //<-- function addtextbox(){ document.formname.redirect.value = document.formname.redirect.value+ escape ( document.formname.yrtextbox.value) location.href="http://path/formmail.pl" // or .php exit; } //--> (where escape does what urlencode does in PHP) </script> and <FORM METHOD = 'POST' Name='formname' OnSubmit='addtextbox()'> <input type='hidden' name='redirect' value='http://www.ahost.org/jstump/faq_confirm.php3'> <input type='text' name='yrtextbox'> </form> ************************************************************* Jees, i surely hope you can use one of these brilliant ideas :-). Chris -------------------------------------------------------------------- -- C.Hayes Droevendaal 35 6708 PB Wageningen the Netherlands -- --------------------------------------------------------------------

« previous php.general (#36304) next »