Forum Moderators: coopster
I have at least two separate forms for customer experience.
The first form contains just simply data collection about location of the customer.
The next form is a email contact form to fill out their contact details for sending via 'mail( ... )' function.
These two html forms are separated by php code and executed via submit buttons (php).
My problem is:
In the first form, they enter their city.
==============================================================
(Pure HTML)
<input type="text" name="City" class="input" maxlength = "35" size="35" />
==============================================================
Then they submit this. Then the next php executes, opening the next HTML form.
I can echo:
==============================================================
$city = $_POST['City']; // debugging
echo ("City :". $city); // debugging
==============================================================
This works. It echos what ever is inserted into the City textbox.
However, by the time this form has been submitted, and the next php code executes for the user to send the contact info via php mail() function as seen in the below example
==============================================================
$city = htmlentities(strip_tags($_POST['City']));
$message = "Event City: $city \n
$blah \n, $moreblah.... "
mail($to, $message, etc....)
==============================================================
the $city variable is empty!
What can i do to fix this with out introducing a new .php file.. (hence the CMS has trouble with this, my lack of knowledge hehe)
Thanks in advance.
You could try doing the sanitisatin in two stages
$city = strip_tags($_POST["city"]);
$city = htmlentities($_POST["city"]);
Another aproach would too to GET the value then sanitise
$city = $_POST['City'];
echo"$city"; //make sure we got it.
$city = strip_tags($city);
$city = htmlentities($city);
Mack.
IOW:
form1.html POSTs to processform1.php and on the same page as processform1.php is the HTML for form2.html? If this is the case, then it's easy...
Pass the city information to the second form as a hidden input, so you can continue passing it to the 3rd form:
<input type="hidden" name="City" value="<? htmlentities(POST['City']); ?> />
##### @ ##### @ #####
If they're not on the same physical page, they're probably should IMO, or are going to need to be for an easy solution to this issue. (If I'm understanding correctly.) You could also solve the issue via cookie if they are required, or with a database, but you're really complicating a simple issue with that type of system and personally, I'd be tempted to put all the php processing and forms together on a single page, so you can easily pass values from one form to another via POST using hidden inputs.
<?php
if($_POST['form1_submitted']=="Yes") {
/* process form1 */
$show_html="The HTML for form2";
}
elseif($_POST['form2_submitted']=="Yes") {
/* process form2 */
$show_html="The HTML for form3";
}
elseif($_POST['form3_submitted']=="Yes") {
/* process form3 */
$show_html="The HTML for the thank you page";
}
else {
$show_html="The HTML for form1";
}
echo $show_html;
* You could even use includes for the HTML if you wanted to get tricky. ;)
<added>
In 'straight php' to build the HTML more efficiently, you would probably use something like:
$show_html="<form blah stuff>";
$show_html.="<input type=\"hidden\" name=\"City\" value=\"". htmlentities(POST['city'])."\" />";
OR
$show_html="<form blah stuff>";
$show_html.="<input type=\"hidden\" name=\"City\" value=\"". htmlentities($city)."\" />";
If you have already set $city from the POST.
** You could probably also play around with the order of the processing and do some error checking on each form, and if the checks don't work out (IOW there is an entry error) you could then redisplay the form they just submitted with the values they entered and a little coaching on what to do, so it is submitted correctly the next time.
</added>
<input type="hidden" name="City" value="<? $city = htmlentities(strip_tags($_POST['City'])); echo ($city); ?>" />
this is the only way after testing that it would work.
I had to echo within the hidden tag.
then in the final section for the mail() i had to repeat $city = $_POST['City']; code.
It now works as i desired.
THANK YOU :-)