I work with symfony 2.0 and I have a view (test.html.php) that contains a
form:
<form action="" method="post" rel="">
<input type="hidden" name="action" value="test" />
<input name="myinput" type="text" value=""/>
<input type="submit" class="button" value="Go" />
</form>
This form sends the value of myinput to testAction in ActionController (and it works) but I wanna add a validation function with jQuery and/or AJAX to validate the myinput value before sending it to the controller and I don't know where to integrate it exactly
Thank you in advance
You can use HTML5 validations for client side validation.
Related
<formn action="" method="POST">
<label>Name</label>
<input type="name">
<button name="submit">Submit</button>
</form>
I have also tried
<form ngNoForm action="table.php" method="POST">
<label>Name</label>
<input type="name">
<button name="submit">Submit</button>
</form>
but I keep on getting this error
"Cannot POST /table.php"
I have double checked and even triple checked the spelling and its right.
It's likely the path for the file is wrong. In your first example you used backend/table.php, give that a shot (example below).
<form ngNoForm action="backend/table.php" method="POST">
<label>Name</label>
<input type="text" name="name">
<input type="submit" value="Submit" />
</form>
But more importantly, if you want to submit a POST request through a form you have to set the URL you want to POST to as the form's action. Putting a link around a button will never submit the form.
<button name="submit">Submit</button>
This would just redirect you to backend/table.php, no POST request was sent so no data would be processed.
My problem is this :
I got 2 forms that are supposed to send different informations to the same page (via POST method). Each form has a submit button. However when I press any of the button, information from both forms are sent to the page.
Is it normal or is there something that I do wrong ?
I can already tell you without looking at your HTML.
You have to properly close the first form before opening the second. Easy mistake to make.
<form method="post" action="page.php">
<input type="text" name="something" />
<input type="submit" value="Submit" />
</form>
<form method="post" action="page.php">
<input type="text" name="somethingelse" />
<input type="submit" value="Submit" />
</form>
I have very simple form (the file is called message.php):
<?php
print_r($_POST);
?>
<form method="post" target="_top" action="<?php echo CANVAS_URL;?>message.php">
<input type="text" name="your_name" />
<input type="hidden" name="signed_request" value="<?php echo $_REQUEST['signed_request'];?>" />
<input type="submit" name="send" />
</form>
I found one solution of this issue - put into the form hidden input with the signed_request - I did it but unfortunately I am still facing with this problem -- I cannot retrieve sent POST data.
If I change the method to method="get", everything is working well, but I would need to data from POST.
Could anyone help me, how to solve this problem? Thanks!
Try this. I don't believe you need to use target in FB canvas aps anymore. Also a form ID would be good.
<form method="POST" id="my_form" action="message.php">
<input type="text" name="your_name" />
<input type="hidden" value="<?php print $_POST["signed_request"] ?>" name="signed_request" />
<input type="submit" name="submit" />
</form>
POSTing to Canvas URLs (as in http://apps.facebook.com/namespace) is simply not supported.
But why post to the top window instead of simply staying within the iframe? It's way better as it doesn't require the entire page to be reloaded, only the iframe.
Did this example of type="submit" have javascript behind the scenes?
<html>
<head>
</head>
<body>
<form action="process.php" method="post">
Username: <input type="text" name="username" value=""/><br />
Password: <input type="text" name="username" value=""/><br />
<input type="submit" value="Submit"/>
</form>
</body>
Because the other way to submit your data inputs into server is like this.
<html>
<head>
<script>
function submit(form){
form.submit();
}
</script>
</head>
<body>
<form action="process.php" method="post">
Username: <input type="text" name="username" value=""/><br />
Password: <input type="text" name="username" value=""/><br />
<input type="button" value="Submit" onclick="submit(this.form);" />
</form>
</body>
If so then we dont need javascript to send data into server?? am i right?
If you use <input type='submit'>, no need to add JavaScript. In this case browser will submit the form even if JavaScript is disabled.
If you want to submit the form using JavaScript, then you can use the above method you wrote. In this case, you can use any other control and on click you can submit.
So, clearly, <input type='submit'> doesn't use any JavaScript.
Your given example does not use javascript to submit data to the server. By default, the submit button sends all info from your form to the server. You may however need javascript to handle things like error checking and posting without requiring a single page reload.
The example mentioned in above code snippet does not use javascript for form submission.
Input button with type="submit" when clicked has a default behaviour for submission of form.
So form will be submitted using submit button regardless of Javascript being enabled in browser. Also we can submit form using javascript through the following code snippet
document.formName.submit();
I built a custom Zend_Form "myForm" and I passed it to my view with:
$this->view->form=new myForm();
Problem: form is not submitting (page doesn't reload/refresh).I thought something was wrong with the "form" tags,but I copyied the bottom code in another page (that is not a Zend environment) and is working.This is the source code:
<form enctype="multipart/form-data" method="post" action="">
<input type="text" name="title" id="title" value="" class="">
<textarea name="text" id="text" class=""></textarea>
<input type="text" name="allegati" id="allegati" value="" class="">
<input type="hidden" name="MAX_FILE_SIZE" value="2097152" id="MAX_FILE_SIZE">
<input type="file" name="file" id="file" class="media[]"></span>
<input type="submit" name="submit" id="submit" value="submit" class="">
</form>
SOLVED: As some of you guys suggested javascript is giving problems:
I had a js script overriding with:
$('form').submit();
Thanks
Luca
Form submitting issues are 99% related to javascript conflicts with the 'form' element or with a wrong defined 'form' tag.
Always check those above when encountering problems.
P.s. for the remaining 1% feel free to ask at Stack!
Best regards
Just a suggestion - try to rename your submit button to something but not "submit" (i.e name="mysubmitbutton").
I think the problem could be with expandos: http://ejohn.org/blog/deadly-expandos/. By default, a form element has a submit function. But, if you call any field inside your form with the name "submit" (like you do in your example), the form.submit will point to your input element and you'll not be able to submit your form.