I have multiple submit buttons with the same name in my ongoing table, i want to have each submit button contains only one link. So whenever i click on a button, it generates a link that the submit is associated with. How to do it?
<input type="submit" value="<? $row['bclink'] ?>" name="re_b" id="re_b">
PHP:
if (isset($_POST['re_b'])){
$xml = simplexml_load_file($re_b);
}
this is what i have, but it's giving me an error that "simplexml_load_file() failed to load external entity "" in .... on line 70"
my question is how to call the value of the button when is clicked?
What error? If you have a problem, then give some details, don't just say you have a problem and expect us to be able to read it from your thoughts. No one here has taken Telepathy 101.
Do you mean you want something like this?
<input type="submit" name="submit" value="Something" />
<input type="submit" name="submit" value="Else" />
if ($_POST['submit'] == 'Something') {
...
} else if ($_POST'submit'] = 'Else') {
...
}
Related
I'm trying to use a tag inside of a function. In this case I want to click the button "find" and display the message "You selected the FIND option!" but it doesn't works. Can someone give me a hint or help me? I'm new using PHP. MORE DESCRIPTION: The website shows me the submit buttons "fruit" and "vegetable". When I click the fruit button then the website displays a table with products and one button called "find". If the user clicks the "find" button then the website must display the message "You selected the FIND option"(this message is just for testing). The problem here is when I click the "find" button, the website doesn't display the message.
<form action="Supermarket.php" method="post">
Please choose which one are you looking for:
<input type="submit" name='fruit' value="fruit">
<input type="submit" name='vegetable' value="vegetable">
</form>
<?php
if(isset($_POST['fruit'])){
fruitMenu();
}
if(isset($_POST['vegetable'])){
vegetableMenu();
}
function fruitMenu(){
echo "--------Welcome to fruit section--------";
$fruits = array(array('Name'=>"Apple",'ID'=>1234),
array('Name'=>"Banana",'ID'=>5678),
array('Name'=>"Watermelon",'ID'=>91011),
array('Name'=>"Orange",'ID'=>1213),
array('Name'=>"Mandarina",'ID'=>1415),
array('Name'=>"Pera",'ID'=>1617));
displayTable($fruits);
echo "<h2>WHAT DO YOU WANT TO DO?</h2>";
displayOptions();
}
?>
<?php
function displayOptions(){
echo '<form action="Supermarket.php" method="post">
<input type="submit" name="find" value="find">
</form>';
if(isset($_POST['find'])){
echo "You selected the FIND option!";
}
}
?>
I have an input type text box as follows
<input type="text" name="deleteprofileconfirmation" id="deleteprofileconfirmation" class="editprofileinput">
Delete Account
I need to pass the value entered in the input type text to deleteaccount.php
I can do with help of jquery, no problem, i need a pure php solution...
I tried using sessions, but problem is how to read the value in input type when link is clicked.. $_POST is also not working...
i cannot use form because this is a form in another form so html5 is not allowing nested forms, sorry should have mentioned that earlier
the following is not working on deleteaccount.php
if (isset($_POST['deleteprofilebutton']))
{
$delete_profile = strtolower($_POST['deleteprofileconfirmation']);
}
Make your link as
href="../controllers/deleteaccount.php?id=$ID_VALUE"
and update the POST to GET
if (isset($_GET['id']))
{
$delete_profile = strtolower($_GET['id']);
}
That would be GET now.
Make sure users with no privileges can hit this url and delete the profiles. Do check the user rights before processing the delete operation.
You can do this using form
<form action="../controllers/deleteaccount.php" method="post">
<input type="text" name="deleteprofileconfirmation" id="deleteprofileconfirmation" class="editprofileinput">
<input type="submit" class="deleteprofilebutton" name="deleteprofilebutton" id="deleteprofilebutton" value="Delete Account">
</form>
You could also give each one a unique name and just check the $_POST for the existence of that input.
<input type="submit" name="deleteprofileconfirmation" value="Delete" />
<input type="submit" name="submit" value="Submit" />
And in the code:
if (isset($_POST['deleteprofileconfirmation'])) {
//delete action
} else if (isset($_POST['submit'])) {
//submit action
} else {
//no button pressed
}
i want to have two buttons in my page that the one saves the data and move to the next page of the site and the other button saves the data and then clear all the fields to enter new data. I did the one button that saves the data and move to the next page but for the second button does not clear the fields but also moves to the next page. How can I fix that?
if(isset($_POST['submitted']))
{
.
.
.
header('Location: education.php');
}
My button code is this...
<input type="submit" value="Next" name="submit" />
<input type="submit" value="Add New & Save" />
Try this code :
if(isset($_POST['submitted']))
{
if($_POST['submitted']=="Next")
{
//perform inserting data and redirect
header('Location: education.php');
}
else if($_POST['submitted']=="Add New & Save")
{
//Clear all fields of form and save the data.
}
}
And give your submit button same name:
<input type="submit" value="Next" name="submitted" />
<input type="submit" value="Add New & Save" name="submitted"/>
OR you can try this also :
if(isset($_POST['submit_next']))
{
//perform inserting data and redirect
header('Location: education.php');
}
else if(isset($_POST['submit_new']))
{
//Clear all fields of form and save the data.
}
And give your submit button different name:
<input type="submit" value="Next" name="submit_next" />
<input type="submit" value="Add New & Save" name="submit_new"/>
One way you could accomplish what you want is to have the ADD NEW button be a separate form. You can have more than one form on a page. So, remove the 'Add New & Save' button from this form and use the 'Next' button for one form and the 'Add New' button for a second form.
Obviously, you would have to change the header url to the current page url (i.e. header('Location:education.php') would have to be changed to point to the page your forms are on. That will save your data and refresh the page, by invoking it again.
And, you would have to include a conditional statement that would determine which button had been clicked, to determine which page to navigate to.
I'm trying to do two different javascript actions with jquery for my php form which has two submit buttons: 'save' and 'next'. The idea is that both button submits form that saves data into db, but while 'next' goes through client-side validation and progress further, the 'save' just skips validation, returns true and the user stays on the form.
<form id="form" name="form" method="post" action="?action=my_php_form">
<input type="submit" name="save" class="save" id="save" value="save"/>
<input type="submit" name="next" id="next" class="next" value="next"/>
</form>
I already managed to succeed when user clicks either 'save' or 'next' after reload, but if user clicks 'next', launches validation and submit returns false, he cant click 'save' and ignore validation anymore. What might be the cause of this?
$(function() {
//Lets skip the whole thing if save is clicked
$('#save').click(function() {
$('#form').submit(function() {
return true;
});
});
$('#next').click(function() {
$('#form').submit(function() {
var invalid = 0;
//A lot of crazy validation, if some invalid stuff then increment increment invalid
if(invalid > 0) {
return false;
}
else {
return true;
}
});
});
});
I think I would do something like this :
$(function() {
//Lets skip the whole thing if save is clicked
//Actually, no binding is needed as the button is already a submit button
//Thx to Ocanal
$('#next').click(function() {
var invalid = 0;
//Validation process
if(invalid) {
$('#form').submit();
} else {
return false;
}
});
});
Why would you skip validation, especially if it so crazy ? Anyway the problem is here
$('#form').submit(function() { ... }
this doesn't overwrite the submit event handler, this ADDS a function to it. Therefore if you first click next then save , the function you defined for next will still be triggered when clicking on save.
While it's not clear with the notation, it's quite logic : that's what allows you to "add" action to your documentReady event from wherever you wish, not only from a central place.
You can use a different type for your non-submit button.
You'll want something like this:
<form id="form" name="form" method="post" action="?action=my_php_form">
<input type="submit" name="save" class="save" id="save" value="save"/>
<input type="button" name="next" id="next" class="next" value="next"/>
</form>
I think what's happening to you now is that both buttons are acting as your "submit" button, so the form is trying to submit, regardless of which button you're clicking, or what functions you've added to the EventListener.
First of all, Java Script is created every time when refreshing the page. It's important to understand that.
Now, if you click on the button 'Save' of type submit, your information will pack up in the form packet and sent to the server. The submit action requires reloading of the page(!).
Therefore, if you want to keep values in fields (if that's what you want) you may use PHP.
Using PHP is not complicated. I combine the code inside the <body> tag and before the <form> tag.
The code checks whether there is a value in the 'Save' field of $_POST variable, if true, we will save the received values.
And then, I present the values using variable access <? = $name ?>. That's it.
<?php
$name = "";
$credit = "";
if(isset($_POST['save'])) {
$name = $_POST['name'];
$credit = $_POST['creditCard'];
}
?>
<form id="form" name="form" method="post" action="good.php">
<input type="text" name="name" value="<?=$name ?>" />
<input type="text" name="creditCard" value="<?=$credit ?>"/>
<input type="submit" name="save" class="save" id="save" value="save"/>
<input type="submit" name="next" id="next" class="next" value="next"/>
</form>
I am currently trying to make a hyperlink that calls the same page that I am on, but a different PHP function. This seems like a simple enough solution however I don't want any information displayed in the URL. A "post" seems to be the best solution but I cannot find any results as to how to make this work.
<?php
function myFirst(){
echo 'The First ran successfully.';
}
function mySecond(){
echo 'The Second ran successfully.';
}
?>
<html><body>
<?php
if (isset($_GET['run'])){
$linkchoice=$_GET['run'];
}else{
$linkchoice='';
}
switch($linkchoice){
case 'first' :
myFirst();
break;
case 'second' :
mySecond();
break;
default :
echo 'no run';
}
?>
<hr>
Link to First
<br/>
Link to Second
<br/>
Refresh No run
</body></html>
If u want to use POST by pressing something in the page, u can either use JS to turn that into a POST request, or simply submit a form.
Assuming u use jQuery
go somewhere
<form id="koko" style="display:none" target="baba/was/here/this/is/the/url" method="post">
<input type="hidden" name="run" value="boo" />
</form>
...
...
function manda_mi(){
$('#koko').submit();
}
If you want to avoid Javascript you could wrap the links in a form, and style the buttons to look like normal links.
Basically:
<button type="submit" value="first" name="action">Link to First</button>
<br/>
<button type="submit" value="second" name="action">Link to Second</button>
<br/>
<button type="submit" value="0" name="run">Refresh no Run</button>
And then just check what button was pressed.
Although the simplest option is probably Javascript.