php form not passing variable through? - php

Hey guys I am not able to pass the variable "profile" through... This is done with smarty templates btw
{if $commentpossible == true}
<form name="form1" method="get" action="comment.php?profile=5">
<p>
<label for="comment"></label>
<textarea name="comment" id="comment" cols="45" rows="5" ></textarea>
<br>
<input type="submit" name="Submit" id="Submit" value="Submit">
</p>
</form>
{/if}
Basically this page is profile?profile=5 and I want to pass that profile through...I have "5 manaully inputed atm rather than a variable just too see if it would work...it still does not....when submit is hit it just goes to comment.php?comment=&Submit=Submit....(comment is blank intentionally there)...I need to be more comment.php?profile=5comment=blablabla etc etc
Any idea on what could be the problem?

Add profile as a hidden field when you're using the GET method:
{if $commentpossible}
<form name="form1" method="get" action="comment.php">
<input type="hidden" name="profile" value="5">
<p>
<label for="comment"></label>
<textarea name="comment" id="comment" cols="45" rows="5" ></textarea>
<br>
<input type="submit" name="Submit" id="Submit" value="Submit">
</p>
</form>
{/if}

Related

Undefined index: post from textarea

After sending, an error always flies to me Undefined index: post what to do? help please
if(isset($_POST['submit'])){
$description = htmlspecialchars($_POST['post']);
}
<form action="sell.php" method="POST" name="confirmationForm">
<textarea placeholder="Post your Comment Here ..." form="confirmationForm" name="post" class="form-control custom-control" rows="3" style="resize:none"></textarea>
<input type="submit" name="submit" value="Send Request">
</form>
Remove form="confirmationForm" from textarea.
Try this
<textarea placeholder="Post your Comment Here ..." name="post" class="form-control custom-control" rows="3" style="resize:none"></textarea>
While using form attribute in form elements, the id attribute of form should be same as form attribute of form elements. Like:
<form action="sell.php" method="POST" id="confirmationForm">
<textarea placeholder="Post your Comment Here ..." form="confirmationForm" name="post" class="form-control custom-control" rows="3" style="resize:none"></textarea>
<input type="submit" name="submit" value="Send Request">
</form>
Or remove form attribute from textarea.
The textarea value does not get send with the rest of your form data, because you associated it with a non-existing form reference, form="confirmationForm" - the value of this attribute must contain the ID of a form element.
Your form only has name="confirmationForm".
Add an id, or remove the form attrribute from the textarea.
Try this code...
<form action="sell.php" method="POST" id="confirmationForm">
<textarea placeholder="Post your Comment Here ..." name="post" class="form-control
custom-control" rows="3" style="resize:none"></textarea>
<input type="submit" name="submit" value="Send Request">
</form>

Form Emailing in HTML and PHP not working

i have created a form on my website that lets others contact me. I used a PHP script to send the email but i always get the error:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
I used this code:
<form method="post" action="contact.php" enctype="text/plain">
Name*:<br>
<input type="text" name="name" placeholder='Steve'><br>
E-mail*:<br>
<input type="text" name="mail" placeholder='john#example.com'><br>
Comment*:<br>
<textarea name="comments" maxlength="400" cols="25" rows="6">
This site is awesome!
</textarea>
<br> <br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
In html and this:
<?php
if($_POST["message"]) {
mail("myemail#example.com", "MCPEmaps Comment", $_POST["message"], "From: an#email.address");
}
?>
In the PHP file.
Any help?
You are POSTing comments, not message.
Change this:
<textarea name="comments" maxlength="400" cols="25" rows="6">
This site is awesome!
</textarea>
to this:
<textarea name="message" maxlength="400" cols="25" rows="6">
This site is awesome!
</textarea>
Change your html with this, As you are using $_POST["message"] but you are not passing it in your html.. So change your this line
<input type="submit" name="message" value="Send">
complete code below:
<form method="post" action="contact.php" enctype="text/plain">
Name*:<br>
<input type="text" name="name" placeholder='Steve'><br>
E-mail*:<br>
<input type="text" name="mail" placeholder='john#example.com'><br>
Comment*:<br>
<textarea name="comments" maxlength="400" cols="25" rows="6">
This site is awesome!
</textarea>
<br> <br>
<input type="submit" name="message" value="Send">
<input type="reset" value="Reset">
</form>
The PHP will not send the mail because there is no input : message
You can use :
<?php
if(isset($_POST["message"])) {
mail("myemail#example.com", "MCPEmaps Comment", $_POST["message"], "From: an#email.address");
}
?>
And
<input type="submit" name="message" />
Try this code in your contact.php file:
<?php
if($_POST["comments"]) {
mail("myemail#example.com", "MCPEmaps Comment", $_POST["message"], "From: an#email.address");
}
?>
If in case you are using in localhost you need to work lot in your php.ini file. otherwise you get result.

How do I echo submitted values from settings.php to mainpage.php?

