wordpress plugin link to php file - php

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">

Related

Where do I place the PHP file in Wordpress that I want to run on a form submission

I have a form on a WordPress page as follows:
<form id="submissions-form" action="submissions-upload.php"
enctype="multipart/form-data" method="post" name="submissions_upload">
...
</form>
Where should I place my submissions-upload.php file?
I specifically want to run the submissions-upload.php code, not code on my page.
I don't know where wordpress pages are meant to be stored. All I know is that it doesn't work on the root page.
You can use same page ... Like as
<?php
if($_POST){
print_r($_POST);
}
?>
<form id="submissions-form" action="#"
enctype="multipart/form-data" method="post" name="submissions_upload">
...
</form>

How to post a form to self?

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 */}

why <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>"> will cause the XSS

Today I read the w3school to learn php by myself.
It says <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">maybe cause the XSS when someone enters the some URL,such as "http://www.example.com/test_form.php/%22%3E%3Cscript%3Ealert('hacked')%3C/script%3E".
I don't konw why enter this URL will cause the $_SERVER["PHP_SELF"] return different result.Can someone tell the reason to me.Thanks.

Simple php contact form, but on submit want to keep the validate.check(this) and add window.open

I have a simple php contact form whereby i would like any error messages or thank you pages to open in a new window, whilst also keeping the validate.check bit.
Current code looks like:
<form name="contactform" method="post" action="contactformpost.php" onsubmit="return validate.check(this)">
Would it be right in coding it like this:
<form name="contactform" method="post" action="contactformpost.php" onsubmit="return validate.check(this); window.open('','my_form_target', 'width=300,height=200', true)">

PHP Form without additional File

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.

Categories