Joomla, a href="#" doesnt work properly - php

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.

Related

HTML PHP FORM two actions?

I have a HTML form where after the user submits the form they see my FormSubmit.php thank you page. Is there a way to make that thank you page still display after submission, but also add a link to another php page that shows you a list of who added their names?
I created a SignupList.php page that reads from a text file. I added the link to the form HTML page at the bottom and to the FormSubmit.php thank you page, but when I add a name ,reach my FormSubmit.php thank you page, then click the link to my SignupList.php page there are no names on it. I noticed on the HTML page in the form action section when I replace FormSubmit.php with SignupList.php I get my desired results a name displays after hitting submit, but my thank you page is gone since I removed the action to it. Any suggestions on how I can do both? Please let me know if I need to explain further.
<!DOCType html>
<html>
<head>
<title>Form</title>
<html lang="en">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
</head>
<body>
<form method="post" action="FormSubmit.php">
<p>Please sign up</p>
<p> First Name:<br>
<input type="text" name="firstname" size="30">
</p>
<p> Last Name:<br>
<input type="text" name= "last name" size="30">
</p>
<p>
<input type="submit" value="Submit Information">
</p>
View Sign Ups
</form>
</body>
</html>
edit: I am not sure why i was down voted, but i figured out the issue. I needed to edit my FormSubmit.php file to write to the document.
In your Formsubmit.php, add:
header('Refresh: 3;url=page.php');
which will refresh the header and redirect the page after 3 seconds.

How to use "HTML form target self"?

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!

form in subpage doesn't work

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?

php after form in wordpress

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!

Html Post Method get blank page after refresh

I am testing Html form using post method and got this odd result:
I have two html pages on server apache (already installed php): post.html and target.html, and the code for these page are followings:
post.html (don't worry about the html standard)
<div style="text-align: center">
<form method="POST" action="target.html">
<input type="text" name="testname" value="sometext" />
<input type="submit" value="submit" />
</form>
</div>
and target.html
<html>
<head>
</head>
<body>
<h1>Target page</h1>
</body>
</html>
When I entered data to the form on post.html page and hit submit button, I got to the target.html page. When on this page(target.html), I refreshed the page, and what I receive is a blank page. The second time I refreshed, It turned to normal Html page.
I don't know why it returned a blank page the first time I refreshed, I have tried the same approach but with PHP page, and the content of target page (assum name target.php) still remains (not blank like html files above)
So, could you explain me about this problem?
Thank you.
This definitely has something to do with your browser. Same here on a mac using Safari, on some pages after submitting the content, the page seems to freeze, I refresh it, and then it works again.
Definitely not a code problem, as far as I'm concerned.
It's because you cannot pass an input from html to html file. Your target.html should be a php file (target.php).
and try to put this code on your target.php
<?php
var_dump($_POST); //this will show the inputted text and also show the data type and will stop the code execution here. other codes below will not be executed.
echo $_POST['testname'];
?>
Additionally, change target.html to target.php in your form action
First I will start out by correcting your post.html
<div style="text-align: center;"> <!-- added a ; after center -->
<form method="POST" action="target.html">
<input type="text" name="testname" value="sometext" />
<input type="submit" value="submit" />
</form>
</div>
that may not matter but you should end all your styles with ;
To continue, everything looks fine. maybe something weird happened between refreshes.
save your form page in php than add the php script in the same page, here try this. remember save in .php.
<?php $testname = $_Post['testname'];
echo $testname ?>
<div style="text-align: center">
<form method="POST" action="">
<input type="text" name="testname" value="sometext" />
<input type="submit" value="submit" />
</form>
</div>

Categories