how to send check box value in to next page without submit button and without action.
here i am going to next page using link so i want that these checkbox value send on next.php
my form is
<form method="post" action="" name="Logreg" style="padding-left:35px; padding-bottom:35px; font-size:14px;">
<input name="pay_type" type="checkbox" value="<?php echo $monthly; ?>"id="chk_Box102" onClick="toggle_2(this);" >
Monthly<br /><br />
<input name="pay_type" type="checkbox" value="<?php echo $yearly; ?>" id="chk_Box103" onClick="toggle_2(this);">
Yearly<br /><br />
<input name="pay_type" type="checkbox" value="<?php echo $lifetime; ?>" id="chk_Box104" onClick="toggle_2(this);">
Lifetime
</form>
and here a link by using i am going to next page
go here
To post data from one page to another page you have to use a submit button like:
<form method="post" action="next.php" name="Logreg" style="padding-left:35px; padding-bottom:35px; font-size:14px;">
<input name="pay_type" type="checkbox" value="<?php echo $monthly; ?>"id="chk_Box102" onClick="toggle_2(this);" >
Monthly<br /><br />
<input name="pay_type" type="checkbox" value="<?php echo $yearly; ?>" id="chk_Box103" onClick="toggle_2(this);">
Yearly<br /><br />
<input name="pay_type" type="checkbox" value="<?php echo $lifetime; ?>" id="chk_Box104" onClick="toggle_2(this);">
Lifetime
<input type="submit" value="Go here" />
</form>
also specify receiving page in action attribute of <form>
In another page (next.php).
You have to access your posted values using $_POST['name'];
eg.
echo $_POST['pay_type'];
EDIT
In your code, I can see that you want to send multiple values for checkbox pay_type, for that you have to write it as an array (name="pay_type[]")in HTML to send multiple values.
So, the complete code will looks like:
<form method="post" action="next.php" name="Logreg" style="padding-left:35px; padding-bottom:35px; font-size:14px;">
<input name="pay_type[]" type="checkbox" value="<?php echo $monthly; ?>"id="chk_Box102" onClick="toggle_2(this);" > Monthly<br /><br />
<input name="pay_type[]" type="checkbox" value="<?php echo $yearly; ?>" id="chk_Box103" onClick="toggle_2(this);"> Yearly<br /><br />
<input name="pay_type[]" type="checkbox" value="<?php echo $lifetime; ?>" id="chk_Box104" onClick="toggle_2(this);"> Lifetime
<br/>
<input type="submit" value="Go here" />
</form>
Code in next.php:
<?php
echo "<pre>";
print_r($_POST['pay_type']); //it will print complete array of values for pay_type checkbox
echo "</pre>";
?>
Log1c ツ as said before you need a button.. :). What is also possible to use an attribute onClick:
Add an ID at your form tag (id="myForm") (dont forget the target page next.php in action)
<form method="post" action="next.php" name="Logreg" style="padding-left:35px; padding-bottom:35px; font-size:14px;" id="myForm">
and then the onClick attribute
go here
jsfilleDemo
Related
When I click submit, the data is submitted to the database but the URL id of the book disappears to ----book.php
I want the URL to go back to the id of the page e.g. ----book.php?id=3
Is it possible to keep the first line as action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" and add the value="<?php echo $book_id ?>"?
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="hidden" value="<?php echo $book_id ?>" name="book_id" />
<p>Author: <input type="text" value="<?php echo $_SESSION['author']; ?>" name="author" id="author" readonly /></p>
<p>Summary: <input type="text" name="summary" value="<?php echo $summary;?>" /></p>
<p><input type="submit" name="submit" value="Submit" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
PHP code:
if (isset($_GET['id'])) {
$book_id = $_GET['id'];
}
Please try this code:
// save values in DB
header('Location: book.php?id=' . $book_id);
exit;
It is because $_SERVER["PHP_SELF"] contains only URL . It does not contain get queries . To solve the problem leave your action empty
e.g
<form method="post" action="">.....
You send a POST form but are trying to retrieve a GET value. Additinally, the parameter is named book_id, not id.
Use $book_id = $_POST['book_id'];
if (isset($_GET['id'])) { also won't work, for the same reasons.
There is no name with "id"
If you want to get the book id:
if (isset($_POST['book_id'])) {
$book_id = $_POST['book_id'];
}
OR modify the HTML like this:
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="hidden" value="<?php echo $book_id ?>" name="id" />
<p>Author: <input type="text" value="<?php echo $_SESSION['author']; ?>" name="author" id="author" readonly />
</p>
<p>Summary: <input type="text" name="summary" value="<?php echo $summary;?>" /></p>
<p><input type="submit" name="submit" value="Submit" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
On the other hand, if you have problems with POST, just modify the first line of HTML for this one:
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) . "?id=" . echo $book_id; ?>">
You can use anyone of these:
PHP_SELF returns just URL. Use REQUEST_URI that returns URL with query string:
<form method="post" action="<?php echo htmlspecialchars($_SERVER["REQUEST_URI"]);?>">
[you can also omit action values - that will have same behavior]
or if you want just id, then use:
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) . "?id=" . $_GET['id'];?>">
Note: Use validation wherever necessary. I just gave you an idea.
Let's say I have a form that I send via GET:
<form method="get" action="/search.php?foo=bar&test=1&something=else">
<input type="text" name="day" placeholder="day"/>
<input type="text" name="link" placeholder="link"/>
</form>
And after submitting my form and processing the data (which consists of only saving it to a file), the url is changed to:
search.php?day=test&link=google.com
What should I do so the url becomes:
/search.php?foo=bar&test=1&something=else&day=test&link=google.com
(preserving the old parameters that were included in action attribute.)
The form action will change every time and it's difficult to keep the old GET parameters in the form action.
However, you can go with hidden fields.
Try this:
<form method="get" action="/search.php">
<input type="hidden" name="foo" value="bar"/> <!-- Add this -->
<input type="hidden" name="test" value="1"/> <!-- Add this -->
<input type="text" name="day" placeholder="day"/>
<input type="text" name="link" placeholder="link"/>
</form>
You could try changing the action before submitting, depending how you're going to submit the form. This can be done if you apply IDs to your texts and either a name or an ID to the form.
HTML:
<form id="frm" method="get" action="/search.php?foo=bar&test=1&something=else">
<input type="text" name="day" id="day" placeholder="day"/>
<input type="text" name="link" id="link" placeholder="link"/>
</form>
Then with JavaScript you can run a function and change the form's action:
var _form = document.getElementById('frm');
var day = document.getElementById('day').value;
var link = document.getElementById('link').value;
_form.action += '&day=' + day + '&link=' + link;
_form.submit();
You could try to use a hidden input field.
<input type="hidden" name="name" value="value">
if you are getting your variables first from get and then want to add into 2nd form you could get this and create input fields hidden with these get values
Now when you submit form in get url you will get all you desire data
<?php
if($_GET){
if(isset($_GET['submit1'])){
$foo = $_GET['foo'];
$test = $_GET['test'];
$something = $_GET['something'];
?>
<form method="get" action="/search.php">
<input type="hidden" name="foo" placeholder="foo" value="<?php echo $foo; ?>"/>
<input type="hidden" name="test" placeholder="test" value="<?php echo $test; ?>"/>
<input type="hidden" name="something" placeholder="something" value="<?php echo $something; ?>"/>
<input type="text" name="day" placeholder="day"/>
<input type="text" name="link" placeholder="link"/>
</form>
<?php
}
}
?>
Basically I have a form that I start out with. On that form is the option to select a checkbox and once I click submit on that form, the information is read into a database and the condition on whether the checkbox has been selected now displays a '0' or '1' in the database.
Now I have an edit form. I choose the row I want to edit and my edit form gets populated with what is in the row. The only thing that doesn't show up, is whether that row was 'checked' on the first form. I want the checkbox to be marked if the user checked the checkbox on the first form and visversa.
Sorry if this sounds like a terrible explination.
Code for the first form:
<form method="post" action="processForm.php">
Name: <input type="text" name="names" required = "required"><br>
Activate: <input type="checkbox" name="activateBox"><br>
<input type="submit" value="Create Users"><br>
</form>
And code for edit form:
<form method="post" action="editForm.php">
ID: <input type="text" readonly name="id" value="<?php echo $row['id']; ?>"><br><br>
First Name: <input type="text" name="firstName" value="<?php echo $row['firstName']; ?>"><br><br>
Last Name: <input type="text" name="lastName" value="<?php echo $row['lastName']; ?>"><br><br>
Email: <input type="text" name="email" value="<?php echo $row['email']; ?>"><br><br>
Activate: <input type="checkbox" name="activateBox" value="<?php echo $row['activated']; ?>"><br><br>
<input type="submit" value="Update"><br>
</form>
I tried doing this but it did nothing. I'm sure I'm missing something pretty simple but I can't figure out what.
if (isset($_POST['activateBox'])) {
echo 'checked="checked"';
}
The checked attribute of the <input type="checkbox"> tag should work. Most likely, when you loaded the edit form, it was an HTTP GET request, rather than a POST, so the $_POST['activateBox'] was empty.
In any case, reading the current state on an edit form from the client seems wrong. Shouldn't the current state come from the database?
Try this:
Activate: <input type="checkbox" name="activateBox"<?php if ($row['activated']) echo " checked"; ?>>
Activate:
<input type="checkbox" name="activateBox"
<?php
if($row['activated']==1){
echo ' value="1" checked';
}else{
echo ' value="0";
?>
<br><br>
I have 4 different pages both with one form each.
I want to gather all the entries on each of the pages and submit once.
Here is code.
Page 1
<form action="page2" method="POST">
<input type="text" name="sex">
<input type="submit" value="Submit">
</form>
Page 2
<form action="page3" method="POST">
<input type="text" name="size">
<input type="hidden" name="sex" value="<?php echo $_POST['sex'] ?>" >
<input type="submit" value="Submit">
</form>
Page 3
<form action="page4" method="POST">
<input type="text" name="colors">
<input type="hidden" name="size" value="<?php echo $_POST['size'] ?>" >
<input type="submit" value="Submit">
</form>
Page 4
<form action="verNote.php" method="POST">
<input type="text" name="likes">
<input type="hidden" name="colors" value="<?php echo $_POST['colors'] ?>" > <input type="submit" value="Submit">
</form>
Then i will like to get all the infos on verNote.php
<?php
echo $_POST['sex'];
echo '<br>';
echo $_POST['size'];
echo '<br>';
echo $_POST['color'];
echo '<br>';
echo $_POST['likes'];
?>
This code above dont seem to post entries from both pages 1 and 2, just for 3 and 4 alone gets submitted.
Will appreciate immediate assistance form anyone who understands my question.
Regards!
You need to load the hidden fields again each time
Page 3
<form action="B.php" method="POST">
<input type="text" name="colors">
<input type="hidden" name="size" value="<?php echo $_POST['size'] ?>" >
<input type="hidden" name="sex" value="<?php echo $_POST['sex'] ?>" >
<input type="submit" value="Submit">
</form>
Page 4
<form action="B.php" method="POST">
<input type="text" name="likes">
<input type="hidden" name="colors" value="<?php echo $_POST['colors'] ?>" >
<input type="hidden" name="sex" value="<?php echo $_POST['sex'] ?>" >
<input type="hidden" name="size" value="<?php echo $_POST['size'] ?>" >
<input type="submit" value="Submit">
</form>
I didn't understand 100% what you're trying to achieve, but have you tried using sessions?
Do this in B.php:
<?php
session_start();
if( isset($_POST['sex']))
$_SESSION['sex'] = $_POST['sex'];
if( isset($_POST['size']))
$_SESSION['size'] = $_POST['size'];
if( isset($_POST['color']))
$_SESSION['color'] = $_POST['color'];
if( isset($_POST['likes']))
$_SESSION['likes'] = $_POST['likes'];
?>
Then you can retrieve the values from any other file, just call session_start(); and use the $_SESSION superglobal.
EDIT
Using sessions, you verNote.php file could be something like this:
<?php
session_start();
echo $_SESSION['sex'];
echo '<br />';
echo $_SESSION['size'];
echo '<br />';
echo $_SESSION['color'];
echo '<br />';
echo $_SESSION['likes'];
echo '<br />';
?>
I have a php and html based tool that has a form that, when submitted, outputs the data reformatted using echo commands.
I'd like to add a 2nd form to the same page that will also output using echo.
My issue is, when I submit the 2nd form the first forms output disappears. I'd like to make it so the echo output from the first form does not go away when the 2nd form is submitted so they will both be on the screen at the same time.
Is there a way I can do this?
Only one <form> block in a page can be submitted at a single time. <input> fields defined in one form will not be submitted when the other form is submitted.
e.g.
<form>
<input type="text" name="foo" />
<input type="submit" />
</form>
<form>
<input type="text" name="bar" />
<input type="submit" />
</form>
Clicking on submit will submit either a foo field, OR a bar field. Not both. If you want both fields to be submitted, then you have to either build them into a SINGLE form:
<form>
<input type="text" name="foo" />
<input type="text" name="bar" />
<input type="submit" />
</form>
or use Javascript to copy the data from one form to another.
<form method="post"> <div>Module1</div> <input type="text"
value="module1" name="module_id"> <input type="text" value="title 1"
name="title"> <input type="text" value="some text 1" name="text">
<input type="submit" name="form_1" value="submit"> </form>
<form method="post"> <div >Module2</div> <input type="text"
value="module2" name="module_id"> <input type="text" value="title 2"
name="title"> <input type="text" value="some text 2" name="text">
<input type="submit" name="form_2" value="submit"> </form>
<?php
if(isset($_POST['form_1'])){
echo '<pre>';
print_r($_POST); }
if(isset($_POST['form_2'])){
echo '<pre>';
print_r($_POST); } ?>
Yes,you can do it.
Eg :
// form1 on page a.php
<form method="post" action="a.php" name="form_one" >
<input type="text" name="form_1" value="if(isset($_POST['form_1'])) echo $_POST['form_1']; ?>" >
<input type="submit" name="submit_1" >
</form>
<?php
if(isset($_POST['submit']))
{
?>
<form method="post" action="a.php" name="form_two" >
<input type="text" name="form_2" value="if(isset($_POST['form_2'])) echo $_POST['form_2']; ?>" >
<input type="submit" name="submit_2" >
</form>
<?php
}
?>
Now when you will submit form_one you will see form_two appear and the value in form one will stay intact in form_one and one the submitting form two the value will remain.
Hope it helped :)