I have a database with some numbers assigned to a fake account (PHP).
I try to contact the database (with success) and get the right result from the form.
My issue is that the form result open a new page and display there...
I would really like the result to be displayed IN the module I use to send the form OR anywhere else on the same page I used to send the form.
<!DOCTYPE html>
<html>
<body>
<form
method="post"
action="http://ggdbase.dx.am/impulseGetInfo.php"
target="_self">
Account name:<br>
<input type="text" name="name" value="derps">
<br>
<input type="submit" value="Click To Load Account Info">
</form>
</body>
</html>
This is what the module look like (on Enjin.com)
This is what I get when clicking the button
I did try replacing '_self' with '_blank' or parent and all the other options I could find but none of them gave me a different result :S
Could it be caused by the Enjin system itself ?
Do not use target. And replace the action as
action=""
This will ensure that you are calling the same page. Write the PHP code there itself.
Hope that help!
Related
Hi guys im quite newbie on coding but i want to ask How to post HTML FORM Data to a http link given to you by a client thanks.
Try creating a .html file as below:
<html>
<form method="post" action="urclientlink">
<input type="text" name="firstname"/>
<input type="text" name="lastname"/>
<input type="text" name="submitButton" value="Submit Form"/>
</form>
</html>
Please elaborate on your question for a better answer. Thanks!
This is no different from submitting form data to a page on your own site. You simply amend the form's action attribute:
<form action="http://another-server.com/another-page">
You also need to be sure you get the right METHOD: e.g. GET or POST:
<form action="http://another-server.com/another-page" method="GET">
You will need to check with the client to see which page and method they need.
I have my page as follows:
<form id="filterQuery" action="#" method="post">
...
<input type="submit">
</form>
<?php
// use $_POST to determine query restrictions and conditions
?>
Now my problem is with the action of the form, because if I make it "#" self, nothing happens when clicking submit.
I'm using a template which shows subpages as include in <div>s. In other words, my page is not a standard HTML page which contain <head> and <body> etc, but is in the following format: basic.php#!/my_sub_page.
Trying to make action "basic.php#!/my_sub_page" results in an empty _POST
I tried your example and everything works fine with /index.php#!/smth in action and post variables.
<form action="#!/something" method="post">
<input type="text" name="var1" value="123">
<input type="submit"></form>
<?php
print_r($_POST);
?>
This is how I check it.
Are you sure you didn't forget name attributes in inputs?
Do you see their values in url after ? if you change method to get?
what I am trying to do is to create a from, and execute a php script after the submit has been pressed. the problem seems to be that the page of wprdpress with the form and the code gets executed all at once.
If I put the code below into a regular test.php file on my server, it does what it is supposed to do (echo "Form Submitted!") after I click submit. However if I put the same code in a page template or a wp page it spits it out all at once (the form, and the "form submitted).
<html>
<head>
<title>Notify on Submit</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<label>Name: <input type="text" name="name" /></label>
<input type="submit" value="Submit" />
</form>
<?php if (count($_POST)>0) echo "Form Submitted!"; ?>
</body>
</html>
I have no idea why this is like that, and would really need some help on this.
What I have also done is to create two different wp pages(one goes to the other). It works, but will create a bit of a mess. I would like to do this in one page.
page 1
<form action="page2" method="POST">
Your form input.
<input type="submit" name="submit" />
</form>
Page 2
<?php
if (count($_POST)>0)
{
echo "Form Submitted!";
unset($_POST);
$_POST = array();
}
else echo "Form has been reset!";
?>
Probably there is another form on the Wordpress page using the POST method. Instead of checking for $_POST > 0 (which will only tell you that something was posted) add some identifier to your form, and check for that so you can tell if your form was posted.
A simple way to do this is with a hidden input:
<html>
<head>
<title>Notify on Submit</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<label>Name: <input type="text" name="name" /></label>
<input type="hidden" name="whatform" value="myform" />
<input type="submit" value="Submit" />
</form>
<?php if (isset($_POST['whatform']) && $_POST['whatform'] == 'myform') echo "My Form Submitted!"; ?>
</body>
</html>
I think you just need to remove the php from your action. The action defaults to the current url on any form.
PHP_SELF refers to the file path - thats why it works when you do it on just a solo file. As part of the wordpress application, you can't run files directly - you have to reach that url.
Remember that WP uses actions and hooks, and so if you put code "in a WP page" or "in a template" it may fire at various times. You might get an echo statement that fires something to the screen before the content comes out. Consider putting all your output within filters, actions and hooks.
Your logic seems to depend on the post count. Consider using a unique name, i.e. the name of the submit button on your form. Check for if(isset($_POST['my-unique-submit-button'])). Is anything else in WP submitting via post? You might not know!
I've made simple form for example in file.php:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="get">
<input type="hidden" name="var" value="example"/>
<input type="submit" value="Submit"/>
</form>
Link
</body>
<html>
Ok. Now when i'm going directly to localhost/file.php then click submit and it goes to localhost/file.php?var=example. Then next i click the Link it goes to localhost/file.php?var=example# so its working.
But I'm building component for joomla. I go to my component by alias -> localhost/joomla/index.php/users_hosts_list, Now i'm on default view and default layout, then i put the form, that is the example file.php shown above.
When i submit the form it goes to localhost/joomla/index.php/users_hosts_list?var=example and i meet the problem. When i click the link, instead of go to localhost/joomla/index.php/users_hosts_list?var=example#, this Link delete variable var and it goes to localhost/joomla/index.php/users_hosts_list#.
What should i change to fix that?
I followed your steps but Joomla form is getting me to home page with ?var=example#.
Can you write something like this
<?php
$post = JRequest::get('post');
$link = "index.php?option=com_advsearch&view=advsearch&layout=test"; // your Joomla link
if($post['var'])
$newlink = "index.php?option=com_advsearch&view=advsearch&layout=test&var=".$post['var'];
?>
<form method="post" action="<?php echo $newlink; ?>">
<input type="hidden" name="var" value="example"/>
<input type="submit" value="Submit"/>
</form>
Link
Joomla adds a base tag to the head of the page. I assume that must strip any parameters.
edit: A test tells me that Joomla does strip parameters for that tag. If you view your source, it will probably have the code:
<base href="localhost/joomla/index.php/users_hosts_list">
This will cause the link to be localhost/joomla/index.php/users_hosts_list# rather than just a #
When you replace the "#" with the real url it should work.
I was wondering if my code below is even correct, I've been having numerous errors with this, but am not sure if the problem really exists here. The code is below:
The user will click 'Exit Group'.
<p class="logout"><a id="exit" name="logout" href="#">Exit Group</a></p>
The code that should be execute when 'Exit Group' is clicked is below:
if(isset($_GET['logout'])){
//CODE TO BE EXECUTED
}
However, the code I am trying to execute when the user clicks 'Exit Group' is not even being executed. There is nothing wrong with the code within the braces, as numerous people have checked it. But I was wondering if my problem may lie in the code above? Thank you.
If you click the link, nothing happens because the URL only contains the fragment identifier #. Not even a GET request will be issued.
You use this kind of link normally to jump to an element inside the page (e.g. Top to jump to an element with ID top). This is completely handled in the browser.
And if you only put the fragment identifier there, just nothing will happen. This is very often used if the link should execute some JavaScript and should actually not link to something else.
You are testing the $_POST array at the server side. But this array only contains elements, if you initiate a POST request by a form. That means you need to create a form with a submit button, e.g.:
<form action="" method="POST">
<input type="submit" name="logout" value="Exit Group" />
</form>
Here comes the name attribute into play, which will be the key in the $_POST array. But assigning this on a normal link will have no effect.
You could do it also with the link, but with a GET request this way:
<a id="exit" href="?logout=1">Exit Group</a>
<!-- ^-- parameter must be part of the URL, name has no effect -->
and
if(isset($_GET['logout'])){
//CODE TO BE EXECUTED
}
Note that you have to pass a parameter logout it here.
It seems you have mixed up GET and POST requests. If you have a form, the name s of the form elements will be transmitted as parameters to the server. That means given this form:
<form method="POST">
<input type="text" name="foo" value="" />
<input type="text" name="bar" value="" />
<input type="submit" name="send" value="Send" />
</form>
if the user clicks on the submit button, the $_POST array at the server side will have the keys:
$_POST['foo']
$_POST['bar']
$_POST['send']
This does not work with links though. A click on a link will create a normal GET request, and here, the parameters must be part of the URL, appended after a question mark ? and separated by an ampersand &:
Link
will result in
$_GET['foo']
$_GET['bar']
$_GET['andMore']
You probably should read about the HTTP protocol.
a isnt a form control. it needs to be an input or select if it's within a form.
For manual linking, do href="/page?logout"
You're using a regular hyperlink, no form will get posted. you need a submit button of some kind in a form with method="post" to do that. regular links just result in GET requests and nothing will ever be posted that way.
edit: added simple example:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Form test</title>
</head>
<body>
<?if ($_SERVER['REQUEST_METHOD'] == 'POST'):?>
<pre><? print_r($_POST)?></pre>
<?endif;?>
<? // $_SERVER['REQUEST_URI'] holds the current URL, so we know that ?>
<? // we'll end up back in this file when the form is submitted. ?>
<form method="post" action="<?= $_SERVER['REQUEST_URI']; ?>">
<input type="text" name="textbox"
value="<?= isset($_POST['textbox'])?$_POST['textbox']:'Type something' ?>" />
<input type="submit" name="submitbutton" value="Submit" />
</form>
</body>
</html>
$_POST will only be filled if you use a form with method=post.
Yes. A POST and a GET are two different things ;)
if(isset($_GET['logout']))
This <a id="exit" name="logout" href="#"> should be <a id="exit" href="?logoff=true#">.
Then logoff will be in the $_GET array.