Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am working on a site to help learn some PHP MVC. At the moment the site carries out the CURD commands but I am looking to improve on them.
The items of the database are displayed in on column with two buttons, one to delete and one to update. When the user clicks the update button a form (update_item_form.php) is displayed that will allow the user enter the item information to be update. The form consists of three fields (title, price and description)
What I am trying to do: When the user clicks the update button the form will be pre populated with all the item information connected with that row.
How will can I send the row information to the form when the user clicks the button?
file_get_contents()
$rightBox = file_get_contents( "templates/update_item_form.php" [database value] );
Update_item_form.php
<h2>Update Item!</h2>
<h4>Fill in the form to update an entry.</h4>
<form action="index.php" method="post">
<fieldset>
<input id='action' type='hidden' name='action' value='updateItem' />
<p>
<label for="fTitle">Title</label> <input type="text"
id="fTitle" name="fTitle" placeholder="title"
maxlength="25" required />
</p>
<p>
<label for="fPrice">Price</label> <input type="text"
id="fPrice" name="fPrice" placeholder="price"
maxlength="25" required />
</p>
<p>
<label for="fDescription">Description</label> <input type="text"
id="fDescription" name="fDescription" placeholder="description"
maxlength="500" required />
</p>
<p>
<div class="form-group">
<div class="controls">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</p>
</fieldset>
file_get_contents won't parse a PHP file. All you're doing is loading the code into $rightBox, not the output that I assume you are after.
For that, you can use output buffering.
ob_start();
include "templates/update_item_form.php";
$rightBox = ob_get_clean();
This will store output between ob_start() and the ob_get_clean() into $rightBox.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
this is some stupid but i dont know.
How i can export the action to two differents sections from submit button?
I want the cancel button to take me to one page and the accept button to take me to another. How can I apply a conditional that takes different actions?
My buttons are Accept and Cancel...
<section>
<form action="/news">
<input type="submit" id="button" value="Accept"> <input type="submit" class="button2" value="Cancel">
</form>
</section>
<!doctype html>
<html>
<head>
</head>
<body>
<form action="submit.html">
<label for="name">Name</label>
<input type="text" name="name">
<label for="lastname">Last Name</label>
<input type="text" name="lastname">
<button type="submit" id="submit">submit</button>
<button type="cancel" formaction="cancel.html">cancel</button>
</form>
</body>
</html>
Basically with html you can make different action in form like this
This question already has answers here:
Send email with PHP from html form on submit with the same script
(8 answers)
Closed 5 years ago.
The question is how do i make the submit button work so if they press submit, the ff will be send to my email (ex: example#gmail.com).'
If PHP is needed please post the code so i just gonna paste it on my code :D ty
<div id="forms">
<form class="form">
<p class="name">
<input type="text" name="name" id="name" placeholder="Enter Your Name" />
</p>
<p class="email">
<input type="text" name="email" id="email" placeholder="mail#example.com" />
</p>
<p class="text">
<textarea name="text" placeholder="Describe your logo" /></textarea>
</p>
<p class="submit">
<input type="submit" value="Send" />
</p>
</form>
</div>
I cannot find the answer in the existing question of this, So i decided to make another one... the existing is like 2 years ago?
I think you just need to put a mailto action on the <form> tag, i.e.:
<form class="form" action="mailto:someone#example.com">
All you need to do is change your form tag to look like this:
<form action="mailto:address#example.com">
This will send unformatted data to your email address without needing PHP. If you would rather format it in a specific way, then you can use the PHP mail function.
I also removed class="form". Typically this is not needed, but it depends on your reason. If you are using class for CSS you can just reference the element form rather than the class name .form.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
NOTE: Possible duplicate question is not helpful, as it does not compensate for multiple options for different pages while also passing form information.
I need to take user input from the current page (for now, this is just a single text field), and there are three buttons. The three buttons are supposed to go to different pages respectively, but all three need the value from the text field to do their job.
Essentially, I need to "pass" the value from the text field to either of the three pages that the buttons should redirect to. Currently, the buttons are unable to redirect as I do not know how to do that.
This is my code thus far:
<html>
<body>
<form name="form" action="" method="post">
Name: <input type="text" name="name" value="<?php echo $name;?>">
</form>
<button type="button">button1</button>
<button type="button">button2</button>
<button type="button">button3</button>
</body>
</html>
No JavaScript please.
<?php
if(isset($_POST['button1'])){
$link='index_1.php?name='.$_POST['name'];
header('location:'.$link);
}elseif(isset($_POST['button2'])){
$link='index_2.php?name='.$_POST['name'];
header('location:'.$link);
} elseif(isset($_POST['button3'])){
$link='index_3.php?name='.$_POST['name'];
header('location:'.$link);
}
?>
<form action="" method="POST">
Name: <input type="text" name="name" value="">
<button type="submit" name="button1" value="button1">button1</button>
<button type="submit" name="button2" value="button2">button2</button>
<button type="submit" name="button3" value="button3">button3</button>
</form>
The page where a form leads to is defined in its action attribute of the formtag. Just write the filepath + filename into that attribute and after submitting, you'll be redirected to that page and can use the POST parameter values there.
But you'll need to add a submit button - one, not three, and as an input tag
Use the submit type, and the check the value for the submitted (or the name you want to put it) in the PHP file, if the value is "button1" do something, if its "button2" etc.
<form action="/action_page.php" method="POST">
Name: <input type="text" name="name" value="<?php echo $name;?>">
<button type="submit" name="submited" value="button1">button1</button>
<button type="submit" name="submited" value="button2">button2</button>
<button type="submit" name="submited" value="button3">button3</button>
</form>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have simple email script with few forms and I am getting duplicate submissions...
So, what is the easiest way to prevent duplicate submissions?
My code..
<form action="main_contact.php" method="post" name="contact_form">
<input type="text" name="contact_name" placeholder="Name">
<input type="email" name="contact_email" placeholder="Email">
<input type="text" name="contact_subject" placeholder="Subject">
<textarea cols="30" name="contact_message" rows="10" placeholder="Your Message"></textarea>
<input type="submit" value="Send">
</form>
<?php
if(isset($_POST['contact_form'])){
var_dump($_POST);
}
?>
You can use jQuery to disable submit button after the form has been submitted:
$('form[name="contact_form"]').submit(function(){
$(this).find('input[type="submit"]').prop('disabled', true);
});
you just need to disable or make visibility hidden after just click on submit button. fist give a id to the submit button
<input type="submit" value="Send" id="sub_id">
and then make it hidden or disable in javascript once you submit the form
document.getElementById('sub_id').style.visibility='hidden';
If you used any framework like Laravel5 or Symfony you would get it "out of the box".
In short:
Register a session token and invalidate it after first form submission.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
This question will more than likely result in an easy answer, however I am at a roadblock until hopefully someone can help, as I am new to PHP.
So I had a basic registration page in HTML and styled in CSS for my website, however it obviously did nothing. So I acquired the necessary PHP files to make it all work, and tested the PHP on a localserver and it was excellent as anticipated.
However my question is, how can I bring the functionality of the PHP into my already created SignUp.html page?
Or do I need to somehow style the PHP and scrap my current html and css files?
I'll attach my current basic html code in the event that helps.
<h2>Sign Up</h2>
<div id="form-data">
<fieldset>
<div class="fieldgroup">
<label for="name"> Username</label>
<input type="text" name="name">
</div>
<div class="fieldgroup">
<label for="name">First Name</label>
<input type="text" name="name">
</div>
<div class="fieldgroup">
<label for="name">Last Name</label>
<input type="text" name="name">
</div>
<div class="fieldgroup">
<label for="email">Email</label>
<input type="text" name="email">
</div>
<div class="fieldgroup">
<label for="password">Password</label>
<input type="password" name="password">
</div>
<div class="fieldgroup">
<p class="right">By clicking register you agree to our <a target="_blank" href="#">policy</a>.</p>
<input type="submit" value="Sign up" class="submit">
</div>
</fieldset>
</div>
Rename the .html file to the .php extension and then put the PHP code into it.
Probably something like:
if(isset($_POST['sent']))
{
// PROCESS FORM IN PHP HERE
}
will help you when modifying the submit button to:
<input type="submit" name="sent" value="Sign up" class="submit">
You can change the extension of the .html files to .php to bring the functionality of PHP to your files. The HTML will still be treated as HTML, so there is no need to change the HTML markup if you change the extension.
You can also "instruct Apache to treat .html as PHP." as #Fred-ii- said.
For running the form through PHP, you can either direct the form to a .PHP file like so:
<form action="phpfile.php" method="*post OR get*">
or you can run it on the page the form is on like so:
<form action="" method="*post OR get*">
<!-- Form Contents Here -->
</form>
<?php
if(isset($_POST['submit'])) {
// PHP code here
}
?>