I'm basically trying to get the values submitted from settings so that when the user submits it, it is displayed onto mainpage.php. Here's the code from what I have in settings.php...
<html>
<head><title></title></head>
<body>
Logout
Main Page
<form action="" method="get">
<b>Bio</b>
<br>
<textarea rows="5" cols="20" name="result" value="result"></textarea>
<br>
<input type="submit" value="Submit" name="bio">
</form>
<form action="" method="get">
<b>Hobbies</b>
<br>
<textarea rows="5" cols="20" name="result" value="result"></textarea>
<br>
<input type="submit" value="Submit" name="hobbies">
</form>
<form action="" method="get">
<b>Past School</b>
<br>
<textarea rows="5" cols="20" name="result" value="result"></textarea>
<br>
<input type="submit" value="Submit" name="school">
</form>
<form action="" method="get">
<b>Work History</b>
<br>
<textarea rows="5" cols="20" name="result" value="result"></textarea>
<br>
<input type="submit" value="Submit" name="work">
</form>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Choose Profile Picture:</label>
<input type="file" name="file" id="file">
<input type="submit" name="pic" value="Submit">
</form>
</body>
</html>
And this is what I have for mainpage.php
<?php
?>
<html>
<head><title></title></head>
<body>
Logout
Settings
</body>
</html>
Any suggestions?
As Jenna R said, it is better to use POST, not GET.
Then each variable is referenced with $_POST["name"], so $_POST["result"] and so on.
I suggest you start reading up on PHP and submitting forms securely if you are doing this for anything other than learning. This is pretty basic, so it looks like you haven't opened up the manual or a book just yet.

Pressing Enter on a <input> submits the wrong <form> (2 forms on 1 page)

I have got two different forms on the same page.
<form action="" method="post" onsubmit="ajax_send('<?print $userid;?>',this.msg.value); return false;">
<input id="msg" autocomplete="off" type="text" name="msg" stlye="width: 80px;" autofocus="autofocus" placeholder="Chat here" />
<input type="submit" />
</form>
and
<form action="?page=about&id=0#comments" method="post">
<textarea class="editbox" id="exitbox" placeholder="Write a comment ..." name="newcomment"></textarea>
<input type="submit" id="submit1" name="submit1"></div></div>
Now when I enter something in <input id="msg"..> and press enter, it submits the second form instead of the first one.
What am I missing?
Your second form isn't closed.
Your second form should by like that
<form action="?page=about&id=0#comments" method="post">
<textarea class="editbox" id="exitbox" placeholder="Write a comment ..." name="newcomment"></textarea>
<input type="submit" id="submit1" name="submit1"></div></div>
</form>

Open PHP Page On Button Click

I wonder whether someone could help me please.
I'm put together the following form contained within a PHP file.
<form name="savemyfindstolocation" id="savemyfindstolocation" method="post">
<p><label></label>
</p>
<p align="left">
<input name="userid" type="text" id="userid"/>
<input name="locationid" type="text" id="locationid"/>
<br />
</p>
<div>
<label>
<div align="left">Click on the map to place the marker for the find that has been made and drag until the precise location has been found. </div>
</div>
<p align="left"><label>Find OSGB36 Latitude Co-ordinate<br />
</label>
</p>
<div>
<div align="left">
<input name="findosgb36lat" type="text" id="findosgb36lat" size="20" />
</div>
</div>
<p align="left"><label>Find OSGB36 Longitude Co-ordinate<br />
</label>
</p>
<div>
<div align="left">
<input name="findosgb36lon" type="text" id="findosgb36lon" size="20" />
</div>
</div>
<p align="left"><label>Date of Trip<br />
</label>
</p>
<div>
<div align="left">
<input name="dateoftrip" type="text" id="dateoftrip" size="10" />
</div>
</div>
<input name="submit" type="submit" onclick="MM_callJS('savedata()')" value="Submit" />
</form>
It all works fine, but I'd now like to add a button that opens the following php page, 'blobupload.php'. If I've understood this correctly from the research that I've done, I need to use javascript to open the page, using the 'submit' action from the main form.
What I don't understand is how to do this when the 'submit' action is already taken for the saving of the information on the main form.
Could someone perhaps please show me how to get around this, i.e. using the same 'submit action but for two different purposes.
Just modify your form tag (add the action attribute to file you want to load):
<form name="savemyfindstolocation" id="savemyfindstolocation" method="post" action="blobupload.php">
And you submit input tag:
<input name="submit" type="submit" value="Submit" />
You can use a second javascript function to open new window like this way
<input name="submit" type="submit" onclick="MM_callJS('savedata()');SECOND_JS_FUNCTION()" value="Submit" />
Use php to process the form is one of the way to do it.
<input name="submit" !!!!!!action="process.php" method="POST (or get)!!!!!!!!!! type="submit" onclick="MM_callJS('savedata()')" value="Submit" />
that way the the variable will be passed to the process.php while you can also redirect the page in the process.php
header("Location:URL");

Categories