Hello I'm creating two pages in Wordpress: dragdrop-translation.php and translation-detail.php using custom template. In the first one the user select a couple of languages, a dead line and the file (.txt or .pdf) that must be traslate. This datas should be send to traslation-detail but I've have a problem with the POST action. The template are placed in wp-content/themes/hello-theme-child-master/dragdrop-translation.php and wp-content/themes/hello-theme-child-master/translation-detail.php
The code of the page that contain the form POST is:
<?php
/**
* Template Name: Drag&Drop - Traslation
*
*/
get_header();?>
<div style="margin-top:120px;">
<!--FIRST PART OF FORM-->
<form method="POST" enctype="multipart/form-data" action="/translation-detail/">
<?php function show_languages_list(){
global $wpdb;
$table_name = "wp_languages_price";
$prepared_query = $wpdb->prepare("SELECT * FROM ".$table_name."");
$results = $wpdb->get_results($prepared_query );
echo '<label for="'.'languages'.'">Select language:</label><select name="'.'languages'.'" id="'.'languages'.'">';
echo '<option value="" disabled selected>Select languages</option>';
foreach($results as $languageCouple){
echo '<option>'.$languageCouple->languages_1.' - '.$languageCouple->languages_2.'</option>';
}
echo '</select>';
}
show_languages_list();?>
<label for="start">Deadline:</label>
<input type="date" id="date" name="trip-start"
min="" max="" placeholder="yyyy-mm-dd">
<br>
<label>Insert text file</label>
<input type="file" name="datafile" id="datafile" size="40" required>
<br>
<input type="submit" value="Calcola preventivo" onclick="checkFields()">
</form>
<br>
<div id="errors" style="color: red;">
</div>
</div>
<script>
//Script for check the datas removed
</script>
<?php get_footer();?>
The code of translation-detail.php is empty so I don't post it.
When I submit the datas, the server replies with a 404 on the action folder of the post.. What path i need to place on the action field of the form?
Related
Hey i am trying to retrive data from a basic form .. but when i am using $_POST['field name'] then it gives me nothing .
here is my basic code
form page is:
<?php
/**
Template Name: galaxy
*/
get_header(); ?>
<div id="main-content" class="main-content">
<form action="<?php echo site_url();?>?page_id=8" method="post">
<input type="text" name="name" /> <input type="submit" value="Send" />
</form>
</div><!-- #main-content -->
<?php
get_footer();
when i click submit it redirects to next page but display nothing with this code
<?php
/**
Template Name: get_value_galaxy
*/
$name=$_POST['name'];
echo $name;
print_r($_POST);
?>
Try using a different name for the variable. I know that Wordpress uses "name" as a public query var, and perhaps that's why it's not working. So rather than using name="name", try this:
Form:
<input type="text" name="unique_name" />
Post Page:
$name=$_POST['unique_name'];
echo $name;
See this list for all query vars:
http://codex.wordpress.org/WordPress_Query_Vars#Query_variables
<div class="container">
<form class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<?php echo form_open('login/validate_credentials');?>
<?php $u = 'placeholder="Username"';
$p = 'placeholder="Password"';?>
<?php echo form_input('username','',$u,'class="input-block-level"');?>
<?php echo form_password('password','',$p,'class="input-block-level"');?>
<label class="checkbox">
<input type="checkbox" value="remember-me"> Remember me
</label>
<?php echo form_submit('submit','Sign in','class= "btn btn-primary"');?>
<?php echo anchor('login/signup','Sign up!', 'class= "btn btn-primary"');?>.<br/><br />
<?php echo anchor('login/admin_log','Go to admin login page');?>
<?php echo form_close();?>
</form>
</div>
I have a login form. When I click sign , it's not redirecting me to the form_open page.
you need to create an action for the form, usually a php script on a different page to handle the data:
as an example:
<form action= "../create_comment.php" method="post" name="comments_form" id="comment" enctype="multipart/form-data">
<div>
<label>Name<span>*</span></label>
<input name="name" type="text" value=" ">
</div>
</form>
You have two forms Parent and child(form inside form).
Submitting the form will process parent form. Simply remove the first (parent) <form> tag.
<form class="form-signin">
^^^^^^^^^^^^^^^^^^^^^^^^^^ ------ remove this
...
...
</form>
^^^^^^^ ------ and this
It looks like you might be using CodeIgniter?
You have 2 form tags in your code.
here: <form class="form-signin">...</form>
and here:
<?php echo form_open('login/validate_credentials');?>...<?php echo form_close();?>
Get rid of this one: <form class="form-signin">...</form>
Your second form tag will handle everything for you. The output will look something like this:
<form method="post" accept-charset="utf-8" action="http:/example.com/index.php/login/validate_credentials" />
If you need to add a class or any other property to the form tag, do this:
$attributes = array('class' => 'email', 'id' => 'myform');
echo form_open('email/send', $attributes);
Form helper on CI Docs
I'm trying to create a page with a form using ci.
When i submit the form, the controller says that I have no data that's been submitted.
I can't see where my error lies.
Here's the view:
<?php echo validation_errors(); ?>
<?php echo form_open('widgets/search/'.$hardwaremodel.'/'.$objectid.'/'.$name.'/'.$fd); ?>
<div class="form-group">
<label for="search">Last 4 characters of address:</label>
<input type="text" class="form-control" id="searchstring" placeholder="last 4 characters" size="4">
</div>
<button type="submit" class="btn btn-default">Search</button>
<button type="cancel" class="btn btn-default">Cancel</button>
</form>
Once the page renders, the form tag ends up looking like this:
<form action="http://myserver/myciapp/index.php/widgets/search/205406zl/5461/SW-1/SW1net" method="post" accept-charset="utf-8">
The controller:
public function search()
{
$searchstring = $this->input->post(); // form data
var_dump($searchstring);
exit;
}
The results of the var_dump shows:
bool(false)
Thanks
EDIT 1
I haven't posted the entire HTML page that includes the form... but I display some of the fields passed in the URI as headings on the page - just before I create the form. Hope that clarifies...
Would this impact the POST data? Why is that relevant?
Thanks
A few things I'd suggest doing. First is, if you are going to include other variables in the form_open tag, I would add those variables to your controller, and put them in the form_open tag as URI strings. This will allow the form validation to work if you are going to echo out validation errors.
Also, you should be calling a name on the input->post() to get the specific item, (but you don't need to to get all POST data).
Controller:
public function search($hardwaremodel, $objectid, $name, $fd) {
$searchstring = $this->input->post('search_string'); // form data
var_dump($searchstring);
exit;
}
View:
<?php echo form_open('widgets/search/'.$this->uri->segment(3).'/'.$this->uri->segment(4).'/'.$this->uri->segment(5).'/'.$this->uri->segment(6)); ?>
<div class="form-group">
<label for="search">Last 4 characters of address:</label>
<input type="text" class="form-control" id="search string" name="search_string" placeholder="last 4 characters" size="4">
</div>
Form elements are referenced by name attribute which is missiong on input field searchstring.
Add:
name="searchstring"
on your input field.
in this code you have not used name attribute.You use id.
try this one
<input type="text" name="searchstring" value="xyz">
i have program codeigniter anda i want to insert form to database.
code view:
<form target="paypal" method="post">
<div class="field1">
<div class="field">
<label>Nama</label>
<input placeholder="Nama" name="nama" type="text">
</div>
<div class="field">
<label>No. HP</label>
<input placeholder="No. HP" name="handphone" type="text">
</div>
<div class="field">
<label>Alamat</label>
<input placeholder="alamat" name="alamat" type="text">
</div>
<div class="field">
<label>Jumlah</label>
<div class="selectbox">
<select name="jumlah" id="">
<?php for ($i=1; $i <= 20; $i++): ?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php endfor; ?>
</select>
</div>
</div>
<button type="submit" name="submit" class="ui teal button order-button">Order now</button>
</div>
</form>
code controller
function simpanOrder()
{
$this->load->model("M_order");
$data['nama'] = $_POST['nama'];
$data['handphone'] = $_POST['handphone'];
$data['alamat'] = $_POST['alamat'];
$data['jumlah'] = $_POST['jumlah'];
if($this->input->post('submit')){
$this->M_order->insert($data);
}
}
when i click submit data not insert to database. so can you help me with this code problem? thanks.
Your form doesn't have an action, and therefore may not be going to the function you want it to. (/controller/function)
<form target="paypal" method="post">
Also, instead of using a button to submit the form - try using <input type="submit"...
Using the <button>, in some browsers, you would have "submit" submitted, in others, "Order now".
If the above doesn't work - check your SQL.
As a side note, CodeIgniter has a form helper and a form_validation library which are quite useful if you're already using CodeIgniter. That won't fix your problem but it's just something I felt I would point out.
See:
http://ellislab.com/codeigniter%20/user-guide/libraries/form_validation.html
http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html
Call model from controller. and write below code in model.
$data = array(
'handphone' => $this->input->post('handphone'),
'alamat' => $this->input->post('alamat'),
)
In this array key is database columnname.
$this->db->insert(yourtablname, $data);
$insert_id = $this->db->insert_id();
You need to define action attribute in form tag where you will provide controller name and method name like this
<form action="<?php echo site_url('controllername/simpanOrder')?>" method="post">
After posting you can debug your code like this
$post = $this->input->post();
echo '<pre>';
print_r($post);
Then
if($this->input->post('submit')){
$this->M_order->insert($data);
}
And finally
echo $this->db->last_query();
This will display you the last query run.
I Have a form which when submitted needs to go to the page and then show one of 4 hidden divs depending on the page.
Here is the form
<form>
<input id="place" name="place" type="text">
<input name="datepicker" type="text" id="datepicker">
<input type="submit" name="submit" id="submit" />
</form>
Here is the page
<div id="brighton">
<p>Brighton</p>
</div>
<div id="devon">
<p>Devon</p>
</div>
<div id="search">
<p>search</p>
</div>
<div id="variety">
<p>variety</p>
</div>
So if Brighton is typed into the place input i need the form to submit the page and show the Brighton div and if Devon is typed in to show the Devon div etc and if the 2/12/2012 is typed into the date picker input and Brighton into the place input it goes to the page and shows the variety div.
i also need it so if the 1/12/2012 is typed in to the date picker input the page redirects to the page show.html.
any help would be greatly appreciated
thanks.
This is easy if you know PHP at all. It looks like you need a good, easy start. Then you will be able to achieve this in seconds.
Refer to W3SCHOOLS PHP Tutorial.
To achieve what you have mentioned, first make the following changes in your form:
<form action="submit.php" method="post">
<input id="place" name="place" type="text">
<input name="datepicker" type="text" id="datepicker">
<input type="submit" name="submit" id="submit" />
</form>
Create a new file called submit.php and add the following code:
<?php
$place = $_POST['place'];
$date = $_POST['datepicker'];
if ($date == '1/12/2012') {
header('Location: show.html');
exit;
}
?>
<?php if ($place == 'Brighton''): ?>
<div id="brighton">
<p>Brighton</p>
</div>
<?php elseif ($place == 'Devon'): ?>
<div id="devon">
<p>Devon</p>
</div>
<?php elseif ($place == 'search'): ?>
<div id="search">
<p>search</p>
</div>
<?php elseif ($place == 'Variety'): ?>
<div id="variety">
<p>variety</p>
</div>
<?php endif; ?>
Now the above example is not the complete solution, but it gives you an idea as to how you can use if-then-else construct in PHP to compare values and do as desired.
Post your form to a php page and then check the posted form parameters to determine which div to show.
<?php
if ($_POST["place"] == "Brighton") {
?>
<div id="brighton">
<p>Brighton</p>
</div>
<?php
} else if ($_POST["place"] == "Devon") {
?>
<div id="devon">
<p>Devon</p>
</div>
<?php
}
?>
Do that for each div and parameter combination. Make sure you set the "method" attribute on your form to "post":
<form action="somepage.php" method="post">...</form>
In the resulting HTML you will only see the one that matches the form parameter.