表单提交以运行javascript,然后发布到php脚本 [英] Form submit to run javascript and then post to php script

查看:36
本文介绍了表单提交以运行javascript,然后发布到php脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究php/html/javascript项目.我有一个表单,当用户按下提交"按钮时,该表单应运行javascript函数,然后发布到php页面以处理以表单提交的数据.

I am currently working on a php/html/javascript project. I have a form where when the user presses the submit button, it should run a javascript function and then afterwards post to a php page to process the data that was submitted in the form.

我让表格运行如下所示的javascript方法

I have the form run a javascript method as below

<form class="form" id="addImageForm" name="addImageForm" action="javascript:validateAddImage();" method="post">

该方法验证表单,调用另一个方法,然后使用 document.myForm.submit();

The method validates the form, calls another method and then it submits the form using document.myForm.submit();

我如何将表单提交到另一个php页面来处理数据,包括上载所选文件.

How do I get it to submit the form to another php page to process the data including upload selected files.

感谢您提供的任何帮助.

Thanks for any help you can provide.

推荐答案

将您的操作"参数设置为PHP脚本,并在javascript事件中执行所有javascript处理.

Set yout 'action' parameter to your PHP script, and do any javascript procesing in a javascript event.

<form class="form" id="addImageForm" name="addImageForm" action="processing.php" method="post" onsubmit="return validateAddImage();">

然后在您的js验证中,如果一切正常,则返回"true",否则,则返回"false".返回"true"表示继续提交过程并将数据发送到processing.php

Then in your js validation, return 'true' if everything's fine, or 'false' if not. Returning 'true' means 'continue with the submit process and send over data to processing.php

这篇关于表单提交以运行javascript,然后发布到php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