set curect address to <form action="> - wordpress

i create simple plugin wordpress , one validationform.php and rflinsertdb.php
when user click on submit form , i want got rflinsertdb.php the page validation and insert information to db , but wordpress give me Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
this 2 php page in one folder that name in public ,i see to many codes in internet but not help, how can i do that ?
thx alot
i try this codes for action form
<form method="post" action="<?php bloginfo('template_url'); ?>/rflInsertdb.php">
<p id="errorMessage"></p>
<p>name: <input type="text" class="register" name="name" id="name"></p>
<p>family: <input type="text" class="registerForm" id="family" name="family"></p>
<p>numbers :<input type="number" class="registerForm" id="numbers" name="numbers" min="1" max="200" value="1"></p>
<p>tell: <input type="text" class="registerForm" id="tell" name="tell"></p>
<p><input type="submit" value="ثبت" class="registerForm" id="submit" name="submit"></p>
</form>

This happens to you, because you are using template directory for: /rflInsertdb.php
Try to use
<form method="post" action="<?php echo plugin_dir_url( __FILE__ ); ?>/rflInsertdb.php">
If your file is under the public (what is under the plugin dir), then maybe:
<form method="post" action="<?php echo plugin_dir_url( __FILE__ ); ?>/public/rflInsertdb.php">
See here: https://codex.wordpress.org/Function_Reference/plugin_dir_url

Related

Wordpress translate search query and link to external url

I am trying to modify WordPress search form, so that after user enters the word in the search bar, that word would be translated and accordingly redirected into external link (for example google). I managed to do translation, redirection, but struggle to get search query in first place.
My code:
<form id="myform" name="myform" role="search" method="get" class="search-form" action="" target="_blank" >
<input type="text" id="SearchText" value="" name="SearchText" placeholder="<?php echo esc_attr($search_text) ;?>" >
<button onclick="go()" type="submit" id="searchsubmit" class="btnsearch"></button>
</form>
Then code for translation needs input for search query $XXXXXXXXXXXXX:
$url = 'https://www.googleapis.com/language/translate/v2?key=' . $apiKey . '&q=' . rawurlencode($XXXXXXXXXXXXX) . '&source=xx&target=en';
$str = $responseDecoded['data']['translations'][0]['translatedText'];
Then I have script that would take translated search query $str:
<script type="text/javascript">
function go() {
document.myform.action = "https://www.google.com/";
document.myform.SearchText.value = "<?php echo $str ?>";
...............
}
</script>
Everything works if I put any word instead $XXXXXXXXXXXXX, but the question what here needs to be entered so that it would take original search entry.
Thank you in advance for any help.
Do you need to receive a request passed in a get parameter? You can use jquery $.get https://api.jquery.com/jquery.get/

wpdp update is not working when a form is posted. But can open directly

