I have this code. Trying to pass form values from one internal page to the other and it's not working.
Here's the code:
<div data-role="page" id="home">
<div data-role="header">
<h1>Page One</h1>
</div><!-- /header -->
<div data-role="content">
<form action="post" name="myform">
<input type="text" value="" name="mytext" />
<input type="submit" value="submit" />
</form>
</div><!-- /content -->
</div><!-- /page -->
//And page 2
<div data-role="page" id="page2">
<div data-role="header">
<h1>Page Two</h1>
</div><!-- /header -->
<div data-role="content">
<?php if (isset($_POST['mytext'])) {
// do something with $_POST['value']
echo 'it works'; } ?>
</div><!-- /content -->
</div><!-- /page -->
It's basically not working ... no errors but no values either.
Your action should be the php script that is going to process your post variables and method should be post.
<form action="somefile.php" method="post">
Most likely the error is here:
<form action="post" name="myform">
<input type="text" value="" name="mytext" />
<input type="submit" value="submit" />
</form>
action is supposed to be the handler of the form, either the same page or another one (where the php script that elaborates the form resides). POST is the METHOD. (which can be either GET or POST)
So it should be:
<form action="" method="POST" name="myform"> <!-- action = "" reloads the same page, otherwise you could write action="myphppage.php" or whatever -->
<input type="text" value="" name="mytext" />
<input type="submit" value="submit" />
</form>
<form action="post" name="myform">
is wrong.
It should be something like:
<form method="post" name="myform" action="">
You need to send a POST method. The action is empty so it sends it to the page itself.
The 'action' should be the page that is the destination URL. You have mixed up method="post" with action="post". Set the action as "second_page.php".
I didn't fully understand what you meant by internal page, but if it is the same page, only a different div, then leave the action as blank(action='').
Related
I am trying to $_GET a hidden input using PHP.
When I check the html code in Chrome, Safari, etc., I can see the value of the hidden variable but when I try to echo it with PHP it is empty. All of this is inside a modal.
I don't really understand what I am doing wrong.
I hope some of you can help me.
<form method="get">
<input name="hiddencontainer" type="hidden" id="hiddencontainer" value="default"/>
</form>
<div id="frame" class="modal">
<div class="modal-content">
<!-- Body content -->
<div class="modal-body">
<p id="content">
<?php
// Get information
$id = $_GET["hiddencontainer"];
echo $id;
?>
</p>
</div>
</div>
</div>
You need to submit the form to get the value, try this
<form method="get">
<input name="hiddencontainer" type="hidden" id="hiddencontainer" value="default"/>
Click the button to submit the form and you will see the value
<input type="submit" name="Submit form"/>
</form>
<div id="frame" class="modal">
<div class="modal-content">
<!-- Body content -->
<div class="modal-body">
<p id="content">
<?php
// Get information
$id = $_GET["hiddencontainer"];
echo $id;
?>
</p>
</div>
</div>
</div>
I am writing code that is meant to log in users.
The login and search worked before but, ever since I combined the two the login form doesn't implement it's own code and instead, it runs the search code
EDIT: I found out why this happens, it's because I have been pressing enter instead of selecting login. So now I want to know, how do I press enter and implement the login code.
Below is the headerPublic.php which contains the search code
<?php
//---------------------BEGIN SEARCH FROM THE SEARCH BAR IN PUBLIC HEADER----------------------------------
if(isset($_POST["search_button"]))
{
//PHP SEARCH CODE
}
//---------------------END SEARCH FROM THE SEARCH BAR IN PUBLIC HEADER----------------------------------
?>
<html>
<head>
<title>VCR Exchange</title>
</head>
<body>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>
<form role="search" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<div class="form-group">
<input type="search" name="search">
</div>
<button type="submit" value = "search" name="search_button">Search</button>
</li>
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>Register</li>
<li>Log In</li>
</ul>
</nav>
And this is the login.php.
<?php require('connect.php'); ?>
<?php require('headerPublic.php'); ?>
<?php require('session.php'); ?>
<form class="form" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<label for="inputEmail" >Email address</label>
<input type="email" name="email" placeholder="Email address">
<label for="inputPassword" >Password</label>
<input type="password" name="password" placeholder="Password">
<button name="login" type="submit">Login</button>
</form>
</body>
</html>
<?php
// IF LOGIN BUTTON IS CLICKED:
if (isset($_POST['login']))
{
//LOG IN CODE
}
?>
The search form was missing a closing form tag
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>
<form role="search" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<div class="form-group">
<input type="search" name="search">
</div>
<button type="submit" value = "search" name="search_button">Search</button>
</form>
</li>
<!------------------------------------SEARCH BAR---------------------------------------------->
hi can anyone tell me whats problem in this form . its not show varible in url
<form class="navbar-form navbar-left" method="post" action="test.php?q=<?php echo $searchb;?>" role="search" style="padding: 3.5px 90px;">
<div class="form-group">
<input type="text" name="searchb" class="form-control" autocomplete="off" placeholder="Search" />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
php code here
if (isset($_POST['searchb'])) {
$searchb = $_POST['searchb'];
}
when something input in form and action url not show any value
test.php?q=
but we echo variable its show value .
First time that form loaded $_POST['searchb'] is empty so action is equal test.php?q= after load form when you submit form then $_POST['searchb'] to be filled
The Part: action="test.php?q=<?php echo $searchb;?>" is first illogical and most importantly unnecessary since you are POSTing your form. It would have been valid if $searchb was pre-defined. However, since it is a part of the Form; it will always be NULL since it was never declared but expected to be dynamically added on Form-Submit, which wouldn't happen. You do it in one of the 2 ways:
OPTION #1 - PASSING q VIA HIDDEN INPUT:
<!-- YOU DON'T NEED THE echo $searchb PART IN YOUR FORM'S ACTION BECAUSE -->
<!-- THAT VALUE IS NOT PART OF THE ACTION AS IT IS NOT EVEN SET AT ALL -->
<form class="navbar-form navbar-left" method="post" action="test.php" role="search" style="padding: 3.5px 90px;">
<div class="form-group">
<input type="text" name="searchb" class="form-control" autocomplete="off" placeholder="Search" />
<!-- ADD THE q AS HIDDEN INPUT ELEMENT WITH A VALUE -->
<input type="HIDDEN" name="q" value="Some value" />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<?php
// INSIDE OF test.php SCRIPT; DO;
if (isset($_POST['searchb'])) {
$searchb = $_POST['searchb'];
}
OPTION #2: USING GET & SETTING Q TO A PRE-DEFINED VALUE
<?php $param = "some-predefined-value"; ?>
<form class="navbar-form navbar-left" method="GET" action="test.php?<?php echo $param;?>" role="search" style="padding: 3.5px 90px;">
<div class="form-group">
<input type="text" name="searchb" class="form-control" autocomplete="off" placeholder="Search" />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<?php
// INSIDE OF test.php SCRIPT; DO;
// BUT REMEMBER TO CHECK INSIDE THE `GET` GLOBAL
if (isset($_GET['searchb'])) {
$searchb = $_GET['searchb'];
}
BETTER OPTION FOR YOUR USE-CASE: USING GET & SETTING Q FROM THE INPUT
<!-- STILL NO NEED FOR SETTING QUERY PARAMETERS MANUALLY-->
<!-- THE GET METHOD WOULD TAKE CARE OF THAT FOR YOU ONCE THE FORM IS SUBMITTED -->
<form class="navbar-form navbar-left" method="GET" action="test.php" role="search" style="padding: 3.5px 90px;">
<div class="form-group">
<!-- NOTICE THAT THE NAME OF THE INPUT FIELD CHANGED TO; q HERE -->
<input type="text" name="q" class="form-control" autocomplete="off" placeholder="Search" />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<?php
// INSIDE OF test.php SCRIPT; DO;
// BUT REMEMBER TO CHECK INSIDE THE `GET` GLOBAL
if (isset($_GET['q'])) {
$searchb = $_GET['q'];
}
I have a simple dialog box:
<div data-role="dialog" id="uploadImage" data-title="Upload Image" data-needs-auth="true">
<div data-role="header" data-position="fixed" data-theme="b">
<h1>Upload Image</h1>
</div><!-- /header -->
<div data-role="content">
<form name=uploadForm method=post enctype="multipart/form-data" action="uploadbi.php" data-ajax="false">
<input type=file name=filename>
<input type=hidden name=MAX_FILE_SIZE value=8000000>
<input type="submit" value="Upload Image" data-theme="a" data-inline="true">
</form>
</div>
</div>
</div>
The problem is that it does not pass the filename field. From Firebug:
Post Parameters
application/x-www-form-urlencoded
MAX_FILE_SIZE 8000000
seid 6e540f68067707233241eb170ca83c43
Source
MAX_FILE_SIZE=8000000&seid=6e540f68067707233241eb170ca83c43
This is running under Firefox and I verified that it also fails under Chrome. It's been forever since I've dealt with file uploads in a form. What am I missing?
Last month I had a similar problem. Try to add data-ajax="false" on your form definition and see if that will help.
For more information, you could check this link.
i got a form.
<form id="site-contact-form">
<div>
<div class="wrapper"><span>Ձեր անունը:</span>
<div class="bg">
<div>
<input type="text" class="input" name="contactname" id="contactname" />
</div>
</div>
</div>
<div class="wrapper"><span>Ձեր E-mail-ը:</span>
<div class="bg">
<div>
<input type="text" class="input" name="email" id="email" />
</div>
</div>
</div>
<div class="textarea_box"><span>Տեկստ:</span>
<div class="bg">
<div>
<textarea cols="1" rows="1" name="message" id="message"></textarea>
</div>
</div>
</div>
<div style="clear:both;"></div>
<button id="sub" name="submit">ուղարկել</button>
</div>
</form>
As you see i got no action on it, no method. But when im clicking on button, its refreshing the page (like when it have action) and adding to URL ?contactname=&email=&message=&submit= ... I never met this problem before, why it is sending variables? I dont have any php on page yet...
Beacause the default method is GET and the URL is the same of the page. Use:
<form method="POST" action="/reactor">
<!-- .... -->
</form>
Actually, the action property is mandatory.
Please correct the code with:
<form id="site-contact-form" method="post">
And the submitted values will not be displayed on the URL.
If you do not specify the form method, it will "get" by default.
This is happening here.
Change the type of button as button
<button id="sub" name="submit" type="button">ուղարկել</button>