I don't know what the heck the problem is with this form not working. The form is not to be sent anywhere. It's just a questionnaire for clients to fill/print out if they like, but I cannot get the results to post into the hidden div. What am I doing wrong? I installed a wordpress php plugin and other php echo's work, but not the POST thing. The HTML:
<form method="post">
<input type="text" placeholder="Your Name" name="yourname" />
<br /><br />
<input type="text" placeholder="Pet's Name" name="petsname" />
<br /><br />
<input type="text" placeholder="Pet's Birth Date" onfocus="(this.type='date')" onblur="(this.type='text')" id="date" name="petsbirthdate" />
<br /><br />
<strong>Pet's Sex</strong>: <input type="radio" value="Male" name="sex" id="Male" /><label for="Male">Male</label> <input type="radio" value="Female" name="sex" id="Female" /><label for="Female">Female</label>
<button type="button" class="button" onclick="show_output();">Display
Answers</button>
</form>
Pay no attention to the onclick handler on the button. I'm not including that JavaScript, but just know that the hidden div does show when the button is clicked. The PHP that returns no form results: Pay no attention to the PHP in brackets, that's the way it works in WordPress with the plugin.
<p class="data_answers">
<strong>Your Name:</strong> [php]echo htmlspecialchars($_POST['yourname']);[/php]</p>
<p class="data_answers">
<strong>Pet's Name:</strong> [php]echo $_POST['petsname'];[/php]</p>
<p class="data_answers">
<strong>Pet's Birth Date:</strong> [php]echo $_POST['petsbirthdate'];[/php]</p>
<p class="data_answers">
<strong>Pet's Sex:</strong> [php]echo $_POST['sex'];[/php]</p>
The PHP that will work (anywhere; I even placed it in the middle of, where the form answers should be, and it shows up. So why doesn't the other work?
[php] echo "Hello world!"; [/php]
Thank You!
Tracy
P.S. Although you cannot see the PHP, but the actual page in draft is here: http://www.safarivet.com/behavior-conditions/
You should add the action attribute in the form tag
<form method="post" action="">
..leads back to the same page
Extending from Johannes answer, you can also use a number sign # or the global variable $_SERVER['PHP_SELF']
Either of these will work
<form method="post" action"">
<form method="post" action"#">
<form method="post" action"<?php echo $_SERVER['PHP_SELF']?>">
Related
I have been trying to pre-fill the subject input with information generated in another page, but have been having difficulties with it despite reading a lot of resources about it and seeing examples. I have tried a variety of links, including my most recent attempt with http://www.myurl.com/folder/index.php/contactform?subject=test, but even that doesn't work. Anybody have any advice? Also, if you want to test it out before answering, the page experiencing the problem is the contact page of this website. I've removed information from below to make it more general. Thanks in advance for any and all of the help.
<form id="contactform" method="post">
<input name="recipient" type="hidden" value="myemail" />
<input name="subject" type="hidden" value="Contacter" />
<p id="contactname">
<label>Name:</label>
<input name="name" type="text" />
</p>
<p id="contactemail">
<label>Email:</label>
<input name="email" type="text" />
</p>
<p id="title">
<label>Subject:</label>
<input name="title" type="text" />
</p>
<p id="contactmessage">
<label>Message:</label>
<textarea name="message"></textarea>
</p>
<p id="submit">
<input type="button" value="Send" />
</p>
<input name="redirect" type="hidden" value="myredirectpage" />
</form>
Lets say your page URL is some thing like below
http://www.example.net/index.php?var1=Something&var2=10&var3=ok
You can use $_GET to get the values of var1, var2,and var3 from the above url
In index.php use the below code to fetch url data
echo $_GET['var1'] // Something
echo $_GET['var2'] // 10
echo $_GET['var3'] // ok
Go through this link http://php.net/manual/en/reserved.variables.get.php
With php you can do this with a session.
On the other page(not the form) you can do $_SESSION['subject'] = 'your subject';
On the form page you can acces this cookie ( make sure you have started the session on top of the page with session_start():
<p id="title">
<label>Subject:</label>
<input name="title" type="text" value="<?= $_SESSION['subject'] ?>"/>
</p>
My goal is to populate a hidden form field with the utm_source from url.
Basically this:
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET["utm_source"] ?>" />
The problem is this form works perfectly on one page, but not on another.
Working: museumhack.com/test-a/?utm_source=hello (form field is hidden, but populates value)
Not working: museumhack.com/test-b/?utm_source=hello (at the bottom)
It seems like the pages may be processing the double quotes differently, but not clear how to fix. Wordpress required a plugin to process on page PHP -- I installed that and don't think it's the problem.
Here is the entire form that I copy/pasted between pages:
<form action="http://museumhack.createsend.com/t/d/s/ihhykl/" method="post" id="lead-capture">
<p>
<input id="fieldName" name="cm-name" type="text" placeholder="Your Name"/>
</p>
<p>
<input id="fieldEmail" name="cm-ihhykl-ihhykl" type="email" placeholder="you#email.com" required />
</p>
<p>
<input id="fieldjuuilj" name="cm-f-juuilj" type="text" placeholder="(212)555-5555" />
</p>
<p>
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET["utm_source"] ?>" />
</p>
<p>
<button type="submit">Request Quick Quote</button>
</p>
Thanks,
Try this code , this might help you
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET['utm_source']='';?>">
I have been reading extensively about this and cannot seem to find a resolution. I have created a form in PHP which I want to submit to the same page I am on. I have read that there are some name's that wordpresses reserves such as "name" - which I am not using. Does anyone have any idea why this redirects to page not found upon submission?
http://hybridhosting.net/markeim/properties/52-coles-road/
<form action="" method="POST">
<input type="hidden" id="my_favorite_nonce" name="my_favorite_nonce" value="a87e4a44aa"><input type="hidden" name="_wp_http_referer" value="/markeim/properties/52-coles-road/"> <input type="hidden" name="form_title" value="brokercontact">
<input type="hidden" name="brokers" value="testemail#gmail.com">
<p>
Your Name
<span>
*
</span>
<br>
<input type="text" id="yourname" name="yourname" class="ink">
</p>
<p>
Your E-mail
<span>
*
</span>
<br>
<input type="text" id="youremail" name="youremail" class="ink">
</p>
<p>
Your Message
<span>
*
</span>
<br>
<textarea cols="" rows="" id="yourmessage" name="yourmessage" class="lab"></textarea>
</p>
<p>
<input type="submit" class="sending" value="Contact Broker">
</p>
</form>
It's something to do with your hidden input fields, not sure what. When I delete the nodes from dev tools and submit the form, it goes through fine!
Delete the hidden input field with name="brokers" and you'll see
I'm guessing WP uses the term "brokers" for something, please see here:
http://contactform7.com/faq/are-there-any-reserved-or-unavailable-words-for-the-name-of-an-input-field/
I have this basic form for edit users, and Im showing the name and the phone in my inputs.
The name is working fine, but my phone its not appearing.
The only difference, and probably the difference that is ruining everything, is that Im using in my phone input the id="ph" that corresponds to a mask that I am using through jquery like this:
jQuery(function($){
$("#date").mask("99/99/9999 99:99:99");
$("#ph").mask("(99) 9999999");
});
Someone there knows how I can solve this problem? Maybe something like strip_tags() but for jQuery, but I dont find nothing about this!
My Basic form:
<form name="form" action="" method="post" enctype="multipart/form-data">
<label class="line">
<span class="data">Name:</span>
<input type="text" name="name" value="<?php echo $resultReadUserEdit['name'] ; ?>" />
</label>
<label class="line">
<span class="data">Phone number:</span>
<input type="text" id="ph" name="phone" value=" <?php echo $resultReadUserEdit['phone'] ; ?> " />
</label>
<input type="submit" value="Edit user" name="sendForm" class="btn" />
</form>
I am just a beginner with PHP & Html. I have seen many questions on SO related to this, but somehow cannot fix a very simple looking problem at my end. So, kindly help.
The following code does not seem to be working. There is always a message "There seems to be a problem right now. Please try again after sometime" before the form when I run this code. Whether I press the submit button or not, it does not make any difference.
<h2 >Inquiry form</h2>
<?php
if (isset($_POST['submit'])){
echo "Thank You!";
}
else {
echo "There seems to be a problem right now. Please try again after sometime";
}
?>
<form name="input" method="POST" action="contact.php">
<label for="Name">Name (required):</label>
<br />
<input type="text" name="Name" />
<br />
<div class="clear"></div>
<label for="inputmail">Email(required):</label>
<br />
<input type="text" name="email" />
<br />
<div class="clear"></div>
<label for="inputtelefon">Phone:</label>
<br />
<input type="text" name="phone" />
<br />
<div class="clear"></div>
<label for="inputmessage">Message:</label>
<br/>
<textarea name="message" cols="28" rows="3" ></textarea>
<div class="clear"></div>
<div id="send">
<input type="submit" value=" Submit " />
<input type="reset" value=" Clear " />
</div>
</form>
Changed code:
<h2 >Inquiry form</h2>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//if ($_SERVER['REQUEST_METHOD'] == 'POST') { This is not working as well
echo "Thank You!";
}
else {
echo "There seem to be a problem right now. Please try again after sometime";
}
?>
<form name="input" method="POST" action="contact.php">
<label for="Name">Name (required):</label>
<br />
<input type="text" name="Name" />
<br />
<div class="clear"></div>
<label for="inputmail">Email(required):</label>
<br />
<input type="text" name="email" />
<br />
<div class="clear"></div>
<label for="inputtelefon">Phone:</label>
<br />
<input type="text" name="phone" />
<br />
<div class="clear"></div>
<label for="inputmessage">Message:</label>
<br/>
<textarea name="message" cols="28" rows="3" ></textarea>
<div class="clear"></div>
</div>
<div id="send">
<input type="submit" value=" Submit " name="submit"/>
</div>
</form>
That's because your submit button does not have a name:
<input type="submit" value=" Submit " name="submit"/>
Edit
Based on the comment of RandomCoder (in Marc B's answer).
Found this similar question: isset($_POST['submit']) vs $_SERVER['REQUEST_METHOD']=='POST'
Invalid method of checking for a submission. Never check for the presence/absence of a form field. It's unreliable. You might change the field name, but forget to update the PHP. Use this instead:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
...
}
it's 100% reliable and will always be "true" if a POST was performed.
Take a look at your updated if statement. It is saying: if the form has been submitted then show "thank you", if the form hasn't been submitted then show "there seems to be a problem".
That's the reason you're always seeing "there seems to be a problem", because when you view the form without submitting it, the else block of your if statement fires.
You should remove the else block because it doesn't make any sense, so it becomes:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// form has been submitted, handle the data and say thanks...
echo "Thank You!";
}
Using this method instead of checking for the submit button is better because Internet Explorer will not send the submit button as a post variable if the user pressed the enter key to submit the form.
More info - Why isset($_POST['submit']) is bad.
There is Only one reasons which I see i.e. you have not defined the name submit to any variable. There are two ways to find the submitting form as:
Either change:
<input type="submit" value=" Submit " />
to
<input type="submit" value=" Submit " name="submit"/>
or add the extra line to do things something like this
<input type = "hidden" name="passed" />
and to check
<?php
if (isset($_POST['passed'])){
echo "Thank You!";
}else {
echo "There seems to be a problem right now. Please try again after sometime";
}
?>