I am trying to update a custom table row.
Here is my form's code (page-vehicles.php)
<form action="<?php echo home_url( "update" ); ?>" method="post">
<input type="number" name="id">
<input type="number" name="number">
<input type="submit" value="submit">
</form>
When I submit the form to (page-update.php) it shows a 404 error. But if I open the page (page-update.php) directly it shows the page (without 404 error).
What am I doing wrong here? :(
You said the custom page where the update needs to happen is page-update.php but you are posting the form to form.action = "http://novits.com/5050/vedit"; Change the action to the proper link.

access non wordpress php files in underscores theme

I'm trying to create a user sign up form in WordPress theme. I searched allot and found a solution which was using a non WordPress php file to insert into database. I've created a file "user-register.PHP" to register users from static page. but some how I cannot access that file getting "Page not found error". I'm using WordPress underscores theme.
sign up form Code:
<form id="user_form" name="user_form" method="POST" action="../user-register.php">
<input type="text" placeholder="Your Name" id="user_name" name="user_name">
<input type="email" placeholder="Your Email" id="user_email" name="user_email">
<input type="password" placeholder="Your Password" id="You Password">
<button name="sign-up" id="sign-up">Sing Up</button>
</form>
user-register.php
$user_name=$_POST['user_name'];
$user_email=$_POST['user-email'];
$user_pass=$_POST['user-pass'];
$con=mysqli_connect('localhost', 'kaizen_it', '', wp_site_user);
if($con){
$query='insert into wp_site_user(name,email,password)values(,$user_name,$user_email,$user_pass)';
mysqli_query($con, $query);
mysqli_close($con);
header("Location: http://localhost/wordpress/registered.php");
}
Any help would be appreciated!
Since you're not creating a custom page template for this, your path should be the absolute path to your login file. Assuming this file is in the root of your theme:
<form id="user_form" name="user_form" method="POST" action="<?php echo get_template_directory_uri() . '/user-register.php'; ?>">
Which will render as:
<form id="user_form" name="user_form" method="POST" action="http://example.com/wp-content/themes/sometheme/user-register.php'; ?>">
This path will need to change if your login file isn't in the root of your parent theme.

Simple Wordpress form submit throws 404 when inputting numeric in input field

I noticed a strange bug when testing out one of our Wordpress apps.
I have a form with an input field and if I type a number such as "3" anywhere in the input text Wordpress will throw a 404:
<input name="author" type="text" />
If I change the name attribute from author to anything else, it works fine:
<input name="bob" type="text" />
I'm not a Wordpress guru or even a PHP dev so I apologize if this is trivial. I've stripped out everything possible from this PHP page. Is there some Wordpress magic going on here where "author" is some sort of reserved word? Here's the entire PHP file (the header is a simple nav-bar and the footer just calls wp_footer()....):
<?php
/**
* Template Name: MyTemplate
*/
get_header();
if(isset($_POST['submitted'])):
echo "<H4>Submitted!</H4>";
else:
?>
<form id="my-form" action="<?php the_permalink(); ?>" method="post">
<input name="author" type="text" /><br/><br/>
<input type="hidden" name="submitted" id="submitted" value="true" />
<input type="submit" value="Submit"/>
</form>
<?php
endif;
get_footer();
OK wow.. So it looks like there are reserved words in form posts:
http://codex.wordpress.org/Function_Reference/register_taxonomy#Reserved_Terms
Sorry for such a novice question.

wordpress custom contact form html + php inside page

hi everybody i have my contact form ready in html and php (2 different files one html and one php file) and i want to use it in a worpress page.
the user fills the form, selects support department answers the captcha and presses submit button. the form sends all the form data through email to the administrator, a thank you email to the user and redirects to a thank you page.
the html form is
<html>
<body>
<head>
<script src="http://www.google.com/recaptcha/api.js" async defer> </script>
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
</head>
<i>Use the form to get in touch with us.</i>
<form action="form.php" method="POST">
<strong>Name:*</strong>
<input style="width:300px;" name="username" type="text" required />
<strong>E-mail Adress:*</strong>
<input style="width:300px;" name="useremail" type="text" required />
<strong>Subject:*</strong>
<input style="width:300px;" name="usersubject" type="text" required />
<strong>Message:*</strong>
<textarea style="width:300px;" cols="40" name="usermessage" rows="5" required></textarea>
<strong>Select Support Department </strong>
<select name="support">
<option style="width:200px;" value="" >Choose Service</option>
<option style="width:200px;" value="support#xxxxxxxx.com" required>Technical support</option>
<option style="width:200px;" value="sales#xxxxxxxxxx.com" required>Sales</option>
<option style="width:200px;" value="info#xxxxxxxxxxx.com" required>Press</option>
<option style="width:200px;" value="info#xxxxxxxxxxx.com" required>Other</option>
</select>
//recaptcha
<div class="g-recaptcha" data- sitekey="------my site key---------"></div>
<input type="submit" value="send" name="submit"/>
//it redirects when you hit submit
<?php
if ( isset( $_POST['submit'] ) ){
header("Location:http://xxxxxxxxx.com/thank-you-messasge/");
}
?>
</form>
</html>
</body>
my form.php is
<?
//set up the message for administrator
$msg="Name:".$_POST["username"]."\n";
$msg .="E-mail:".$_POST["useremail"]."\n";
$msg .="Subject:".$_POST["usersubject"]."\n";
$msg .="Usermessage:".$_POST["usermessage"]."\n";
//set up message for customer
$msg_customer="We received your request and we will answer you within 24 hours.";
$msg_customer.="\n"."xxxxxxxxxxxxxx";
//set up the email for the administrator
$recipient=$_POST["support"];
$subject= "Support Contact Form ";
$mailheaders="From: xxxxxxxx sales#xxxxxxxxx.com \n";
//set up the email for the customer
$recipient_customer=$_POST["useremail"];
$subject_customer= "Support Contact Form ";
$mailheaders_customer="From: xxxxxxxxxx sales#xxxxxxxxxxxxxxx.com \n";
//send the emails
mail($recipient,$subject,$msg, $mailheaders);
mail($recipient_customer,$subject_customer,$msg_customer, $mailheaders_customer);
?>
i want this form to appear in one page and be able to run the php code when the submit button is pressed.
i cannot run the form.php file even if i save it on the root directory.
it seems i am loosing something
thank you very much
To troubleshoot your form, press F12 in your browser to access the developer tools menu, and take a look at what happens on the Network panel when you submit the form. This should give you some clues about what is failing.
Also, you should not be using unfiltered $_POST variables directly, e.g.:
$name = sprintf("Name:%s\n", filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING) );
i found out the way:
i copy/pasted the html form inside the page code view and i linked absolutely to my php file
<form action="http://example.com/php_file_directory/form.php" method="POST">

Resources