form action not calling script php - php

Edit: calling the script works but still having a problem with passing my parameters.
here is processdonateditems.php
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['id']) && isset($_POST['type'])) {
$scripttype =mysql_real_escape_string($_POST['type']);
if($scripttype == "cancel") {
....
here are my buttons which have to submit this form
<input type="button" value="Confirm Sent" class="btn" <?php if($fetch_donate3['claim_status']=='1'){?> enabled <?php } else {?> disabled <?php }?>>
<input type="button" value="Cancel Donation" class="btn")
...
</form>

Your buttons have type="button". If you want some of them to submit the form they should contain
type="submit"
If that's not the case then use javascript to submit the form like that:
document.getElementById("change_donate").submit();
Edit:
to receive $_POST['id'] and $_POST['type'] you need to have those elements inside the form. Like that for example:
<input type="hidden" name="id" value="" />
<input type="hidden" name="type" value="" />

Related

How do I make a form update itself?

I have a form with 3 selections, and I want the form to replace the selected text with the name entered when submitted. So if the user enters their name as Josh, and picks 'King', I want the form to update itself and instead of having King it would say Josh which would no longer be a choice, and then have the other two characters below for someone else to pick from. This is a PHP document, but the data is in a HMTL form of course.
I was reading something about hidden forms, but was not sure how to implement them here. Does anyone have any suggestions?
<form method="get" action="">
Your Name: <input type="text" name="name" />
<br/>
<input type="radio" name="character" value="King"> King<br>
<input type="radio" name="character" value="Queen"> Queen<br>
<input type="radio" name="character" value="Prince"> Prince <br>
<input type="submit" value="Submit" />
Are you looking to do something like this?
You can do it by using php conditions and hidden fields.
Save the file with the name "form.php" then run it and tell me if it does the trick ;)
<form method="post" action="form.php">
Your Name: <input type="text" name="name" />
<br/>
<?php if((isset ($_POST['name-1']) || isset($_POST['name'])) && (isset ($_POST['character-1']) && $_POST['character-1']=='King'))
{
$name=isset($_POST['name-1'])?$_POST['name-1']:$_POST['name'];
echo $name.'<br><input type="hidden" name="name-1" value="'.$name.'"/><input type="hidden" name="character-1" value="'. $_POST['character-1'].'"/>';
}
else {?>
<input type="radio" name="character-1" value="King"> King<br>
<?php } ?>
<?php if((isset ($_POST['name-2']) || isset($_POST['name'])) && (isset ($_POST['character-2']) && $_POST['character-2']=='Queen'))
{
$name=isset($_POST['name-2'])?$_POST['name-2']:$_POST['name'];
echo $name.'<br><input type="hidden" name="name-2" value="'.$name.'"/><input type="hidden" name="character-2" value="'. $_POST['character-2'].'"/>';
}
else {?>
<input type="radio" name="character-2" value="Queen"> Queen<br>
<?php } ?>
<?php if((isset ($_POST['name-3']) || isset($_POST['name'])) && (isset ($_POST['character-3']) && $_POST['character-3']=='Prince'))
{
$name=isset($_POST['name-3'])?$_POST['name-3']:$_POST['name'];
echo $name.'<br><input type="hidden" name="name-3" value="'.$name.'"/><input type="hidden" name="character-3" value="'. $_POST['character-3'].'"/>';
}
else {?>
<input type="radio" name="character-3" value="Prince"> Prince <br>
<?php } ?>
<input type="submit" value="Submit" />
</form>

PHP check atleast two buttons are selected

