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>
Related
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
}
}
?>
I am new to coding and have learned a whole lot in the last 12 months using S/O so i would like to say thanks for helping me out and any input is more than appreciated.
I have created a 4 page Registration form that consists of the following process:
1. index.php (Main page / Landing page with form input values)
2. page2.php (Select date, time and confirm appointment)
3. page3.php (Booking confirmed please Select nearest location, Survey and service)
4. SSL Payments page with iframe insert from 3rd party
on page3.php i have inserted an internal iframe that is hosted on the same server, using separate css files, js, ect.. So due to my lack of coding skills i found it easier to insert the iframe rather than merging the page as 1 complete page.
Now on all pages i have managed to get the $_POST Variables passing from page 1 --> 2 --> 3
But on page 3 i fail to get all the variables displayed in the iframe hidden inputs. I can not understand why only some are being displayed and others are not.. When the form gets submitted the only ones that come through are the ones you can see hidden in source code.
i have also tried to do the following:
insert <?php session_start();?> at the top of the page
and at the bottom of page i have:
<?php
$_SESSION['Name']=$_POST['Name'];
$_SESSION['Postcode']=$_POST['Postcode'];
$_SESSION['Building']=$_POST['Building'];
$_SESSION['EmailAddress']=$_POST['EmailAddress'];
$_SESSION['Telephone']=$_POST['Telephone'];
$_SESSION['datepicker']=$_POST['datepicker'];
$_SESSION['timeofsurvey']=$_POST['timeofsurver'];
$_SESSION['PropertyOwner']=$_POST['PropertyOwner'];
?>
I have these on each page to make sure they get passed across each page, All the input ['names'] are correct and on the same page where the iframe is they are displayed back to the user in a text box to the right side of the iframe basically to show the user that their information is correct while booking their appointment.
Here is my iframe form source code:
<div id="app" my-app my-controller="Controller">
<form action="Processing.php" id="regForm" name="regForm" method="post">
<input type="hidden" value="<?php echo $_SESSION['Name'];?>" name="Full Name">
<input type="hidden" value="<?php echo $_SESSION['Telephone'];?>" name="Telephone">
<input type="hidden" value="<?php echo $_SESSION['EmailAddress'];?>" name="Email">
<input type="hidden" value="<?php echo $_SESSION['Building'];?> " name="Building Number or Name">
<input type="hidden" value="<?php echo $_SESSION['Postcode'];?>" name="Postcode">
<input type="hidden" value="<?php echo $_SESSION['PropertyOwner'];?>" name="PropertyOwner">
<input type="hidden" value="<?php echo $_POST['datepicker'];?>" name="Survey Date">
<input type="hidden" value="<?php echo $_POST['timeofsurvey'];?>" name="Survey Time">
The only hidden variables failing to display are the following:
['Name']
['EmailAddress']
['datepicker']
['timeofsurvey']
All other variables are being displayed fine, As i said even the page that has the iframe inserted is also displaying all variables back to the user correctly. If you click to view page source code you see them fine... Then as soon as you view the inner iframe source code you see the variables above are missing.
This is the outcome when viewing the iframe source code:
<div id="app" my-app my-controller="Controller">
<form action="Processing.php" id="regForm" name="regForm" method="post">
<input type="hidden" value="" name="Full Name"> **<----- This input is missing**
<input type="hidden" value="0123456789" name="Telephone">
<input type="hidden" value="" name="Email"> **<------- This input is missing**
<input type="hidden" value=" " name="Building Number or Name">
<input type="hidden" value="NW1 1AA" name="Postcode">
<input type="hidden" value="Yes" name="PropertyOwner">
<input type="hidden" value="" name="Survey Date"> **<--- This input is missing**
<input type="hidden" value="" name="Survey Time"> **<--- This input is missing**
<input type="hidden" name="field_passthrough1" value="Consumer" />
<input type="hidden" name="field_passthrough2" value="en-UK" />
I hope i have not gone the longest way round here trying to explain, as i understand a lot of you guys are really to busy to be reading long posts like mine when it will be something so simple.. I have spent 2 days trying all sorts to get this working and i can not seem to get a way round this.
I would really appreciate any help guys, Thank You.
############# UPDATE TO LAMONDE ################
This is how i now have the iframe and the only fields that are now missing is:
['Name']
['EmailAddress']
['Building']
---> ['datepicker'] and ['timeofsurvey'] are now working...
<input type="hidden" value="<?php echo $_SESSION['Name'];?>" name="Name">
<input type="hidden" value="<?php echo $_SESSION['Telephone'];?>" name="Telephone">
<input type="hidden" value="<?php echo $_SESSION['EmailAddress'];?>" name="EmailAddress">
<input type="hidden" value="<?php echo $_SESSION['Building'];?> " name="Building">
<input type="hidden" value="<?php echo $_SESSION['Postcode'];?>" name="Postcode">
<input type="hidden" value="<?php echo $_SESSION['PropertyOwner'];?>" name="PropertyOwner">
<input type="hidden" value="<?php echo $_SESSION['datepicker'];?>" name="datepicker">
<input type="hidden" value="<?php echo $_SESSION['timeofsurvey'];?>" name="timeofsurvey">
Here is source view on page3.php iframe:
<input type="hidden" value="" name="Name">
<input type="hidden" value="07541258585" name="Telephone">
<input type="hidden" value="" name="EmailAddress">
<input type="hidden" value=" " name="Building">
<input type="hidden" value="saas" name="Postcode">
<input type="hidden" value="No" name="PropertyOwner">
<input type="hidden" value="21/01/2015" name="datepicker">
<input type="hidden" value="4:30 pm" name="timeofsurvey">
Your $_POST will have the same name has your input.
So: $_POST['Name'] != $_POST['Full Name'];
It's pretty much the same for every input that are missing.
Also you really shouldn't use spaces in input names
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
The form is like below;
<form action="sendmail.php" method="get">
<input type="text" name="phone" id="phone" data-clear-btn="true">
<input type="text" name="name" id="name" data-clear-btn="true">
<input disabled="disabled" type="text" name="textinput-disabled" id="textinput-disabled" placeholder="Text input" value="<?php echo $info;?>">
</form>
$info = "type1"; and the $info works fine in the form.
but In the sendmail.php
$name=$_GET['name'];
$type=$_GET['textinput-disabled'];
$phone=$_GET['phone'];
I get the name and phone, but I can't get the value in the textinput-disabled.
What's the problem here.
Disabled fields are not submitted. You can make it readonly or hidden, to get value when submitted.
<input readonly type="text" name="textinput-disabled" id="textinput-disabled" placeholder="Text input" value="<?php echo $info;?>">
Thats expected behaviour.
Instead use
<input readonly type="text"...
Or if you must use disabled for some reason, add a hidden field:
<input disabled="disabled" type="text" name="textinput-disabled" id="textinput-disabled" placeholder="Text input" value="<?php echo $info;?>">
<input type="hidden" name="hidden" value="<?php echo $info;?>">
$name=$_GET['name'];
$type=$_GET['hidden'];
$phone=$_GET['phone'];
As disabled input cannot be submitted in form so you can use readonly="readonly", so use below :
<input readonly="readonly" type="text"
name="textinput-disabled" id="textinput-disabled"
placeholder="Text input" value="<?php echo $info;?>">
For more information on readonly
I had the same problem, but with a checkbox.
Since the readonly value doesn't change a checkbox so that it cant be clicked, I still had to use the disable option.
So I just added a hidden field with the desired variable name right below the checkbox:
<input type = 'checkbox' value = '1' name = 'EnableD_".$NR."' ";if($noti["ACTIVE"]==1)echo " checked "; echo " disabled >
<input type = 'hidden' value = '1' name = 'Enable_".$NR."' ";if($noti["ACTIVE"]==1)echo " checked "; echo " >
How to pass a form value to next page in other form?
I have this code in the :
<form action="confirm.php" method="post">
First name: <input type="text" name="firstname"><br>
Last name: <input type="text" name="lastname"><br>
Email: <input type="text" name="email">
</form>
Now I want that in confirm.php to put some hidden input fields with this values, I tried this code:
<form action="nextpage.php" method="post">
//some other input fields...
<input type="hidden" name="firstname" value="<?php $_POST['firstname']?>">
<input type="hidden" name="lastname" value="<?php $_POST['lastname']?>">
<input type="hidden" name="email" value="<?php $_POST['email']?>">
</form>
And so on in other 2 pages, and in the last page I want to email all this fields, I tried PHP _SESSION, but no luck with that, so I think that this can be more easier for me!
And something else I forgot to tell, on the second page (nextpage.php) action form variable I refer to a file that use this code:
<?php
header('Location: dear-'.$_POST['firstname'].'.php');
?>
<html>
<form>
<input type="hidden" name="firstname" value="<?php echo $_POST['firstname']?>">
<input type="hidden" name="lastname" value="<?php echo $_POST['lastname']?>">
<input type="hidden" name="email" value="<?php echo $_POST['email']?>">
</form>
</html>
In this case how to pass this values (firstname, lastname and email) on the next page ? I use that because I want to generate a page like this www.site.com/dear-name.php
Try this in confirm.php
<form action="nextpage.php" method="post">
//some other input fields...
<input type="hidden" name="firstname" value="<?php echo $_POST['firstname']?>">
<input type="hidden" name="lastname" value="<?php echo $_POST['lastname']?>">
<input type="hidden" name="email" value="<?php echo $_POST['email']?>">
</form>
You forgot to echo your variable.
<input type="hidden" name="firstname" value="<?php echo $_POST['firstname']; ?>">
Update:
You have two choices :
Store your data to session and retrieve to another page.
Pass your data using query string.
header('Location: dear-'.$_POST['firstname'].'.php?firstname='.$_POST['firstname'].'&lastname='.$_POST['lastname'].'&email='.$_POST['email']);
use echo:
<input type="hidden" name="firstname" value="<?php echo $_POST['firstname']; ?>">
<input type="hidden" name="lastname" value="<?php echo $_POST['lastname']; ?>">
<input type="hidden" name="email" value="<?php echo $_POST['email']; ?>">
and if this still not working, isset() your post variables:
if(isset($_POST['firstname'],$_POST['lastname'],$_POST['email'])) {
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
echo '<input type="hidden" name="firstname" value="$firstname">';
echo '<input type="hidden" name="lastname" value="$lastname">';
echo '<input type="hidden" name="email" value="$email">';
}
In your input text field, value is empty because of echo is missing. You need to add echo to print the value in your form. So that it can be sent into another page.
The second option is that you can use session_start() in top of each page.
and store the value of the variable in your session.
$_SESSION['name'] = "value_of_session"// in your case that is POST data
and this can be used in next page you need not to include hidden fields.
the most important thing is that You must write
<?php session_start() ?> // in each(you've three) page.