I have working on this for hours and searched the net since last night but to no avail. I am trying to collect multiple options selected from a dropdown menu in a form and echo it into the textarea of the form on the next page.
I am able to echo the multiple options but cannot figure out how to echo the selectted options directly into the textarea of the form on the next page. Please help.
Here is the form..
<html><head>
</head><body>
<center><form action="92.php" method="post">
<select name="cat[]" size="9" required multiple><option value="Africa">Africa</option>
<option value="App">App</option>
<option value="Art">Art</option></select><br /><br />
<input type="submit" name="submit" value="Submit">
</form></center>
</body></html>
Here is the second form 92.php...
<?php
$cat = $_POST['cat'];
foreach ($cat as $s) {
echo "<center><form action=max21.php method=post>
Your ID: <input class=text size=9 name=us type=text readonly><br /><br />
<textarea rows=4 cols=35 id=ans name=ans maxlength=140>$s</textarea><br /><br />
<input type=submit id=submit value=Submit></form></center>";
}
?>
Thanks a ton in advance!
<center><form action=max21.php method=post>
Your ID: <input class=text size=9 name=us type=text readonly><br /><br />
<textarea rows=4 cols=35 id=ans name=ans maxlength=140>
<?php
$cat = $_POST['cat'];
foreach ($cat as $s) {echo $s. ' ';
}
?>
</textarea><br /><br />
<input type=submit id=submit value=Submit></form></center>
This should work. Simple, start loop INSIDE textarea. The rest on 92.php page is ordinary HTML - no need to echo form.
Related
I have a form for adding products and their detail to a mysql db.
I have another form that shows the products where I can remove the product from the db, I can also hide or show the product in the website.
I need to be able to edite the product details too. Is there any way that when I choose to edit a products I can get it details to appear in the first form again? The form is for adding details so can it be used to edit them too?
This is my code for first product adding form.
<form class='productsaddform' action='productsadd.php' method='post'
enctype='multipart/form-data' name='image_upload_form' id='image_upload_form'>
<?php
include '../inc/categorydropdown.php';?>
<p><b>Choose Image</b><br /><input name="image_upload_box" type="file"
id="image_upload_box" /></p>
<b>Name</b><br /><input type=text name="aname" /><br />
<b>Brand</b><br /><input type=text name="abrand" /><br />
<b>Code</b><br /><input type=text name="acode" /><br />
<b>Description</b><br /><textarea rows="12" cols="40" name="adescription"></textarea>
<br />
<b>Product Spec</b><br /><textarea rows="12" cols="40" name="aspec"></textarea><br />
<b>Price</b><br /><input type=text name="aprice" /><br />
<p><label for="cat">Category</label>
<select name="cat" id="cat">
<?php echo $op;?>
</select><br />
<label for="subcat">Subcategory</label>
<select name="subcat" id="subcat"> </select></p>
<br />
<br />
<input type='submit' id='submit' name='submit' value='Add Product' />
<input type='hidden' value='new' /><br />
<?php include '../inc/add_products.php'; ?>
</form>
And this is the form to display the products
<form class='productsremoveform' action='productsadd.php' method='post'>
<?php include '../inc/categorydropdown.php'; ?>
<?php include '../inc/remove_products.php'; ?>
<span class='formheading'>Remove/Hide/Show Products</span><br /><br />
<p><label for="cat">Category</label>
<select name="cat" id="removecat"> <?php echo $op;?> </select><br />
<label for="subcat">Subcategory</label>
<select name="subcat" id="removesubcat"> </select>
<input type='submit' name='show' value='Show' /> </p>
<?php
include '../inc/connect.php';
if(isset($_POST['show'])){
$subcat = intval($_POST['subcat']);
$q = "SELECT * FROM products WHERE subcat = $subcat";
$result = $link->query($q);
if($result){
while($row=mysqli_fetch_array($result)){
echo "<div class='removeproducts'>";
echo "<input type='checkbox' name='remove[{$row['id']}]' value='Remove'>Remove";
echo "<br />";
echo "<input type='checkbox' name='edit[{$row['id']}]' value='Edit'>Edit";
echo "<br />";
if ($row['status'] == 1){
echo"<input type='checkbox' name='hide[{$row['id']}]' value='Hide'>Hide";
echo "<br />";
}
if ($row['status'] == 2){
echo"<input type='checkbox' name='show[{$row['id']}]' value='Show'>Show";
echo "<br />";
}
echo "<br />",
"<span class='productthumbcode'>",
"{$row['code']}",
"</span>",
"<div id='thumb'>",
"<img class='resizedimage' src='{$row['image']}' alt='{$row['name']}' />",
"</div>",
"</div>";
}
echo "<br style='clear:both' />";
}
else{
echo mysqli_error();
}
}
?>
<input type='submit' id='submit' name='submit' value='Submit' />
</form>
EDIT;
This is the form on my new edit page.How do i get the relevent details from the db into the input values?
<?php if (isset($_GET['pid'])) { ?>
<form class='productsaddform' action='edit_products.php' method='post'
enctype='multipart/form-data' name='image_upload_form' id='image_upload_form'>
<span class='formheading'>Edit Product</span><br /><br />
<p><b>Choose Image</b><br /><input name="image_upload_box" type="file"
id="image_upload_box" /></p>
<b>Name</b><br /><input type="text" name="aname" />
<br />
<b>Brand</b><br /><input type=text name="abrand" /><br />
<b>Code</b><br /><input type=text name="acode" /><br />
<b>Description</b><br /><textarea rows="12" cols="40" name="adescription"></textarea>
<br />
<b>Product Spec</b><br /><textarea rows="12" cols="40" name="aspec"></textarea><br />
b>Price</b><br /><input type=text name="aprice" /><br />
<input type='submit' id='submit' name='submit' value='Add Product' />
<input type='hidden' value='new' /><br />
<?php include '../inc/edit_products.php'; ?>
</form>
<?php } ?>
This is what i have now, but the form doesnt display now
<?php if (isset($_GET['pid'])) {
$q = mysqli_query($link, "SELECT * FROM products WHERE id = '".$_GET['pid']."'") or
die (mysqli_error());
$row = mysqli_fetch_array($q); ?>
<form class='productsaddform' action='edit_products.php' method='post'
enctype='multipart/form-data' name='image_upload_form' id='image_upload_form'>
<span class='formheading'>Edit Product</span><br /><br />
<p><b>Choose Image</b><br /><input name="image_upload_box" type="file"
id="image_upload_box" /></p>
<b>Name</b><br /><input type="text" name="aname" value=<?php"$row['name'];"?> />
<br />
<b>Brand</b><br /><input type=text name="abrand" /><br />
<b>Code</b><br /><input type=text name="acode" /><br />
<b>Description</b><br /><textarea rows="12" cols="40" name="adescription"></textarea>
<br />
<b>Product Spec</b><br /><textarea rows="12" cols="40" name="aspec"></textarea><br />
<b>Price</b><br /><input type=text name="aprice" /><br />
<input type='submit' id='submit' name='submit' value='Add Product' />
<input type='hidden' value='new' /><br />
<?php include '../inc/edit_products.php'; ?>
</form>
<?php } ?>
EDIT:
Now I want to be able to search products by code in my first form then have that products details displayed in the form in my edit_product page as it is when i edit a product as we sorted. Any idea how to go about this?
This wouldn't be the necessarily the cleanest way to do it, but you could get the information from the db (as you would normally), put it into an array and for each input have something like this:
<input type="text" name="aname" value="<?php echo (isset($array['name'])) ? $array['name'] : ''; ?>" />
Basically, it's an inline if statement that checks to see if the variable is set and if it is, it sets the value of the input to that.
Hope this helps!
If you have any questions on this, let me know :)
EDIT
To answer your question from the comments you could have a link for each product which then takes you to an edit product page e.g.
Link:
AND then just have a page similar to you first page that checks to see if the get variable is set.
I have a form where I would like to use _POST data to submit check box values. My problem is there are already post values in my current page. When I submit the form it is returning the current post values instead of the ones I want, which gives me the Notice: Undefined index message.
Basically this form is to compare selected products, but in the current post values it has the product information along with order by values. Is there a way to just submit my new form's information on its own?
Thank you
EDIT
Well, here's the thing about my code, I am using a shopping cart called Virtuemart. I've added the code below minus all the other stuff which don't effect the form.
Product File
// Code here for Template file for individual items in category
//creating checkbox for comparison form
echo "<input type =\"checkbox\" name=\"fruit[]\" value=\"".$product_sku."\" />
<label for=\"".$product_name."\"> ".$product_name."</label>";
Category File
//all other forms on this page
<form action="items/index.php" method="get" name="results" target="_blank">
<input class="inputbox" name="search" id="item-search" type="text" value="Search"></td><td>
<input type="image" class="sub-button" src="/search.png" alt="submit" name="submit" value="search">
</form>
<form action="index.php" method="get" name="order">
Sort by:
<select class="inputbox" name="orderby" onchange="order.submit()">
<option value="product_list" >Select</option>
<option value="product_name" selected="selected">Product Name</option>
<option value="product_price" >Price</option>
<option value="product_cdate" >Latest Products</option>
</select>
<script type="text/javascript">//<![CDATA[
document.write(' <input type="hidden" name="DescOrderBy" value="ASC" /><img src="images/sort_asc.png" border="0" alt="Ascending order" title="Ascending order" width="12" height="12" />');
//]]></script>
<noscript>
<select class="inputbox" name="DescOrderBy">
<option value="DESC">Descending order</option>
<option selected="selected" value="ASC">Ascending order</option>
</select>
<input class="button" type="submit" value="Submit" />
</noscript>
<input type="hidden" name="Itemid" value="89" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="page" value="shop.browse" />
<input type="hidden" name="category_id" value="0" />
<input type="hidden" name="manufacturer_id" value="0" />
<input type="hidden" name="keyword" value="" />
<input type="hidden" name="keyword1" value="" />
<input type="hidden" name="keyword2" value="" />
<div id='limitbox'> Display #
<select class="inputbox-reg" name="limit" size="1" onchange="this.form.submit();">
<option value="6" >6</option>
<option value="18" >18</option>
<option value="30" >30</option>
</select>
<input type="hidden" name="limitstart" value="0" /></div> <noscript><input type="submit" value="Submit" /></noscript>
<!-- PAGE NAVIGATION AT THE TOP <br/>
<div style="text-align:center;"> </div>
-->
</form>
// all other forms end
Form I want to pass values from
echo"<form method=\"POST\" name=\"compare\" id=\"compare\" action=\"http://localhost/comparepage/\">";
//TEMPLATE FILE HERE THAT GENERATE PRODUCTS FROM PRODUCT FILE CODE ABOVE.
//Basically it has foreach statements to generate all products
echo "<input type=\"submit\" name=\"submit\" value=\"Compare\" onClick=\"document.compare.submit()\" >";
echo "</form>";
I've changed POST to GET just to get the values that are being passed and in the next page I see a bunch of values in the url.
Try putting the fields of the second form within separate <form> tags
Form 1:
<form method='post' action='/process.php'>
<input name='town' type='text'/>
<input name='country' type='text'/>
<input type='submit'/>
</form>
Form 2:
<form method='post' action='/process.php'>
<input name='gender' type='text'/>
<input name='state' type='text'/>
<input type='submit'/>
</form>
If you submit form 1, $_POST will contain town, country
If you submit form 2, $_POST will contain gender & state
As suggested, some code and more details would be helpful. But if you have multiple form fields on the same page, and depending on the action, you want to submit different sets of those fields, then just wrap them in different <form></form> elements. A POST submit only submits the form fields contained with that particular block.
So you could have:
<form name='form1' method='POST' action='#'>
<input type='hidden' name='field1' value='true' />
<input type='submit' name='submit' value='Submit' />
</form>
<form name='form2' method='POST' action='#'>
<input type='hidden' name='field1' value='false' />
<input type='submit' name='submit' value='Submit' />
</form>
If the first submit button is clicked, $_POST['field1'] = 'true', else = 'false'
I cannot seem to find an answer to my question on the internet. I can't help but think it is a stupid mistake, however I have gone over my code at least 6 - 7 times and even took a break to look at it with fresh eyes. If someone could look it over for me, that would be super sweet!
<div id="input_alignment" style="font-size:20px">
<?php
if(!($Valid_Profile == true)){ ?>
...Form that has no issues
<?php }
else{ ?>
<form action="Redact_Profiles.php" style="font-size:19px" method="post">
<input type="hidden" value="<?php echo $Valid_Profile ?>" name="Valid_Profile" />
<input type="hidden" value="<?php echo $Username ?>" name="Username" />
<input type="hidden" value="<?php echo $Password ?>" name="Password" />
<br />
<?php echo $Profile_Username . "<br>"; ?>
<input type="submit" style="font-size:9px" value="Edit" name="" /> <?php echo $Profile_Password . "<br>"; ?>
<br />
<br />
......<br />
<input type="submit" style="font-size:9px" value="Edit" name="" /> <?php echo $Profile_First_Name . "<br>"; ?>
<input type="submit" style="font-size:9px" value="Edit" name="" /> <?php echo $Profile_Last_Name . "<br>"; ?>
<?php echo $Profile_EMail . "<br>"; ?>
<br />
<input type="submit" style="font-size:9px" value="Edit" name="" /> <?php echo $Profile_Location . "<br>"; ?>
<input type="submit" style="font-size:9px" value="Edit" name="" /> <?php echo $Profile_Referee_Password . "<br>"; ?>
<input type="submit" style="font-size:9px" value="Edit" name="" />
</form>
<?php }
?>
</div>
The very last two submit buttons don't work. When I take away the php containing the $Profile_Location and $Profile_Referee_Password, the submit buttons work.
Sorry, what I mean by Doesn't work means that the submit button isn't responding. The page doesn't re-load, and it acts like the submit button is disabled. The submit button looks enabled, but it is like it doesn't want to "press".
After 2 days of headache I have figured it out: When a submit button is outside the bounds of the height and width of any "div", it will not function like a button, but more like a picture. So as a good practice, when a button is not functioning properly, check to see if it is literally "outside" of the container you put it in.
This error doesn't present itself in viewing the source page, or in any error checking. However, if it does, I don't know about it. I am using a Mac, Safari 6, and CS5 Dreamweaver, if anyone is interested.
I have a submit buttom like this:
<?php
echo "<form id='abottom' method='post'>
<button name='".$row3[$ww]."' id='".$row3[$ww]."' type='button'>More Details</button>
<input type='hidden' name='action' value='".$row3[$ww]."' />
</form>";
?>
and ids are working right of the buttons of the table rows (by Firebug). But when I want to output $_POST in a query while loop, then no one of those works for me:
<?php
echo $_POST[$row3[$ww]]." <br />";
echo $_POST['$row3[$ww]']." <br />";
echo $_POST[$row3['$ww']]." <br />";
echo $_POST["$row3[$ww]"]." <br />";
echo $_POST[$row3["$ww"]]." <br />";
echo $_POST[$row3['".$ww."']]." <br />";
?>
Which one will be the right? Those above didn't work for me.
$row3 // is a fetch result of sql3
$ww // is table rows name on which one is selected
Raw HTML output example:
<form name ='dets' method='POST'>
<input class = 'showt' name ='6' id ='6' type='button' value= 'More Details'></input>
<input type='hidden' name='data' value='6' />
<noscript><input type='submit' value='Submit'></noscript>
</form>
Much better for debugging and finding the correct variable would be to use
<?php
echo '<pre>';
var_dump($_REQUEST);
echo '</pre>';
to see which variables arrive at your script.
Update:
I think, what you need is:
<form method="post">
<input type="hidden" name="data" value="<?php echo $row3[$ww]; ?>"/>
<input type="submit" value="More Details"/>
</form>
<?php
echo $_POST['data']];
And if you have several values in $row3 then add extra forms like this:
<form method="post">
Second Data
<input type="hidden" name="data" value="<?php echo $row4[$ww]; ?>"/>
<input type="submit" value="More Details"/>
</form>
Always keep the name of the hidden input the same (data)!
Your button has type="button". This should be type="submit" or it won't submit the form it is in.
Your PHP code should look like this:
<?php
echo "<form id='abottom' method='post'>
<button name='".$row3[$ww]."' id='".$row3[$ww]."' type='submit'>More Details</button>
<input type='hidden' name='action' value='".$row3[$ww]."' />
</form>";
?>
I'm using post to send info to my page. I'm using that to create a variable and pass that variable to a new <input>. However, when I submit the new form, the variable is blank.
The variable is created from post data:
$timenotstarted = $_POST["placeholder"];
Then inline in the html:
<form name="newform" method="post" action="insert.php">
<input type="text" name="timerset" value="<?php echo $timenotstarted; ?>">
<input type="submit" value="Submit"><
</form>
When the new form is submitted, the variable whose name="timerset", is blank.
When I echo $timenotstarted on the same page that this form is,
it will show its value. It just "goes away" when I try to use it in the new form.
Edit: Here's what's happeneing:
Not sure if this helps: http://forexguruguide.com/timer/insert.php
And here's the whole shabang:
<?php include 'connect.php';
$timenotstarted = $_GET["placeholder"];
$start = $_POST["start"];
$timerset = $_post["timerset"];
echo $timenotstarted . '<br />';
echo $start . '<br />';
echo $timerset . '<br />';
?>
<form name="timeform" method="get" action="insert.php">
<select name="placeholder">
<option value="1">1 min</option>
<option value="3">3 min</option>
<option value="5">5 min</option>
<option value="10">10 min</option>
</select>
<input type="submit" value="Set timer">
</form>
<form name="startform" method="post" action="insert.php">
<input type="hidden" value="1" name="start">
Timer set to: <input type="text" name="timerset" value="<?php print $timenotstarted?>">
<input type="Submit" value="Start Timer">
</form>
<?php
if ($start==1) {
$target = time() + ($timerset * 60);
mysql_query("UPDATE countdowntimer SET target='$target' WHERE id='0'");
mysql_query("UPDATE countdowntimer SET timenotstarted='null' WHERE id='0'");
echo 'Timer started' . '<br />';
echo $target . '<br />';
echo time(); }
else if (!empty($timenotstarted)) {
$timenotstarted .= ":00";
mysql_query("UPDATE countdowntimer SET timenotstarted='$timenotstarted'");
echo 'Timer set to: ' . $timenotstarted; }
else {
echo 'Set the timer then start the timer'; }
?>
shouldn't use POST for that. It's GET's job
<? if (!isset($_GET['placeholder'])): ?>
<form>
Enter placeholder:
<input type="text" name="placeholder" value="">
<input type="submit" value="Submit">
</form>
<? else: ?>
<form name="newform" method="post" action="insert.php">
<input type="text" name="timerset" value="<?=htmlspecialchers($_GET["placeholder"])?>">
<input type="submit" value="Submit">
</form>
<? endif ?>
It's not clear to me what you're doing wrong from your post, but here's the basics on how to do it right:
page1.php
<form action="page2.php" method="post">
<input type="hidden" name="foo" value="bar"/>
<input type="submit"/>
</form>
page2.php
<form>
<input name="foo2" value="<?php echo htmlspecialchars($_POST['foo']); ?>"/>
</form>
So, here's what FINALLY worked. I just rebuilt the second form...:
<form name="testyboy" method="post" action="insert.php">
<input type="hidden" value="1" name="start">
<input type="hidden" value="<?php print $timenotstarted?>" name="testyboy">
<input type="submit" value="Start Timer">
</form>
It's identical. I have no idea what made it work....
Anyways thanks for everyone's efforts! Its much appreciated.