I've a form that will require user to choose/click at least two buttons in order to submit the form
<button type="button" name="Investor-agree-one">I AGREE</button>
<button type="button" name="Investor-agree-two">I AGREE</button>
<button type="button" name="Investor-agree-three">I AGREE</button>
<button type="button" name="Investor-agree-four">I AGREE</button>
<button type="button" name="Investor-agree-five">I AGREE</button>
How do I validate the form using php that at least two buttons are selected and redirect user to one page, if not redirect to another page? So basically is like:
if(buttonSelected>=2){
goto this page
}else{
goto another page
}
How do I indicate whether the button is being selected in the first place using the button elements?
Thats pretty easy,
Give your buttons all the same "name", and a unique value
so lets say we have this button tag:
<form method="post">
<button name="somebutton" value="buttonone">
<button name="somebutton" value="buttontwo>
<button name="somebutton" value="buttontwo">
</form>
Your php should then look something like this:
<?php
$button = $_POST['somebutton'];
if($button == "buttonone"){
//do button 1 stuff, in your example:
header('location: someurl.php');
}
if($button == "buttontwo"){
// do button 2 stuff
}
?>
You may use checkbox instead of button, so your code may like this:
<?php
if(isset($_POST['agree_one'])) {
// do something
}
?>
<form method="post">
<label>
<input type="checkbox" name="agree_one" value="1"/>
I Agree
</label>
<label>
<input type="checkbox" name="agree_two" value="1"/>
I Agree
</label>
<label>
<input type="checkbox" name="agree_three" value="1"/>
I Agree
</label>
</form>
But if you just want to count how much user has selected the agree checkbox, you may want this code:
<?php
if(isset($_POST['agree']) && count($_POST['agree']) > 2) {
// do magic
}
?>
<form method="post">
<label>
<input type="checkbox" name="agree[]" value="1"/>
I Agree
</label>
<label>
<input type="checkbox" name="agree[]" value="1"/>
I Agree
</label>
<label>
<input type="checkbox" name="agree[]" value="1"/>
I Agree
</label>
</form>

one form multiply tasks with php

