I have a simple signup form:
<h2>Signup</h2>
<form action="actions.php">
Email:<br>
<input type="text" name="lastname">
<br>
Password:<br>
<input type="text" name="lastname">
<br>
<br>
<input type="submit" name="signupButton" value="submit">
</form>
And here is my actions.php:
<?php
echo 'test1';
if(isset($_POST['signupButton'])){
echo 'test2';
}
?>
But when I click the submit button the page that shows is only shows:
test1
Why is the button being clicked failing to pass the if statement?
you need to specify a method type (post/get)
<form action="actions.php" method="POST">
Related
I want to call a function from an included file when a form is pressed:
<?php include 'app/lc.php'; $lc = new lc();?>
<form action="<?php $lc->create_user('1', '2'); ?>">
Email:<br>
<input type="text" name="lastname">
<br>
Password:<br>
<input type="text" name="lastname">
<br>
<input type="submit" value="Submit">
</form>
above I try to create an instance of the lc class and then run the create user function in that class.
However, this results in my code breaking at the action tag in the form. What am I doing wrong and how do I fix it?
You can't call a PHP function from a form's action tag. You need to put it in another file and then call it or call that other file using AJAX
E.G.
Form.php
<form action="createuser.php" method="post">
Email:<br>
<input type="text" name="email">
<br>
Password:<br>
<input type="text" name="password">
<br>
<input type="submit" name="cu" value="Submit">
</form>
CreateUser.php
<?php
include 'app/lc.php';
$lc = new lc();
if(!empty($_POST['submit']){
$lc->create_user('1', '2');
// or $_POST['password'], $_POST['email'], etc.
}
Id basically like the below submission to place text at the end of the url
example of what i want
http://example.com/(text) -- without the () obviously
example of what i don't want -- http://www.example.com/index.php?firstname=text
<form action="(end of current url)">
<fieldset>
search name
<br>
<input type="text" name="search" value="name">
<br>
<input type="submit" value="Submit"></fieldset>
</form>
id like to fix this via html or php either will do aslong as it submits the request to that :)
thank you in advance.
Using the POST method instead of GET.
<form action="" method="POST">
<fieldset>
search name
<br>
<input type="text" name="search" value="name">
<br>
<input type="submit" value="Submit"></fieldset>
</form>
In short you do the following:
<?php
// Get posted text
$text = strtolower(mysql_real_escape_string($_POST['text']));
// Do some cleanup here
// Redirect to page
if ($text != ''){
header( 'Location: http://www.example.com/' . $text );
}
// HTML output below (not before)
?>
<form method="post" action="">
<fieldset>
Search name<br />
<input type="text" name="text" /><br />
<input type="submit" value="Submit" />
</fieldset>
</form>
haven't programmed PHP in a while but I
have to assemble something for a client really fast.
I've set up 2 forms with POST but when I go to the next file it's just blank space, for some reason POST isn't being registered but is set cause I'm not getting an error echo.
Hese's the forms:
<form action="Funkcije.php" method="post" name="AddFromDB">
<input type="text" placeholder="Šifra Art" name="ArtNo">
<input type="submit" value="Dodaj">
</form>
<br>
<div id="newItem">
<form action="Funkcije.php" method="post" name="AddNew">
<input type="text" placeholder="Šifra" name="Art">
<input type="text" placeholder="Ime Proizvoda" name="ImeProizvoda">
<input type="text" placeholder="Dobavljač" name="Dobava">
<input type="text" placeholder="Cijena" name="Cijena">
<input type="submit" value="Dodaj">
</form>
</div>
And here's the 2nd file:
if(isset($_POST["AddFromDB"], $_POST["ArtNo"])){
addExisting ($_POST["ArtNo"]);
}
else if(isset($_POST["AddNew"], $_POST["Art"], $_POST["ImeProizvoda"], $_POST["Dobava"], $_POST["Cijena"])){
newItem ($_POST["Art"] && $_POST["ImeProizvoda"] && $_POST["Dobava"] && $_POST["Cijena"]);
}
else if (!isset ($_POST)){
echo "error";
}
So, by code I should be getting an error if POST is not set but I get nothing. Just a blank space.
here, you must be give a name to the submit button to check which form is POST like this...
<form method="post" name="AddFromDB">
<input type="text" placeholder="Šifra Art" name="ArtNo">
<input type="submit" value="Dodaj" name="form1">
</form>
<br>
<div id="newItem">
<form method="post" name="AddNew">
<input type="text" placeholder="Šifra" name="Art">
<input type="text" placeholder="Ime Proizvoda" name="ImeProizvoda">
<input type="text" placeholder="Dobavljač" name="Dobava">
<input type="text" placeholder="Cijena" name="Cijena">
<input type="submit" value="Dodaj" name="form2">
</form>
</div>
<?php
if(isset($_POST["form1"], $_POST["ArtNo"])){
echo "1";
}
else if(isset($_POST["form2"], $_POST["Art"], $_POST["ImeProizvoda"], $_POST["Dobava"], $_POST["Cijena"])){
echo "2";
}
else{
echo "error";
}
?>
now, this work fine..
thank you.. enjoy coding...
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 :)
I have two input forms and would like the second one to stay on the page even when it is submitted.
<div id="first">
<form method="POST">
Number: <input type="text" name="number"><br>
<input type="submit" value="Submit">
</form><br>
</div>
<div id="second">
<?php
if (isset($_POST['number']) && !empty($_POST['number'])){
?>
<form method="POST">
Name: <input type="text" name="name"><br>
<input type="submit" value="Submit">
</form><br>
<?php
}
?>
</div>
<div id="third">
<?php
if (isset($_POST['name']) && !empty($_POST['name'])){
echo "TEST";
}
?>
</div>
When I submit my first form, the second form appears correctly since $_POST['number'] is not empty. However, the content of 'number' disappears as soon as I submit it.
Then, when I submit the second form, the word "TEST" appears correctly but the form itself disappears since $_POST['number'] from the first form is now empty.
I need to find a way to somehow save the value of number in the first form so that the second form does not disappear.
Any suggestions?
You can add hidden field:
<input type="hidden" name="number" value="<?php echo $_POST['number']; ?>">
Then your second form will be changed to:
<form method="POST">
Name: <input type="text" name="name"><br>
<input type="hidden" name="number" value="<?php echo $_POST['number']; ?>">
<input type="submit" value="Submit">
</form