I'm facing some error when i click submit button, the value for userID is not passed. below is my code.
<div> <input type='hidden' id='userID' value="<?$inputs ['userID'] ?? '' ?>" >
</div>
<button type='submit' name="update">Update</button>
after clicking Update button, the info will be passed to function. But the value passed for the userID is NULL. Can someone assist me?
If you have wrapped your form by form tag you should have name attribute to send your data
<form action="destination.php">
<div> <input type='hidden' name='userId' id='userID' value="<?$inputs ['userID'] ?? '' ?>" >
<button type='submit' name="update">Update</button>
</form>
Related
When I click submit button of form I get two variables with same name in url. Why this happens.
The form is following
<select name='name1' form='select_form'>...</select>
<select name='name2' form='select_form'>...</select>
<form id='select_form' action='index.php' method='get'>
<input type='text' name='date_start' value='val1' id='datepicker1'>
<input type='text' name='date_end' value='val2' id='datepicker2'>
<button id='submit' type='submit' value='Submit'>Select</button>
</form>
When I click submit button I can see the following url
index.php?name1=val_name1&name2=val_name2&date_start=2016-08-01+00%3A00%3A00&date_start=&date_end=2016-08-03+00%3A00%3A00&date_end=2016-08-03+00%3A00%3A00
As you can see there are two date_start variables. What is the reason?
This has very bad impact, because when I change only one value (for example only date_start) then after clicking submit I have the following
index.php?name1=val_name1&name2=val_name2&date_start=2016-08-01+00%3A00%3A00&date_start=&date_end=2016-08-03+00%3A00%3A00&date_end=
So second value of date_end is empty.
I'm facing a strange problem. I have a HTML form in which user can input the ID number and then submit the form to get the analysis. The problem that I'm facing is that when the user manually inputs the ID, the form doesn't submit, but if the ID is copy pasted in the Text box, and the click the submit button, it works and loads the analysis. Can someone please help.
the form looks like below:
<form action="" method = "GET" class="form-inline">
<div class="input-group" style="padding-top: 10px; padding-bottom: 10px;" >
<span class="input-group-addon">Campaign IDs</span>
<input type="text" name="campaigns" id="campaigns" style="width:220px;" value="<?=$campaigns?>" class="form-control" aria-describedby="basic-addon2">
</div>
<input type='submit' class='btn btn-success' id='idsub'>
</form>
and php is handled like this:
if(isset($_GET["campaigns"]) && $_GET["campaigns"] != null) {
$teststart = true;
$campaign_array = explode(',',$_GET["campaigns"]);
If I type the campaign Id and then submit the button:
the URL submitted remains:
http://localhost/Optimization/insight.php?campaigns=
However, if I copy and paste the campaign ID in the text box, the URL string becomes:
http://localhost/Optimization/insight.php?campaigns=70067553
Try this in your script ::
<?php
if(isset($_GET["campaigns"]))
{
$campaigns = $_GET["campaigns"];
echo "Input field exists";
}
?>
<form method="GET">
<input type="text" name="campaigns" value="<?php echo isset($campaigns)?$campaigns:''; ?>">
<input type='submit' name="Submit" value="Submit" class='btn btn-success' id='idsub'>
</form>
You need to echo to pass php variable to html
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 simple form as outlined in the code below. I would like to append the value submitted in rm_accounts text box to the hidden page_confirm input value at the end of the URL. Hopefully that makes sense.
Essentially, if the user enters '123456' in the rm_accounts textbox, I want value of page_confirm to be http://www.mywebsite.com/index.php?rm_accounts=123456
<form name="signup" method="post" action="https://go.reachmail.net/libraries/form_wizard/process_subscribe.asp" >
<input type='text' name='rm_accounts' value='' />
<input type="hidden" name="page_confirm" value="http://www.mywebsite.com/index.php?rm_accounts=">
<input type="submit" name="Submit" value="Submit" >
</form>
All help is very much appreciated. Thanks!
Use Jquery focusout event to update hidden field value
When user enters 12345 and focus out of textbox or clicks submit(or anywhere) the below code get executed and update the value of hidden field.
$('input[type=text]').focusout(function(){
$('input[type=hidden]').val("http://www.mywebsite.com/index.php?rm_accounts="+$('input[type=text]').val());
console.log($('input[type=hidden]').val());
});
or in submit button click
$('input[type=submit]').click(function(){
$('input[type=hidden]').val("http://www.mywebsite.com/index.php?rm_accounts="+$('input[type=text]').val());
console.log($('input[type=hidden]').val());
});
Working JSFiddle link
http://jsfiddle.net/mkamithkumar/qNdny/1/
I would first suggest you give your HTML some IDs like so:
<form id="signup" method="post" action="https://go.reachmail.net/libraries/form_wizard/process_subscribe.asp" >
<input type='text' name='rm_accounts' id='rm_accounts' value='' />
<input type="hidden" name="page_confirm" id="page_confirm" value="http://www.mywebsite.com/index.php?rm_accounts=">
<input type="submit" name="Submit" value="Submit" >
</form>
Then use some jQuery for your task:
$('#signup').submit(function(){
var value = $('#rm_accounts').val();
var page_confirm = 'http://www.mywebsite.com/index.php?rm_accounts='+value;
$('#page_confirm').val(page_confirm);
});
I have a form with multiple submit buttons.
Each submit button is an IMG SRC trash can which denotes the delete icon for messages in a web based messaging mail inbox
what is the best way to figure out which submit button icon was clicked so that I can then write the PHP/MySQL code to DELETE the message?
if(!empty($_POST)){
// How do I figure out which submit button has been clicked to get the ID of the message to delete?
}
<form method="POST">
<input src="http://www.foo.com/img.png" id="button_1">
<input src="http://www.foo.com/img.png" id="button_2">
<input src="http://www.foo.com/img.png" id="button_3">
<input src="http://www.foo.com/img.png" id="button_4">
...
<input src="http://www.foo.com/img.png" id="button_100">
</form>
Set value for each submit button and check that in php and find which one is clicked
<form method="POST">
<img src="http://www.foo.com/img.png" id="button_1" name="submit_btn" value="1">
<img src="http://www.foo.com/img.png" id="button_2" name="submit_btn" value="2">
<img src="http://www.foo.com/img.png" id="button_3" name="submit_btn" value="3">
<img src="http://www.foo.com/img.png" id="button_4" name="submit_btn" value="4">
...
<img src="http://www.foo.com/img.png" id="button_100" name="submit_btn" value="100">
</form>
echo $_POST['submit_btn']; will give you the value of which submit button is clicked
Give each button a name=""
Then you can do something like
isset($_POST['button_name']) {
// execute code here if true
}
THE solution of this problem is to use the NAME attribute of the tag input/button.
<input type="submit" name="submitSave" value="Save"/>
<input type="submit" name="submitAddComment" value="Add comment"/>
or
<button type="submit" name="submitSave">Save</button>
<button type="submit" name="submitAddComment">Add comment</button>
I think you can also use the value attribute of button tag, this is definitively not possible with input tag.
If you need to use an ID or another variable, use name="submitDelete[888]"
Then, check it with PHP:
if( isset($_POST['submitDelete']) ) {
echo key($_POST['submitDelete']);// Displays the ID to delete, e.g. 888.
}
So many years later, I like button because it allows to display a text or an image independently of the value returned.
Here is an illustration of possibilities which fits the title of this post and more cases than the OP.
<?php
if(!empty($_POST['id'])){
echo 'button '. $_POST['id'] .' clicked';
} elseif ('create' === ($_POST['action'] ?? '')) {
echo 'create clicked'; // ?action=create
} elseif (isset($_POST['action'])) {
echo 'refresh clicked'; // ?action
} elseif (isset($_POST)) {
echo 'Default clicked'; // ?
}
?>
<form method="POST">
<!-- Original Post examples -->
<button type="submit" name="id" value="1"><img src="http://www.foo.com/img.png"></button>
<button type="submit" name="id" value="2"><img src="http://www.foo.com/img.png"></button>
...
<button type="submit" name="id" value="100"><img src="http://www.foo.com/img.png"></button>
<!-- Additional possibilities -->
<!-- ?action=create -->
<button type="submit" name="action" value="create">New element</button>
<!-- ?action -->
<button type="submit" name="action">Refresh</button>
<!-- ? -->
<button type="submit">Default</button>
</form>
you can give a name and a value to each of your buttons. It will then show up under $_POST['submit']
<img src="http://www.foo.com/img.png" id="button_4" name='submit' value='4' />
You have to pass your value to the current file by declearing name and value for each.. then you can echo in your php script in order to know which one is clicked.