I am making an CMS, and the pages that are going to be made by the clients, they are going to use the same form to edit the page, add new page, add new subpage, edit the subpage.. I dont want to copy that form multiply times for each action. I would like to know if anyone of you has an idea how to use that form for all of the actions in the best way.
<div class="containerholder">
<div class="container">
<div id="contain">
<form method="post" id="customForm" action="edited.php">
<div>
<label for="name">Navigation</label>
<input id="name" name="navigation" type="text" value="<?php echo $navigation ?>" />
</div>
<div>
<label for="message">Content</label>
<textarea id="content" name="content" cols="" rows="" ><?php echo $content ?></textarea>
</div>
<div>
<input type="hidden" name="id" id="id" value="<?php echo $id ?>">
<input id="send" name="send" type="submit" value="Save and update" />
</div>
</form>
</div>
</div></div>
this is the form if you want to see it, I have an idea how to make it but it doesnt look to me like it is the best way (professional).
Thank you for your time!
Use multiple submit-buttons for every task and identify the requested task by the name of the submit-button(usually only a clicked submit-button is submitted)
Professional: it's not "professional" in my eyes to use a single form for all tasks.
You could use multiple submit buttons, as google does with its search/feeling lucky choice:
<input id="send" name="send" type="submit" value="edit" />
<input id="send" name="send" type="submit" value="new page" />
<input id="send" name="send" type="submit" value="edit subpage" />
<input id="send" name="send" type="submit" value="new subpage" />
The name=value pair for the submit button is transmitted as it is for the rest of the form data, so at the server it is collected using the same functionality ($_GET or $_POST etc.)
Alternatively, you could use form controls and javascript events to control the communication to the server via AJAX (it's more flexible, you can control exactly what data is transmitted via javascript, and it's seamless for the end-user who isn't waiting for page reloads). See http://www.w3schools.com/ajax for simple source code.
add two or more radio button to select you function, for example :
<form action="" method="post">
...
<input type="radio" name="function" value="Add" />
<input type="radio" name="function" value="Delete" />
<input type="radio" name="function" value="Edit" />
..
</form>
and in php :
<?PHP
...
if( $_POST['function'] == 'Add' )
{
//Add Function
} else
if( $_POST['function'] == 'Delete' )
{
//DeleteFunction
} else
if( $_POST['function'] == 'Edit' )
{
//EditFunction
}
...
?>
I would suggest making a single form, and then using scripting to switch it between modes and datafill the fields as required.
For links directing to the form.
/* To create a New Record */
New Record
/* To delete an Existing Record */
Delete #123
/* To edit an Existing Record */
Delete #123
For the form file (in my example thisfile.php itself).
<?php
if( isset( $_GET['action'] ) ){
switch( strtolower( $_GET['action'] ) ){
case 'delete' :
/* Perform Deletion Action Here */
break;
case 'edit' :
if( isset( $_POST['save'] ) ){
/* Perform Modification of Existing Values Here */
}else{
/* Perform Query for Existing Values Here */
}
break;
case 'new' :
if( isset( $_POST['save'] ) ){
/* Perform Creation of New Record Here */
}else{
/* Set Default Values */
$navigation = '';
$content = '';
}
break;
}
}
?>
<div class="containerholder">
<div class="container">
<div id="contain">
<form method="post" id="customForm">
<?php if( isset( $_GET['action'] ) ){ ?>
<input type="hidden" name="action" value="<?php echo $_GET['action']; ?>" />
<?php } ?>
<?php if( isset( $_GET['record'] ) ){ ?>
<input type="hidden" name="record" value="<?php echo $_GET['record']; ?>" />
<?php } ?>
<div>
<label for="name">Navigation</label>
<input id="name" name="navigation" type="text" value="<?php echo $navigation ?>" />
</div>
<div>
<label for="message">Content</label>
<textarea id="content" name="content" cols="" rows="" ><?php echo $content ?></textarea>
</div>
<div>
<input id="send" name="send" type="submit" value="Save and update" />
</div>
</form>
</div>
</div>
</div>

Update Statement using Request Method Post

I've done a search related to 'update statement using form'.
Lots of post showed an update function using a form using isset
if(isset($_POST["submit"])) { //process } else { //show form }
Does this mean that it is not possible to do update using this?
if($_SERVER["REQUEST_METHOD"] == "POST") { //process } else { //show form }
It seems so cause my update function doesn't work.
Solved : It works now. I added
<input type="hidden" name="contact_id" value="<?php echo $row["contact_id"]; ?>" />
before
<input type="submit" name="submit" value="Submit" />
in the form
<form method="post" action="update.php">
Username: <input type="text" name="contact_name" value="<?php echo $row["contact_name"]; ?>" />
Email: <input type="text" name="contact_number" value="<?php echo $row["contact_number"]; ?>" />
<input type="hidden" name="contact_id" value="<?php echo $row["contact_id"]; ?>" />
<input type="submit" name="submit" value="Submit" />
</form>
bith ways should work.
But what you should do first is :
var_dump($_POST);
to make sure there is anything in the $_POST var before you do the 1st option.
I don't know if REQUEST_METHOD is always in uppercase. To test this, use strtoupper($_SERVER['REQUEST_METHOD']) == 'POST' and see if it works.

How do i select buttons using php and enter into database?

Here is my current code..
<form action="js.php" method="post">
<input type="button" id='approve' value="Yes" onclick="a()" class="approve" />
<input type="button" id='reject' value="No" onclick="r()" class="reject"/>
<input type="submit" name="submitted" value="TRUE" />
</form>
This is my form and the page title is js.php..
I want that if the user clicks on any of the button the name of the button should bge entered into the database into a table called response under the heading response.
How Do i do that?Thanks..
I have done some PHP part...
<?php
require_once('connect.php');
if(isset($_POST['submitted']))
{
//if on button click
mysqli_select_db($connect,"check");
//entering query
}
?>
here is what Im using to enter the data
<?php
require_once('connect.php');
//if on button click
mysqli_select_db($connect,"pubd");
//entering query
if ($_POST['action'] == 'approve') {
// user clicked Yes
$yes = "insert into response (button) values ('approve')";
$yesr = mysqli_query($connect,$yes) or die(mysqli_error($connect));
} else if ($_POST['action'] == 'reject') {
$no = "insert into response (button) values ('reject')";
$nor = mysqli_query($connect,$no) or die(mysqli_error($connect));
}
?>
<form action="js.php" method="post">
<input type="button" id='approve' name="action" value="Approve" onclick="a()" class="approve" />
<input type="button" id='reject' value="Reject" name="action" onclick="r()" class="reject"/>
</form>
If you're just looking for an answer how to check which button was clicked, here it is:
HTML:
<input type="submit" id='approve' value="Yes" name="action" class="approve" />
<input type="submit" id='reject' value="No" name="action" class="reject"/>
PHP:
if ($_POST['action'] == 'Yes') {
// user clicked Yes
} else if ($_POST['action'] == 'No') {
// user clicked No
}

Categories