I have a page which is accessible via a url - something like this http://websitename/index.php?q=pagename. On this page, I have a form that I would like to submit to the same page so that I could do some post processing. I have tried the following things but couldn't get it to work -
<form name="formname" action="pagename.php" method="post">
<form name="formname" action="" method="post">
<form name="formname" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
In other words, I would like to submit the form to pagename.php file (where the form resides). The page (pagename.php) is not directly accessible. How do I get this done? I will greatly appreciate any help on this one. Thanks.
Try this:
In HTML5 you can just do <form> and its set to self.
<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="post">
OR
<form name="formname" id="mainForm" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['REQUEST_URI'];?>">
OR
<form method="POST" action="<?=($_SERVER['PHP_SELF'])?>">
The point is your $_SERVER variable contains all the information you would require to generate that specific page's URL. If you have decided not to go with the HTML5 way, then one of these options should work. Otherwise you're missing something else not mentioned in your question.
i think this will solve your problem
<form name="formname" action="#" method="post">
Try
<form method="post">/*your stuff here*/</form>
and you should add a submit button with attribute "name=submit" so the form could be submitted also track if its have been posted with php then do your actions like below
if(isset($_POST["submit"])){ /* your code */}
Related
Seems like a simple question, I'm building a simple contact form plugin for wordpress. I have the following line in a file called contact.php - this file is what creates the html elements for the form:
<form method="post" action="process.php" name="contactform" id="contactform">
However, process.php is not found (as it links to here). How do I link to that file using a php command, something like this perhaps:
<form method="post" action="<?php plugins_url(); ?>process.php"
name="contactform" id="contactform">
The above doesn't work, but it's the kind of solution I'm looking for.
Please use the below code. This will help you.
<form method="post" action="<?php plugins_url( 'process.php', __FILE__ ); ?>" name="contactform" id="contactform">
I am working with PHP forms.
The opening form tag looks like this:
<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="GET">
This generated the following HTML:
<form name="adv_search_form" action="index.php?&rel=common_listing&module=company&sort_option=&search_option=&show_max_row=15" method="GET">
When I submit this form, I land on a URL:
http://localhost/projectcode12may2014/ampanel/index.php?field%5B%5D=broker_name&adv_operation%5B%5D=LIKE&value%5B%5D=&query_type%5B%5D=AND&submit=Submit
But what I want is that
?field%5B%5D=broker_name&adv_operation%5B%5D=LIKE&value%5B%5D=&query_type%5B%5D=AND&submit=Submit
should be appended to the action URL on the landing page. Can anyone suggest any good method for doing this?
Thanks in advance.
If you are using method="get" the parameters in action are overwritten. Only what is in the from will be transmitted.
You need to add hidden fields for all these values. For example:
<input type="hidden" name="module" value="company" />
That is your from data.
You have method="get" in your form tag. This means that the form data is concatinated to the URL. Use method="post" to have send form data as a POST request and keep your URI clean.
So change this line
<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="GET">
to this
<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="post">
Then you can access your form data in PHP with the global $_POST var which holds an array with the submitted data.
This is a normal behavior. Using GET method discard all parameters specified directly in action attribute.
Use POST method instead or move parameters from action attribute of the form to input fields with type="hidden".
I want to post the careers form directly on email using HTML5. To post the form directly on my email id and i used syntax
<form action:"mailto:web#domain.com" method="post" enc type="text/plain">
</form>
but it does not work properly. Please tell me how i links form directly with email id.
Try using
<form action="mailto:web#domain.com" method="post" enctype="text/plain">
instead of
<form action:"mailto:web#domain.com" method="post" enc type="text/plain">
:-)
like below:
<form action="mailto:myforms#mydomain.com" enctype="text/plain" onsubmit="location.href='thanks.html';" >
Refer: http://www.html-form-guide.com/email-form/email-form-mailto.html
Try
<form action="mailto:web#domain.com" method="post" enctype="text/plain">
</form>
You just wrote enctype wrong. Hope this helps :)
I have a form in one of my pages and I want to make it submit to the same page. I am doing this:
<form method="POST" action=".">
But when I submit the form it submits to the root directory of my site instead of to the same page the form is on.
I know that the form is being submitted because I tried temporarily changing the method to GET and when I submitted the form, the URL showed the get variables.
Why is the form not submitting to the current page?
If it's relevant, I'm using PHP with xampp.
Try this:
<form method="POST" action="">
This is what I do
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
I'm a newbie though so if Juampi's answer works too , I'd go with it.
Is it possible to to have a PHP form without having a seperate file,
e.g. Normal Form
<form action="send.php" method="post">
But instead of calling send.php have the code held in send.php in the same file as the form?
Sure, just supply the action attribute with an empty action
<form action="" method="post">
or with a $PHP_SELF call.
<form action="<?php echo $PHP_SELF;?>" method="post">
Both will submit to the current page.