send post request in joomla 2.5 - php

I create a new module that send user information to the data base.
But i have trouble with post request!
<form action="send.php" id="send_c" method="post" >
<p>1</p>
<input type="text" name="pib_u" />
<p>2</p>
<input type="text" name="email_u" />
<p>3</p>
<input type="text" name="phone_u" />
<p>4</p>
<select>
<?php
foreach ($list as $item) {
echo '<option>'.$item->cat_name.'</option>';
}
?>
</select>
<p></p>
<input type="submit" value="Go" />
</form>
when i trying to send information from the form i get the 404 error with send.php
PS: send.php in module folder
please help me to resolve this problem! Thx!

try
<form action="<?php echo JURI::root().'modules/your_modname/send.php';?>" id="send_c" method="post" >
get request your with
$_POST['var_name'] or JRequest::getVar ('var_name');

If you send the request to the same page where the module is loaded leave the action attribute empty.
<form action="" id="send_c" method="post" >
The way you wrote it it looks for {current url}send.php and it doesn't find it.

Related

Check if the form is submited does not work

I want to echo something once a form is submitted. But when I click the submit button, it seems that the page is just refreshing itself and I do not see the word that I have written in the echo section. Here is my code:
<?php
if (isset($_POST['submit'])) {
echo "submitted";
}
?>
<h3>Post your form here</h3>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<label>Insert a title here</label><br>
<input name="title" type="text" placeholder="add a title"><br><br>
<label>Insert the body here</label><br>
<textarea name="body" placeholder="insert the body here "></textarea><br><br>
<input type="submit" value="submit" name="submit"><br>
</form>
I also tried the code by removing the isset function, but that did not work, either.
In form action, you have missed an echo.
action="<?php echo $_SERVER['PHP_SELF']; ?>"
This is working code. I test it on my Machine.
Why you don't use else statement to test it better.
here is the code.
Note (Check your localhost server settings)
<?php
if (isset($_POST['submit'])) {
echo "submitted";
}
else
{
echo "Not working";
}
?>
<h3>Post your form here</h3>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<label>Insert a title here</label><br>
<input name="title" type="text" placeholder="add a title"><br><br>
<label>Insert the body here</label><br>
<textarea name="body" placeholder="insert the body here "></textarea><br>
<br>
<input type="submit" value="submit" name="submit"><br>
</form>
Actually the credit goes to #ashok. He was right that I needed to check localhost server settings.
I am using Phpstorm to write PHP codes. Whenever I click on the Chrome browser to see the results, it takes me to
http://localhost:63342/ name of the file page.
The port 63342 is the default port used by Phpstorm. Since I am using Xampp and it runs on port 8080. I changed port number 63342 to 8080, and it worked.
If you are submitting to the same page, you really dont need to define an action.
Instead of isset, use !empty as such
if(!empty($_POST['submit'])){
echo "success";
}
I must bring to your attention that if the suggestions don't work, you should start with debugging what you are actually receiving from the form POST, using:
<pre>
<?php var_dump($_POST); ?>
</pre>
Turning on error reporting in your php settings is also a good start for debugging.

PHP post throws 404 error after submit

I am trying to make simple login system. But I encountered a problem with post method. Simple register.php file is not working:
<?php
if (isset($_POST['username'])) {
print('text');
}
?>
<html>
<body>
<form method="post">
<input type="text" name="username" required/>
<button type="submit" name="submit">Register</button>
</form>
</body>
</html>
After pressing a button it opens 404 error page.
I searched through dozens of similar questions but still got no solution. I'm working on localhost, PhpStorm 2016.3.2 and PHP7.0 and Ubuntu 16.04
SOLUTION:
It was built-in PhpStorm server's fault. It's not working when post method is used.
I'm using now Lampp and post works fine.
It's work. Are you start Xampp Server or Lampp Severr on your Ubuntu ? I think you forgot to start Server
Try:
<?php
if (isset($_POST['submit'])) {
$username = $_POST['username'];
echo $username;
}
?>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="username" required />
<button type="submit" name="submit">Register</button>
</form>
</body>
</html>
Give the action attribute to the form tag and see.. Here I have added index.php.. U can change it to the same file u r working on.. This might solve the problem.
<form action="index.php" method="post">
<input type="text" name="username" required/>
<button type="submit" name="submit">Register</button>
</form>

need to do a query when button is pressed php

I want to so when a button is pressed on my page it runs a query in the database
View
<form method="POST" action="evcccontroller/query">
<input type="submit" name="nw_update" value="NW_Update"/>
</form>
Controller
public function query()
{
// load the index view
$this->load->view('querycheck');
}
querycheck.php
<?php
if(isset($_POST['nw_update']))
{
echo("You clicked button one!");
//and then execute a sql query here
}
else
{
echo" dhur";
}
An Error Was Encountered
The action you have requested is not allowed.
I think problem with your action attr of form try like
<form method="POST" action="<?php echo base_url(); ?>/evcccontroller/query">
<input type="submit" name="nw_update" value="NW_Update"/>
</form>
add base url to form action
action="<?php echo base_url(); ?>/evcccontroller/query"
Just try
<form method="POST" action="<?php echo site_url('evcccontroller/query')?>">
<input type="submit" name="nw_update" value="NW_Update"/>
</form>
code is looking fine. I think the form action url is wrong. try this:
<form method="POST" action="<?=base_url('index.php/evcccontroller/query')?>">
<input type="submit" name="nw_update" value="NW_Update"/>
</form>

How to to handle form that is called in jquery post request

I have a comment system in which there is a from with hidden comment-id input, the comment system is back-ended by php and i have use jquery post request to bring comments in html pages. every thing is working fine except if i try to handle the form in comments through jquery it does not give any response.
comment system in php
<?php while($row = mysqli_fetch_assoc($query)):?>
<div class="comment-container">
<div class="comment"><?php if(!empty($row['comment'])){echo $row['comment'];}else{echo 'None.';} ?></p></div>
<form name="comment_delete" method="post">
<input name="remove" type="hidden" value="<?php echo $row['id']; ?>" />
<input value="Delete" type="submit" class="comment-delete" />
</form>
</div>
<?php endwhile;?>
jquery to handle comments.
function get_comments(){
$.post('../comment.php', {value1:url1, value2:comment}, function(data)
{
$('#comments').html(data);
});
$('form[name=comment_delete]').submit(function(){
alert('hi')
});
Please see and suggest any possible way to handle this form via jquery.
Thanks.
<form name="comment_delete" method="post" onsubmit="return get_comments()">

Can I have a form on index.php and process it with index.php

Is this possible? I have looked online and cannot seem to find an answer.
yes why not
sure you can post to the same page :)
INDEX.PHP
<?php
if (isset($_POST['txt']))
echo 'Thnx for submitting the form';
else
echo 'Submit the form';
?>
<form name="frm" method="post" action="index.php">
<input type="text" name="txt" id="txt"/>
<input type="submit" />
</form>
yes,
<form name="name" method="post" action="">
then run the php to handle the data in the top of index.php
This not exactly what you asked for but this will make your form submit to its own page without reloading the page so here is the link. It's a youtube video.
http://www.youtube.com/watch?v=FPXL-ZU3rEY&feature=related

Categories