How to add data from a previous page to formmail

Hi,
I’m using matt’s formmail contactform which works fine. Since I’m selling products I would like people who are viewing these products having the possibilty to request information on a product instantly. So the name or code of this product should already be completed on the contactform without having to choose from a dropbox by the viewer. E.g. when the visitor is on the product page “xxx” and would like to have information on this particular product now he would have to choose the contactbutton which brings him to the formmail contactform page, where he has to select the item from a dropdown list. Since there are many different items the dropdown list will be huge. So more convenient would be if the product isself is already pre-selected and the visitor only has to complete the form with his contactinformation. I guess I need to pass a variable containing the productcode from the previous page (=the product page) into formmail one way or another but don’t manage to fix that.
I’m not a programmer so any help would be very much appriciated
Terry

Hi Terry, welcome to the forums!

I’m not sure what you’re referring to here, do you have a link you could provide?

Basically what you’ll need to do is add a hidden field to the form that contains the product name or code that you want to be included in the email:

<input type="hidden" name="product_name" value="supervax2000">

Then you’ll need to alter the script slightly to check for and include the new form field in the email. We can help you with this if you provide a link to the script (or post the script in your reply).

Hi Fretburner

Thx for your quick reply.

This is the script I’m using:

<FORM ACTION="/cgi-bin/FormMail.pl" METHOD="POST">

                  <TABLE BORDER="0" cellpadding="2" cellspacing="0" width="95%">
                    <TR>
                      <TD>Offerte aanvraag betreft:<br>
                        <select name="through">
                          <option value="Geen">Maak een keuze ----></option>
                          <option value="Systeemwanden">Systeemwanden</option>
                          <option value="Projecttapijt">Projecttapijt</option>
                          <option value="Projectmeubilair">Projectmeubilair</option>
                          <option value="Overige projectinrichting">Overige projectinrichting</option>
                          <option value="Maatwerk meubilair">Maatwerk meubilair</option>
                          <option value="Afbouwpakketten">Afbouwpakketten</option>
                          <option value="Projectmanagement">Projectmanagement</option>
                          <option value="Ontwerp">Ontwerp</option>
                          <option value="Het Nieuwe Werken">Het Nieuwe Werken</option>
                          <option value="Akoestische design wanden">Akoestische design wanden</option>
                          </select>

                        <BR></TD>
                      </TR>
                    <TR>
                      <TD VALIGN="TOP"><INPUT TYPE="TEXT" NAME="bedrijf" SIZE="30">

                      Bedrijf
                      <BR></TD>
                      </TR>
                    <TR>
                      <TD VALIGN="TOP"><INPUT TYPE="TEXT" NAME="realname" SIZE="30">

                      Naam *
                      <BR></TD>
                      </TR>
                    <TR>
                      <TD><INPUT TYPE="TEXT" NAME="phone" SIZE="30">
                      Telefoonnummer
                      <BR></TD>
                      </TR>
                    <TR>
                      <TD><input type=text name="email" SIZE="30">

                      E-mail *
                      <BR></TD>
                      </TR>
                    </TABLE>
                  <BR>
                  <TABLE BORDER="0" cellpadding="4" cellspacing="0" width="90%">
                    <TR>
                      <TD VALIGN="TOP">Omschrijving<BR></TD>
                      </TR>

                    </TABLE>
                  <TEXTAREA NAME="comments" ROWS="6" COLS="35" wrap="soft"></TEXTAREA>
                  <p> * verplichte velden<br>
                    &nbsp;
                    <input name="submit" type="submit" id="submit" value="Verstuur">
                    <input name="reset" type="reset" id="reset" value="Wissen">


             <input type="hidden" name="recipient" value="info@example.com">

             <input type=hidden name="required" value="email,realname">
            <input type=HIDDEN name="subject" value="reactie via website example.com">
            <input type=hidden name="missing_fields_redirect" value="http://www.example.com/error.htm">
            <input type=hidden name="redirect" value="http://www.example.com/thanks.htm">

                  </form>

This script I’m using in a different website and works fine for that. In this case the visitor can select the subject through the dropdown menu when completing the form.
In the new website I’m building however I would like the form already completed with the subject, which is the productname from the previous page. E.g. the visitor is watching several products on whatever page and would like to receive information about product “xxx”. When clicking on the “xxx” image or link he should be forwarded to the contactform (or the contactform should pop-up) mentioning already product “xxx”. So only thing he needs to do is completing the form (name, email adress, telephone and comment). When sent I would like to see the product involved and remaining contactinformation.
When I have to contruct seperate contactforms for each product it probably would work as well, but that doesn’t make sense to me. My idea is to have a variable "product_name=“xxx” produced when clicking the link to the contactform which will be used in the form. So the link itself contains the name of the product and will be prepopulated in the form skipping the dropdown menu to selct the subject. Actually the dropdown menu would be otiose.

Hi Terry,

Sorry for not getting back to you sooner, for some reason I didn’t get an email notification of your reply.

If you have PHP available on your server then it’s quite straightforward to do what you want.
You can construct your contact form links to be something like /contact.php?product_name=supervax2000 and then, on your contact page:


<?php
// (At the top of the page)
// remove any HTML tags etc from input
$product_name = filter_input(INPUT_GET, 'product_name', FILTER_SANITIZE_STRING);
?>

<!-- Inside your form tags -->
<input type="hidden" name="subject" value="Information request for: <?php echo $product_name ?>">

Hi Fretburner,

I replied to you earlier but somehow this reply doesn’t show up I discovered!

I have tried your suggestion but am still not able to get this working.

I’ve changed the formmail
<FORM ACTION=“/cgi-bin/FormMail.pl” METHOD=“POST”>

into

<FORM ACTION=“email.php” METHOD=“POST”>

added the email.php and changed the form to work with the email.php
After the alterations everything works o.k. and same as before the change: When the visitor fills-in the form and sends it I receive the email with all the options filled in by the visitor (like before).

Unfortunetaly I don’t manage to get the form pre- filled-in with the requested product from which the visitor has left (e.g.Superfax2000) before he/she entered the contactpage.

Should the line
/contact.php?product_name=supervax2000
be somewhere on the productpage e.g. Supervax2000.html?

Where should I put the PHP code
<?php
// (At the top of the page)
// remove any HTML tags etc from input
$product_name = filter_input(INPUT_GET, ‘product_name’, FILTER_SANITIZE_STRING);
?>

<!-- Inside your form tags –>
<input type=“hidden” name=“subject” value=“Information request for: <?php echo $product_name ?>”>

I guess I have to adapt the email.php as well.

I tried several ways to adapt/add the lines but still see not output in the email I receive ones the request has been sent.

Please help.
Kind regards
Terry