This code generates multiple form associated with each product and its id.
But at html side only first is working. When I inspected the page I came to know that this code only generates form for first product only. Anyone Else faces this?
for ( $b = 0; $b < sizeof( $id ); $b++ ) {
echo "
<form action='Post.php' method='GET'>
<div class='form-group' style='display:none' id='$id[$b]'>
<label class='control-label'>Message</label>
<input type='text' name='id' value='$id[$b]'style='display:none'>
<input type='text' name='nam' value='admin 'style='display:none'>
<textarea type='text' class='form-control ' rows='4' col='10' name='mess' >
</textarea>
<input style='margin-top:10px' type='submit' class='btn btn-info' value='Submit'>
</div>
</from>";
}
You seem to close your form tag with 'from'.
change /from to /form
Related
Hei. I would very much appreciate some help with this. I am creating a very simple "find and replace" application to generate links. I am using the code below to do this.
It now replaces the word "chocolate" with anything I'd like. But i would also like to change other words within the same text with the push of the same button.
Forexample; if i would like to change the word "loves" to "hates" as well.
How would i do this? Appreciate all the help i can get.
<?php
$offset=0;
if(isset($_POST['text']) && isset($_POST['searchfor']) && isset($_POST['replacewith']))
{
$text=$_POST['text'];
$search=$_POST['searchfor'];
$replace=$_POST['replacewith'];
$search_length=strlen($search);
if(!empty($text)&&!empty($search)&&!empty($replace))
{
$strpos=strpos($text,$search);
$text=substr_replace($text,$replace,$strpos,$search_length);
echo $new = str_replace(' ', '%20', $text);
}
else
{
echo 'pls fill in all fields';
}
}
?>
<form action='index.php' method='POST'>
<textarea name='text' style="display:none;" rows='6' cols='30'>http://andy.com/loves/chocolate/cake</textarea><br><br>
<input type='hidden' value= 'chocolate' name='searchfor'><br><br>
Replace the word chocolate with:</br>
<input type='text' name='replacewith'><br><br>
<input type='submit' value='find and replace'>
</form>
You can use arrays in str_replace, so this code will work using 2 comma separated valus in the input field:
$offset=0;
if(isset($_POST['text']) && isset($_POST['searchfor']) && isset($_POST['replacewith']))
{
$text=$_POST['text'];
$search=explode(",",$_POST['searchfor']);
$replace=explode(",",$_POST['replacewith']);
var_dump($replace);
$text=str_replace($search,$replace,$text);
echo $text;
}
<form action='#' method='POST'>
<textarea name='text' style="display:none;" rows='6' cols='30'>http://andy.com/loves/chocolate/cake </textarea><br><br>
<input type='hidden' value= 'chocolate,cake' name='searchfor'><br><br>
Replace the word chocolate with:</br>
<input type='text' name='replacewith'><br><br>
<input type='submit' value='find and replace'>
If you want to use 2 (or more) input fields use this code:
$offset=0;
if(isset($_POST['text']) && isset($_POST['searchfor']) && isset($_POST['replacewith']))
{
$text=$_POST['text'];
$search=explode(",",$_POST['searchfor']);
$replace=array($_POST['replacewith'],$_POST['replacewith2']);
var_dump($replace);
$text=str_replace($search,$replace,$text);
echo $text;
}
<form action='#' method='POST'>
<textarea name='text' style="display:none;" rows='6' cols='30'>http://andy.com/loves/chocolate/cake </textarea><br><br>
<input type='hidden' value= 'chocolate,cake' name='searchfor'><br><br>
Replace the word chocolate with:</br>
<input type='text' name='replacewith'><br>
Replace the word cake with:</br>
<input type='text' name='replacewith2'><br><br>
<input type='submit' value='find and replace'>
so I have a form. The form consists of 10 lines by default. It goes like this:
<form method="post" action="actionhere">
<?php
for($i=0; $i<10;$i++) {
?>
<div class='clone_me'>
<span>Line <?php echo $i;?></span>
<input type='checkbox' name='ck_<?php echo $i;?>'/>
<input type='text' name='tx_<?php echo $i;?>'/>
</div>
<?php } ?>
<input type='submit' name='submit' value='Submit'/>
</form>
So inside the form, we will have 10 rows of checkbox+textbox.
What I'm trying to make is, I want to place a button to add new row (the checkbox+textbox). Now, problem is, I need the $i value (since it's form the for loop). Is that possible that when we click the add row button, the value of $i that we set inside for loop be incremented by 1 on each click? I know we can clone the div using jquery, but how about the $i value?
I think you are doing it in wrong way you do not need $i value inside name attribute you have to use array for it for example
<form method="post" action="test.php">
<div class='clone_me'>
<span>Line 1</span>
<input type='checkbox' name='ck[]'/><!--this field should menditory-->
<input type='text' name='tx[]'/>
<span>Line 2</span>
<input type='checkbox' name='ck[]'/><!--this field should menditory-->
<input type='text' name='tx[]'/>
</div>
<input type='submit' name='submit' value='Submit'/>
</form>
Now implement this code in actionhere.php
<?php
$cks = $_POST['ck'];
$txs = $_POST['tx'];
foreach($cks as $key => $ck) {
echo $ck."<br>";
echo $txs[$key]."<br>";
}
?>
Well, basically no. Your PHP script is already over when the html has been generated. So you can't rely anymore on PHP. But you don't need to make it explicitly appear in your html.
You should count the rows using jquery :
var i = $('form').find('.clone_me').length
and then add a new row using javascript again :
$('form .clone_me:last').clone().insertAfter('form .clone_me:last');
<input type='hidden' name='counter' id='counter'/>
<input type='checkbox' name='chk' id='chk'/>
<?php
$counter=$_POST['counter'];
for($i=0;$i<=$counter;$i++)
{
$chk=$_POST['chk'.$i];
// Your Insert Code Here
}
?>
may be this can be but have some limit
if you have no problem with page reload the you can do it is:-
by this way your page will reload and the value in textbox and checkbox will gone:---:)
every time new page generate and send by server to client browser
<?php
if(isset($_POST['submit'])){
$ends = $_POST['ttl_rows'];
}else{
$ends = 10;
}
?>
<form method="post" action="#">
<?php
for($i=1 ; $i<$ends;$i++) {
?>
<div class='clone_me'>
<span>Line <?php echo $i;?></span>
<input type='checkbox' name='ck_<?php echo $i;?>'/>
<input type='text' name='tx_<?php echo $i;?>'/>
</div>
<?php } ?>
<input type='hidden' name='ttl_rows' value='<?php echo ($i+1); ?>'/>
<input type='submit' name='submit' value='Submit'/>
</form>
I am trying to make a like button for posts on my website.
PHP for like query (d_db_update is
function d_db_update($string) {
return mysql_query($string);
}
)
if($_GET['like']) {
$like = d_db_update("UPDATE posts set post_rating = post_rating+1 WHERE post_id = {$_GET['like']}");
}
Button
<form action='{$_SERVER['PHP_SELF']}&like={$posts_row['post_id']}' method='get'>
<p align='left'>{$posts_row['post_rating']}
<input type='submit' name='like' value='Like' /></p>
</form>
What can I do to fix it/make it work?
Use below form with a hidden input it solve your problem.
<form action='{$_SERVER['PHP_SELF']}' method='get'>
<p align='left'>{$posts_row['post_rating']}
<input type='hidden' name='like' value='{$posts_row['post_id']}' />
<input type='submit' value='Like' /></p>
</form>
You are using your form action wrong.. if you are using get method than there is not need to use the form..
try this..
<a href='yourpage.php?like=<?php echo $post_id ?>'>Like</a>
your submit button name and like variable which you have used in action url are the same , and you used get method in method of form.So, you need to change the submit button name.
or
you can do it without using form only on button click try below code
<input type='button' name='like' value='Like' onclick="location.href='yourpage.php?like=<?php echo $post_id ?>'" />
Change your code to this
You can not write PHP variables using {}. You need to echo them out.
<form action='' method='get'>
<p align='left'><?php echo $posts_row['post_rating'] ?>
<input type='hidden' name='like' value='<?php echo $posts_row["post_id"] ?>' />
<input type='submit' value='Like' /></p>
</form>
Edit--
You were not returning the post id correctly, I made the changes, also there is no need to provide any action as it will be self only.
I have a little problem with my code and I don't know what is wrong in my code... So I have a two form where the first load is the "view.php" then the second is "checkbox_building.php".. My problem is when I removed the button of delete in "view.php" the dropdown list can proceed to "checkbox_building.php". but when I placed it back, its not working (its not proceeding to "checkbox_building.php") I'm kinda confuse about this.
Here's my code for "view.php"
<fieldset width= "200px">
<form name='form' method='post' action=''>
Select Network: <select name="netName" onChange="this.form.action='checkbox_building.php'; this.form.submit()">
<option value="" >- Select -</option>
<?php
include 'connect.php';
$q = mysql_query("select fldNetname from tblnetwork");
while ($row1 = mysql_fetch_array($q))
{
echo "<option value='".$row1[fldNetname]."'>".$row1[fldNetname]."</option>";
$net = $row1[fldNetname];
}
?>
</select>
<input type='submit' name='submit' value='Delete Building/s' onClick="this.form.action='delete_building.php'; this.form.submit()">
</form>
</fieldset>
thanks.!
just as a guess, just from your code:
correct the flaw, then
change
<input type='submit' name='submit'
to
<input type='button' name='dosubmit'
and
<form name='form' method='post' action=''>
to
<form name='<someUsefullName>' method='post' action=''>
and all references to this as well, since "form" is a reserved word in IE and this.form.action may lead to errors there.
just remove name='submit' and try
<input type='submit' name='submit' value='Delete Building/s' onClick="this.form.action='delete_building.php'; this.form.submit()">
so it will be
<input type='submit' value='Delete Building/s' onClick="this.form.action='delete_building.php'; this.form.submit()">
its because this.form.submit is default submit function, but in your code its an input element :)
I have multiple forms on one page all are like this: The ID value changes but the options can be similar.
<form class="test"><td>4000</td>
<td align='center'><input type='radio' name='radio' value='car' checked></td>
<td align='center'><input type='radio' name='radio' value='boat' ></td>
<td align='center'><input type='radio' name='radio' value='Plane' ></td>
<input type='hidden' name='id' value='4000'/>
<input type='hidden' name='location' value='local'/>
<div class="form" style="display: none;">
</div></form>
Using JQuery I'm trying to submit this when any of the 3 radio buttons are selected.
<script>
$("input[name='radio']").click(function() {
var CurrectForm=$(this).parents('.test:first');
$.post(
'do.php',
CurrectForm.serialize(),
function( response ) {
CurrectForm.find('#form').html( response );
show( response );
}
);
} );
</script>
I've used similar to the above with checkboxes and dropdown lists, which have worked fine. But this doesn't seem to submit the values to the do.php page. The values that are submitted are show in the div form. Doing a var_dump($_POST); results in an empty array.
Can someone point me in the right direction ?
Thanks
Changing the form ti this seems to work ?
<td><form class="test">
<input type='radio' name='radio' value='car' checked>
<input type='radio' name='radio' value='boat' >
<input type='radio' name='radio' value='Plane' >
<input type='hidden' name='id' value='4000'/>
<input type='hidden' name='location' value='local'/>
<div class="form" style="display: none;">
</div></form></td>
Why does changing the cause it to work ?
Jfiddle with working example :) http://jsfiddle.net/QvpH5/
My guess is that there are multiple forms on your page with the class test. What is happening, is when you use parents(), you don't realize it first finds all of the ancestors, and then searches for .test:first. This will return the very first form's values, regardless of which form is clicked.
Look at this jsFiddle to see the fix (change .parents to .parent): http://jsfiddle.net/SDzzr/