[英]Modify form input value on submit
我不确定标题的措辞如何,但这是我想做的。
我有一个登录到Webmail的表单,我没有访问该Webmail的权限-它只是将表单输入发布到网站上,然后Webmail服务器从那里获取它。
每个登录此页面的人都将使用相同的电子邮件扩展名(例如“ @ myemail.com”),因此,我想节省每次键入该文件的麻烦,相反,他们可以只写“ mike”,并且表单将添加“ @ myemail.com”。
我可以将此表单发布到一个中间层的php页面,该页面将“ mike” +“ @ mymail.com”粘贴在一起,然后将此信息发布到Webmail吗?
还是有一种更简单的方法而不必创建另一个页面呢?
<form name="loginForm" action="http://webmail.emailsrvr.com/login.php" method="POST" target="_blank">
<input type="hidden" name="js_autodetect_results" value="SMPREF_JS_OFF">
<input type="hidden" name="just_logged_in" value="1">
<input type="hidden" name="type" value="v3">
<input type="hidden" name="useSSL" id="useSSL" value="">
<input type="email" name="user_name" placeholder="Username" required autofocus>
<input type="password" name="password" placeholder="Password" required>
<label for="remember"><input type="checkbox" name="remember">Remember my info</label>
<button type="submit">Sign In</button>
</form>
我想取在这里输入的值...
<input type="email" name="user_name" placeholder="Username" required autofocus>
...并在其中添加扩展名,例如“ @ myemail.com”,然后发布。
任何想法? 在此先感谢您的帮助。
我可以做这样的事情吗?
第1页-输入用户名和密码...
<input type="text" name="send_email" placeholder="Username" required autofocus>
<input type="password" name="send_password" placeholder="Password" required>
<label for="remember"><input type="checkbox" name="remember">Remember my info</label>
<button type="submit">Sign In</button>
</form>
第2页-PHP使用用户名并添加“ @ myemail.com”并发送表格...
<?php
$form_email = $form_password = "";
if (!empty($_POST['send_email']) && !empty($_POST['send_password'])) {
$form_email = $test($_POST['send_email']) . '@fountaincreations.ca';
$form_password = $test($_POST['send_password']);
echo '<form name="loginForm" action="http://webmail.emailsrvr.com/login.php" method="POST" target="_blank">';
echo '<input type="hidden" name="js_autodetect_results" value="SMPREF_JS_OFF">';
echo '<input type="hidden" name="just_logged_in" value="1">';
echo '<input type="hidden" name="type" value="v3">';
echo '<input type="hidden" name="useSSL" id="useSSL" value="">';
echo '<input type="hidden" name="user_name" value="' . $form_email . '">';
echo '<input type="hidden" name="form_password" value="' . $form_password . '">';
echo '</form>';
} else {
echo '<p style="text-align:center;padding:40px 20px;">Please go back and try again.</p>';
}
function test($data) {
$data = strtolower(data);
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
如何告诉PHP自动提交表单?
如果我使用jQuery,这就是我所拥有的:
不过目前无法使用。
HTML:
<div class="box top">
<form name="loginForm" action="http://webmail.emailsrvr.com/login.php" method="POST" target="_blank">
<input type="hidden" name="js_autodetect_results" value="SMPREF_JS_OFF">
<input type="hidden" name="just_logged_in" value="1">
<input type="hidden" name="type" value="v3">
<input type="hidden" name="useSSL" id="useSSL" value="">
<div class="inner">
<div class="inner-row"><input type="text" name="user_name" placeholder="First Name" required autofocus></div>
<div class="inner-row"><input type="password" name="password" placeholder="Password" required></div>
<div class="inner-row">
<div class="inner-col col-2-4"><label for="remember"><input type="checkbox" name="remember">Remember my info</label></div>
<div class="inner-col col-2-4"><button type="submit">Sign In</button></div>
</div>
</div>
</form>
</div>
<div class="box bottom">
<div class="inner">
<div class="inner-row"><p>Already signed in? <a href="http://webmail.emailsrvr.com/a/webmail.php" target="_blank"><b>Go to your inbox.</b></a></p>
</div>
</div>
JS:
<script type="text/javascript">
$(document).ready(function(){
$("button[type='submit']").on('click', function(e){
e.preventDefault();
var userEmail = $.trim($("input[name='user_name']").val());
$("input[name='user_name']").val(userEmail+"@fountaincreations.ca");
$("form[name='loginForm']").submit();
});
});
</script>
我想这会像这样,希望对您有帮助。 我在这段代码中所做的是,首先我停止通过e.preventDefault();
提交表单e.preventDefault();
然后我通过附加“ @ mymail.com”来获取所需输入的值并分配回值。
$(document).ready(function(){
$("button[type='submit']").on('click', function(e){
e.preventDefault();
var userEmail = $.trim($("input[type='email']").val());
$("input[type='email']").val(userEmail+"@mymail.com");
$("form[name='loginForm']").submit();
});
});
我认为,如果您要将用户名+“ @ mymail.com”附加到useremail字段,这是我的建议:1#创建输入user_email(只需隐藏此字段)
<input type="hidden" name="user_email" id="user_email" placeholder="User Email">
2#在下面添加js
$('#user_name').on('input', function() {
username = this.value+'@myemail.com';
$('#user_email').val(username);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.