I have a Joomla site that I am building a form for. The form is working fine in a localhost test environment but when I put it on my live server, the form would not work properly. I stripped out code until I basically just had the form and I still have issues, the form is very slow to submit and display the data, it could take minutes for the updated data to display and I have to refresh the page to get it. On another server the form works properly. Data is displayed as fast as the submit button is clicked.
I've been fighting this for a couple of days and have gotten nowhere.
Here is the form:
<form action="<?php $_SERVER['REQUEST_URI'] ?>" method="post">
<select name="vendor_num">
<option value="" selected="selected" > Select a Vendor </option>
<option value="000000" >All Vendors</option>
<option value="008064" >Great Glacier Salmon</option>
<option value="008173" >Seed 2 Sausage</option>
<option value="008219" >Back Forth Artisan Cheese</option>
<option value="008215" >True North Salmon</option>
</select>
<br />
<label for="prov_ont">
<input type="radio" id="prov_ont" name="prov" value="Ontario" > Ontario
</label>
<br />
<label for="country_canada">
<input type="radio" id="country_canada" name="country" value="Canada" > Canada
</label>
<br />
<label for="kosher">
<input type="radio" id="kosher_flag" name="kosher" value="Y" > Kosher
</label>
<br />
<label for="halal">
<input type="radio" id="halal_flag" name="halal" value="Y" > Halal
</label>
<br />
<label for="oceanwise">
<input type="radio" id="oceanwise_flag" name="oceanwise" value="Y" > Oceanwise
</label>
<br />
<input type="submit" name="submit" value="submit" style="padding:5px; margin-top:20px;">
<input type="reset" value="reset" name="reset" style="padding:5px; margin-top:20px;">
</form>
<pre>
<?php
var_dump($_POST);
echo "<br />";
?>
</pre>
the problem URL is: http://findlayfoods.com/search-test
Here is another host with the same page working:
http://glenntooth.com/index.php/form-test
I have also tried with action="", exactly the same thing.
I am admittedly a beginner but have been working on this for a while. Help appreciated.
G
Related
I have the following code to submit GET values:
<form method="GET">
<input type="hidden" name="price" value="ASC" />
<input type="submit" value="Price Low to High" />
</form>
<form method="GET">
<input type="hidden" name="price" value="DESC" />
<input type="submit" value="Price High to Low" />
</form>
<form method="GET">
<input type="hidden" name="price" value="" />
<input type="submit" value="Default" />
</form>
Which is working fine. So I am not repeating myself with three forms, is there a way I could have a single form, and define what GET values are submitted by the buttons? They would still need to have the same information visible to the user e.g. the button that submits DESC needs to display as Price High to Low
use this code:
<form method="GET">
<input type="submit" name="price" value="ASC">Price Low to High</input>
<input type="submit" name="price" value="DESC" >Price High to Low</input>
<input type="submit" name="price" value="" >Default</input>
</form>
If having three buttons is not obligatory by design, then I suggest, why not just use a select to let the user decide what he wants (as most of the sites already do)
<form method="GET">
<select id="price" name="price">
<option value="">Default</option>
<option value="ASC">Price Low to High</option>
<option value="DESC">Price High to Low</option>
</select>
<input type="submit" value="Price Low to High" />
</form>
Demo
And if having three buttons is necessary then, you could do either one of (though not limited to) the following..
Use plain links (<a> anchor tags), yup you read that correct, since the form is just submitting using the $_GET method, eventually the data is gonna be inside the URLs, so why not just have it there in the first place using the href attributes of the "buttons" ?
Use the solution that #Aref Anafgeh suggested, and have three submit buttons each with different values and just let the html handle which value is sent to the server.
Use JavaScript and make ajax calls, which pretty much allows you to handle what is & isn't sent in the request.
Try this code.
<!DOCTYPE html>
<html>
<body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "GET")
{
echo "Form Submited by ".$_GET['submitbutton']." Button";
}
?>
<form method="GET" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="hidden" name="price" value="ASC" />
<input type="submit" value="Price Low to High" name="submitbutton"/>
</form>
<form method="GET" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="hidden" name="price" value="DESC" />
<input type="submit" value="Price High to Low" name="submitbutton"/>
</form>
<form method="GET" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="hidden" name="price" value="" />
<input type="submit" value="Default" name="submitbutton"/>
</form>
<script>
</script>
</body>
</html>
<form method="get">
<select name="sort">
<option value="asc">Ascending</option>
<option value="desc">Descending</option>
<option value="default">Default</option>
</select>
<button name="price">Sort price ascending</button>
</form>
snip
<?php if ($_GET['sort'] == "asc") {
// Do something
} elseif ($_GET['sort'] == "desc") {
// Do something else
}
// etc
?>
Hyperlinks to http://url/?price=XXX would also work fine since you're using GET
<html>
<BODY>
<form action= "myscript.php" method="post">
first name: <input type="text" name="firstname" value="Mary"><br>
Last name: <input type="text" name="lastname" value= "clan"><br>
<input type="checkbox" name="mychoices[]" value="choice1" checked>
<input type="checkbox" name="mychoices[]" value="choice2">
<input type="checkbox" name="mychoices[]" value="choice3">
<select name="myselection">
<option value="selection1" selected>Option1</option>
<option value="selection2">Option2</option>
<option value="selection3">Option3</option>
</select>
<select name="myselections[]" size="3" multiple>
<option value="choice1" selected >Choice1</option>
<option value="choice2" selected>choice2</option>
<option value="choice3">choice3</option>
</select>
<textarea name="mytextarea" rows="10" cols="40">
Welcome to the web developement world.
</textarea>
<input type="password" name="mypassword">
<input type="hidden" name="myname" value = "myvalue">
<input type="reset" value="reset form">
<input type="image" name="myimage" src="desert.jpg" height="42" width="42" onclick= "document.write('<? php Aftersubmit() ?>');"/>
<input type="submit" name="submitbutton" value="Submit Form">
</form>
<?php
function Aftersubmit()
{
$myname = $_POST['myname'];
if(isset($myname)){
echo ($myname);
}
}
?>
</BODY>
</HTML>
I want to display the value of hidden tag after clicking submit button. But getting "Object not found" error 404. Beginner in php, pls help. I also want to know how to call php functions from html.
You can't call a PHP function from an onClick event. That only works with Javascript functions. So one problem is in this line:
onclick= "document.write('<? php Aftersubmit() ?>');
You can remove that, and then pull your PHP out of the function. This will display your name if you click the submit button.
<?php
if(isset($_POST['submitbutton'])){
$myname = $_POST['myname'];
if(isset($myname)){
echo ($myname);
}
}
?>
You may also have to change the action of your form:
<form action= "myscript.php" method="post">
If the file myscript.php doesn't exist, then you'll get a 404 Not Found error every time. You can make a form point to itself by removing the action attribute:
<form method="post">
I have a form with a simple file upload input like:
<div class="contenttitle radiusbottom0">
<h2 class="finfo"><span>Uploader</span></h2>
</div>
<p>
Chose your file: <input type="file" name="uploaded_file" />
</p>
the rest as well, is a very simple form. Now when I execute (submit) this form it takes about 30 seconds to process it. Even when I don't choose any file to upload.
When I remove the file input from the form then it takes 1 second max. I add it back and it takes a lot of time again. The action page does not matter. What could be the problem?
here is the complete form:
<div class="boxwhite">
<form class="stdform" enctype="multipart/form-data" method="post" action="">
<div class="two_third">
<p>
<label>Header</label>
<input type="text" name="title" id="firstname" class="longinput" value=""/>
</p>
</div>
<div class="one_third">
<p>
<label>Status</label>
<select name="status">
<option value="1" <?= $content[status]==1?'selected':'' ?> >Active</option>
<option value="0" <?= $content[status]==0?'selected':'' ?> >Pasive</option>
</select>
</p>
</div>
<br clear="all" />
<input type='hidden' name='parent_id' value='3' />
<div class="contenttitle radiusbottom0">
<h2 class="finfo"><span>Uploader</span></h2>
</div>
<p>
Chose your file: <input type="file" name="uploaded_file" />
</p>
<BR />
<input type="submit" name="submit" value="Add" class="" />
<button class="cancel radius2">Cancel</button>
</form>
</div>
(this files are on a windows server)
I have moved the work to a linux server. Everything works fine now.
So I'm recycling a nice simple e-mail contact form that I have from other sites:
<form method="post" action="javascript:loadContent('#bodyContent','/wp-content/themes/GenomeStudios2013/sendmail.php');"> <!--javascript:loadContent('#rightColumn', 'sendmail.php');-->
<h1>Contact Us</h1>
<br /><br />
<p><font color="red">*</font>Name:</p>
<p><input name="name" type="text" cols="30" /></p>
<br />
<p><font color="red">*</font>Email:</p>
<p><input name="email" type="text" cols="30" /></p>
<br />
<p>Contact Topic:</p>
<select name="topic">
<option value="Feedback">Feedback</option>
<option value="Bug Report">Bug Report</option>
<option value="Press">Press</option>
<option value="Complaint">Complaint</option>
<option value="Suggestion">Suggestion</option>
<option value="Business">Business</option>
<option value="Job Information">Job Information</option>
</select>
<br /><br />
<p><font color="red">*</font>Message:</p>
<p><textarea name="messageBox" cols="30" rows="5"></textarea></p>
<br />
<p>Would you like to recieve a reply?</p>
<p>Yes:<input type="radio" name="reply" value="yes"/> No:<input type="radio" name="reply" value="no"/></p>
<br />
<p><input type="submit" name="submitButton" value="Send" /></p>
But I'm now trying to load the result page into the div that this page was loaded in instead of reloading the whole page. This however doesn't allow the form to pass the field information to the 2nd page to process.
I've tested it and all I get is a blank e-mail.
Is there a way to pass that info through to the 2nd page even though javascript is loading it instead of a full page load?
loadContent - is not native js function, you need check did you copy from that site the script with the function "loadContent"
But, I see you use WP, then I would advise use cforms-plagin it has GPL and easy to use for create forms
Basically, I want made a simple form in html and i want to output the all of the user input once clicked submit using php. So far its just displaying the details I entered but it doesn't get user's data to echo them out. Here are my two files
output.php:
<?php
echo 'Name: '.$POST["name"].'<br /> Gender: '.$POST["gender"].'<br />Country: '.$POST["country"];
?>
testingformphp.html (form part):
<form id="form" name="form" method="post" action="./PHP/output.php"/>
Name<input name="name" type="text" id="name"/><br/>
Gender<label><input type="radio" name="gender" id="gender_0" value="male"/>Male</label><br/>
<label><input type="radio" name="gender" id="gender_1" value="female"/>Female</label><br/>
<select name="country" id="select">
<optgroup title="europe">
<option value="Russia">Russia</option>
<option value="Greece">Greece</option>
</optgroup>
</select>
<input type="submit" id="button" value="Submit"/>
<input type="reset" id="reset" value="Reset"/>
</form>
Can anyone help?
$POST does not exists, try $_POST.
<?php
echo 'Name: '.$_POST["name"].'<br /> Gender: '.$_POST["gender"].'<br />Country: '.$_POST["country"];
?>
http://www.tizag.com/phpT/postget.php To review the post and get method.