I'm having a form with only one submit button. I don't know why, but when I use this code and I click on the submit button, nothing is happening. If I use a ! before the isset you'll see the echo in the page. I don't know what's wrong with it.
<form>
<input type="submit" value="Toevoegen" name="addImg" />
</form>
<?
if (isset($_POST['addImg'])) {echo "haaallloooo";}
?>
Maybe, form by default is sending variables by get, try using method="POST" attribute in form tag
You have to set the method to POST.
Otherwise you can use:
$_REQUEST['addImg']
The variable $_REQUEST can access both GET and POST parameters.
Form needs an action and a method.
<form action="" method="post">
<input type="submit" value="Toevoegen" name="addImg" />
</form>
<?
if (isset($_POST['addImg'])) {echo "haaallloooo";}
?>
Regarding "isset", if $_POST['addImg'] is not set, it doesn't echo "haaallloooo".
isset — Determine if a variable is set and is not NULL
Check http://hk.php.net/manual/en/function.isset.php
Related
have you guys any ideas why the url is set in the $_GET, when i submit a form with post method?
I have a form like this:
<form action="/test/show/" method="post" enctype="multipart/form-data">
<input name="product" value="testing">
<input type="file" name="image">
<input type="submit" value="go" name="submit">
</form>
In my chrome i can see it will be send as post, but if i do this:
if (count($_GET) > 0) {
var_dump($_GET);
}
I get this result:
array(1) { ["url"]=> string(10) "test/show/" }
and i have no idea why?
Can you help me?
Under normal circumstances, with that URL, it wouldn't be. Presumably you are using mod_rewrite or similar to map /test/show onto something like /index.php?url="%2Ftest%2Fshow.
This is because PHP picked poor names for the $_GET superglobals.
An HTML form with method="GET" will put the data from its form controls in the query string, but that isn't the only way to request a URL with a query string.
$_GET contains data from the query string irrespective of the request method.
new to CI and for some reason the form submits to a wrong url.
the result is : http://localhost/ci/index.php/subjects/localhost/ci/index.php/do_upload
and can't understand why.
This is the html code :
echo form_open_multipart('do_upload');
?>
<input type="file" name="files[]" id="fileupload"
style="position:absolute; top:-200px" multiple />
<input type="submit" id="uploadFile" style="position:absolute; top:-200px" />
<?php echo form_close(); ?>
Any help?
I've also tried to write subjects/do_upload on form open, same thing.
Check your config for base_url and site_url
Leave them '' blank.
i'm working on a symfony project and i developed a form to upload a file and save its info to a table in my model. And didn't use the sfForm class to implement my form.
Here you have my form
<form name="new_file" action="<?php echo url_for('home/uploadFile');?>" method="post">
<input type="file" id="file">
<input value="<?php echo $codigo_maestro?>" id="master_id">
<input value="<?php echo $codigo_entidad?>" id="entity_id">
<input type="submit" value="Upload">
</form>
So now i'm trying to access the fields of the sumbited form in my action function and don't know how :(
$request->getParameter('file');
$request->getParameter('master_id');
$request->getParameter('entity_id');
this code didn't work.
So please help me solve this! How can i access the fields of my form from the action??
You need to add a name to your form fields, that's the name you can access them via $request->getParameter().
finally i did this way, maybe not most elegant, but working
in action.class.php
$file= $_FILES['file'];
$filesize = $archivo['size'];
$filetype = $archivo['type'];
$filename = str_replace(' ','-',$file['name']);
I think that if you assign a name attribute to an input type='text' that name becomes the post variable. How can you assign a post variable to am html textarea. i cant seem to get it working. Im just trying to take a user's imputed text from the textarea and put it into a mysql database. thanks
form:
<form action='index.php' method='POST'>
<textarea name='form'></textarea>
</form>
<?php $input=$_POST['form']; ?>
Zend newbie here ... And just to make it better, my mission is to build on top of someone else's pre-existing Zend site.
(BTW: zf show version --> Zend Framework Version: 1.11.1 -- I seem to have Zend_Form).
Here's the curious bit. All the forms are built in HTML within views. They seem to work, although I can't figure out how -- especially given what I am seeing.
I followed the convention and created a view for a test form and wrote the form:
<form action="<?php echo $this->url(array('controller'=>'ControllerName','action'=>'submit'));?>" method="post" style="margin-left:20px">
<p class="bold setmgr">Your email here:</p>
<div class="field">
<input class="text" type="text name="custEmail"/>
</div>
<div class="field">
<input class="button" value="Submit and be free!" type="submit"/>
</div>
</form>
The submitAction member in the controller is firing correctly. No problem.
But ALL the places I could look for the POST data appear to be empty!
echo "obj custEmail = [" . $this->_request->getPost('custEmail') . "]\n";
echo "GET custEmail = [" . $_GET['custEmail'] . "]\n";
echo "POST custEmail = [" . $_POST['custEmail'] . "]\n";
if ($this->_request->isPost()) {
$data = $this->_request->getPost();
Zend_Debug::dump($data);
}
They all produce nothing.
I'd be much obliged for a solution or even a clue about what is going wrong.
Thanks for reading.
Your form is not in the correct format.As it's PHP you can use form like this or you can even generate a ZEND_FORM(which is profound way to do it).It's always a good practise to work around with ZEND_FORM.If you still want to use this and the go by your way,here is th snippet I modified for you.
I am modifying the Code for you.Your View should have this form in it;
<form action="" method="post" style="margin-left:20px">
<p class="bold setmgr">Your email here:</p>
<div class="field">
<input class="text" type="text" name="custEmail"/>
</div>
<div class="field">
<input class="button" value="Submit and be free!" type="submit" name="submit"/>
</div>
</form>
<?php
echo $this->custEmail;
?>
Now write the following one on your ACTIOn,i.e. submitAction;
public function submitAction()
{
if ($this->getRequest()->isPost())
{
$custEmail = $this->getRequest()->getPost('custEmail');
echo $custEmail;
$this->view->custEmail = $custEmail;
}
}
Now check if it works for you or not.
Create a form using Zend_Form. When ZF already has a way to create forms, you should use that. Your method is like a hack and is not a recommended way to do things.
Check here on how to create a Zend_Form
http://framework.zend.com/manual/en/zend.form.html