Jump to content

not getting form variables


damiancds
 Share

Recommended Posts

I'm working on a recipe submission form, and they best way I can think of doing this is to have a form, where they put in the their contact info, recipe name, but, when it comes to the ingredients, and in a two part form, i would ask how many ingredients, and the second part (submitted to itself, would have a for loop to echo out the form textboxes. and have the final part, after entered, create a text file with all the info, and possibly send me a message when something was submitted.my problems are:I can't seem to grab the info from the first part to the second (everything seems to check out,variables in question : build_ingd and build_prep (from the form in the else condition)Code: (echo's were there for debugging)

<?php echo "<br> START"; $num_ingd = $_REQUEST['build_ingd']; $num_prep = $_REQUEST['build_prep']; echo "<br>num_ingd = ".$build_ingd; echo "<br>num_prep = ".$build_prep;if($num_ingd >= 1 && $num_prep >= 1){ echo "<br> IN IF"; $num_ingd = $_REQUEST['build_ingd']; $num_prep = $_REQUEST['build_prep']; echo "<br>num_ingd = ".$build_ingd; echo "<br>num_prep = ".$build_prep;	echo "		<form method='post' action='/recipes/submit.php'>				<fieldset id='fieldset_contact_info'>		<h3>Contact Information</h3>		<label for='fname' id='fnamel'>First Name:</label><input type='text' size='40' name='firstname' value='' id='fname'>		<label for='lname' id='lnamel'>Last Name:</label> <input type='text' size='40' name='lastname' value='' id='lname'>		<label for='email' id='emaill'>Email:</label><input type='text' size='40' name='email' value='' id='email'>		<input type='reset' value='Clear' class='button' id='reset1' onclick='return clear_fieldset('reset1')';>		</fieldset>				<fieldset id='fieldset_recipe_info'>		<h3>Recipe Information</h3>		<label for='rname'>Recipe Name:</label><input type='text' name='name' size='40' value='' id='rname'>		<label for='serves'>Serves:</label><input type='text' name='servings' size='40' value='' id='serves'>		<label for='prept'>Prep Time:</label><input type='text' name='prep_time' size='40' value='' id='prept'>		<label for='cookt'>Cooking Time:</label><input type='text' name='cook_time' size='40' value='' id='cookt' value='If Applicable'>		<label for='baket'>Baking Time:</label><input type='text' name='bake_time' size='40' value='' id='baket' value='If Applicable'>		<input type='reset' value='Clear' class='button' id='reset2' onclick='return clear_fieldset('reset2')';>		</fieldset>								<fieldset id='fieldset_ingredients_info'>		<h3>Ingredients</h3>";		$build_ingd = 59;		for ( $x = 1; $x <= $build_ingd; $x++)		{			echo "<label for='i_".$x."'>Ingredient ".$x.":</label> <input type='text' size='50' value='' name='ingredient_".$x."' id='i_".$x."'>";		}		echo "		<label for='i_99'>Ingredient 99:</label> <input type='text' size='50' value='' name='ingredient_99' id='i_99'>		<input type='reset' value='Clear' class='button' id='reset3' onclick='return clear_fieldset('reset3')';>		</fieldset>				<fieldset id='fieldset_prep_info'>		<h3>Preparation</h3>";		for ( $y = 1; $y <= $build_prep; $y++)		{			echo "<label for='p_".$y."'>Preparation Step ".$y.":</label> <input type='text' size='50' value='' name='prep_".$y."' id='p_".$y."'>";		}		echo "				<label for='p_99'>Step 99:</label> <textarea rows='1' cols='50' id='p_99'></textarea>		<input type='reset' value='Clear' class='button' id='reset4' onclick='return clear_fieldset('reset4')';>		</fieldset>								<fieldset id='fieldset_other_info'>		<h3>Other Information</h3>		<label for='other'>Other Information:</label><textarea rows='10' cols='50' id='other' title='Couldn't find where to put your other notes? Stick 'em in here, anything from what goes well with your recipe, to little tips about the recipe like substitutions or time-savers.'></textarea> 		<input type='reset' value='Clear' class='button' id='reset5' onclick='return clear_fieldset('reset5')';>		</fieldset>								<input type=Submit value='Submit Recipe' class='button'>		<input type='reset' value='Clear' class='button'>		</form>	";}else{ $num_ingd = $_REQUEST['build_ingd']; $num_prep = $_REQUEST['build_prep']; echo "<br> IN ELSE"; echo "<br>num_ingd = ".$build_ingd; echo "<br>num_prep = ".$build_prep;	echo "		<form method='post' action='/recipes/submit.php'>				<fieldset id='fieldset_builder_info'>		<h3>Contact Information</h3>		<label for='fname' id='build_i'>Nubmer of Ingredients</label><input type='text' size='40' name='build_ingd' value='' id='build_i'>		<label for='lname' id='build_p'>Number of Preparation Steps:</label> <input type='text' size='40' name='build_prep' value='' id='build_p'>		</fieldset>			<input type='submit' value='Continue' class='button'>		<input type='reset' value='Clear' class='button' id='reset1'>		</form>	";}?>

If anyone has a better way of doing this (though without javascript because i don't like the idea of it only working when someone else want's it to), give a shout, I probably hadn't thought of it yet.I've also thought about having a file upload form where they just upload a text file (or word document/ open office, whatever) but I'm not really sure about having it be secure. Also, if i did the upload option, I'd want to upload two things at once, the image and the actual recipe.I planned either way, to take the information and then hand code it into a new page

Link to comment
Share on other sites

  • 2 weeks later...

sorry about taking so long to get back to you, finally got done some of the other things I was doing.On your suggestion, I removed all but the first requests, so they are only requested once. The curious part is that I have an input form, and then it gets submitted to itself, and if the values are greater than 1, it shows the next part, which works. It seems to lose the value. I'm really at a loss here.

Link to comment
Share on other sites

if the values are greater than 1, it shows the next part, which works. It seems to lose the value.
I'm not sure what you mean by that, if you're trying to use the values again on another page you'll need to save them some how. If that's what you're trying to do, you can either print them into another form which can get submitted to the next page, or you can save them in the session and then access them on later pages.
Link to comment
Share on other sites

okay, a little background: The first part of the form asks how many ingredients there are, then takes that information to the second form and the second form is built with that many text boxes for however many ingredients. I'm not sure if my testing (if num > 1) actually test if it's longer(as in string length) or greater(higher in number)The first form submits to itself( as in the same page) where the basic logic is:

if( num > 1){      Show part 2 of the form where they put in all the info (which has a for loop running to build the textboxes) and submit}else{       Show part 1 (just asking for number of ingredients}

Also, at the end of all this, I plan on putting all the information into a text file (don't know if that matters, but I'll do that later, though I've already got that done, except for the user's inputs

Link to comment
Share on other sites

I AM SUCH A @%$!ing IDIOT...As it turns out, when I was requesting it, i used $num_ingd = $_REQUEST['build_ingd'];but when i did my comparing, output and form building, i used build_ingd as a variable not what I set it to.Now where's that dunce cap...again, thanks for the help and tolerance of stupidity...

Link to comment
Share on other sites

and i just put this together, nevermind

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><script type="text/javascript">/*<![CDATA[*//*---->*//*--*//*]]>*/</script> <style type="text/css"></style></head><body><?phpecho "<br> START";$num_ingd="";$num_prep="";if(isset($_REQUEST['build_ingd']) && isset($_REQUEST['build_prep']) && $_REQUEST['build_ingd'] >=1 && $_REQUEST['build_prep'] >=1){echo "<br> IN IF";$num_ingd = $_REQUEST['build_ingd'];$num_prep = $_REQUEST['build_prep'];echo "<form method='post' action='/recipes/submit.php'><fieldset id='fieldset_contact_info'><h3>Contact Information</h3><label for='fname' id='fnamel'>First Name:</label><input type='text' size='40' name='firstname' value='' id='fname'><label for='lname' id='lnamel'>Last Name:</label> <input type='text' size='40' name='lastname' value='' id='lname'><label for='email' id='emaill'>Email:</label><input type='text' size='40' name='email' value='' id='email'><input type='reset' value='Clear' class='button' id='reset1' onclick='return clear_fieldset('reset1')';></fieldset><fieldset id='fieldset_recipe_info'><h3>Recipe Information</h3><label for='rname'>Recipe Name:</label><input type='text' name='name' size='40' value='' id='rname'><label for='serves'>Serves:</label><input type='text' name='servings' size='40' value='' id='serves'><label for='prept'>Prep Time:</label><input type='text' name='prep_time' size='40' value='' id='prept'><label for='cookt'>Cooking Time:</label><input type='text' name='cook_time' size='40' value='' id='cookt' value='If Applicable'><label for='baket'>Baking Time:</label><input type='text' name='bake_time' size='40' value='' id='baket' value='If Applicable'><input type='reset' value='Clear' class='button' id='reset2' onclick='return clear_fieldset('reset2')';></fieldset><fieldset id='fieldset_ingredients_info'><h3>Ingredients</h3>";//$build_ingd = 59;for ( $x =1; $x <= $num_ingd; $x++){echo "<div><label for='i_".$x."'>Ingredient ".$x.":</label> <input type='text' size='50' value='' name='ingredient_".$x."' id='i_".$x."'></div>";}echo "<input type='reset' value='Clear' class='button' id='reset3' onclick='return clear_fieldset('reset3')';></fieldset><fieldset id='fieldset_prep_info'><h3>Preparation</h3>";for ( $y = 1; $y <= $num_prep; $y++){echo "<div><label for='p_".$y."'>Preparation Step ".$y.":</label> <input type='text' size='50' value='' name='prep_".$y."' id='p_".$y."'></div>";}echo "</fieldset><fieldset id='fieldset_other_info'><h3>Other Information</h3><label for='other'>Other Information:</label><textarea rows='10' cols='50' id='other' title='Couldn't find where to put your other notes? Stick 'em in here, anything from what goes well with your recipe, to little tips about the recipe like substitutions or time-savers.'></textarea><input type='reset' value='Clear' class='button' id='reset5' onclick='return clear_fieldset('reset5')';></fieldset><input type=Submit value='Submit Recipe' class='button'><input type='reset' value='Clear' class='button'></form>";}else{echo "<br> IN ELSE";echo "<br>num_ingd = ".$num_ingd;echo "<br>num_prep = ".$num_prep;echo "<form method='post' action=''><fieldset id='fieldset_builder_info'><h3>Contact Information</h3><label for='fname' id='build_i'>Nubmer of Ingredients</label><input type='text' size='40' name='build_ingd' value='".$num_ingd."' id='build_i'><label for='lname' id='build_p'>Number of Preparation Steps:</label> <input type='text' size='40' name='build_prep' value='".$num_prep."' id='build_p'></fieldset><input type='submit' value='Continue' class='button'><input type='reset' value='Clear' class='button' id='reset1'></form>";}?></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...