1

I wasn't sure how to phrase the title, but here's what I'm trying to do.

I have a form to login to webmail, I don't have access to the webmail - it just posts the form input to the website and the webmail server takes it from there.

Everyone logging in to this page will be using the same email extension (e.g. "@myemail.com"), so I want to save the hassle of typing that every time, instead they can just write "mike" and the form will add "@myemail.com" on it's own.

I could post this form to a middle ground php page that sticks "mike" + "@mymail.com" together and posts this info to the webmail?

Or is there a simpler way to do this without having to create another page?

<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>

I want to take the value entered here...

<input type="email" name="user_name" placeholder="Username" required autofocus>

...and add an extension like "@myemail.com" to it, then post it.

Any idea? Thanks in advance for your help.


I could do something like this?

PAGE 1 - Enter username and password...

<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>

PAGE 2 - PHP takes username and adds "@myemail.com" and sends form...

<?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;
    }
?>

How do I tell PHP to automatically submit the form though?


Here's what I have if I were to use jQuery:

It doesn't currently work though.

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>
11
  • 1
    basically you want to attach "@mymail.com" with input value on form submit? Commented Jan 1, 2016 at 19:28
  • so, why the jquery/php tags? what exactly are you looking for here; solutions for either or, or both? if jQuery, where's your code for it? Commented Jan 1, 2016 at 19:36
  • @Fred-ii- I don't know anything about jQuery, I know a little PHP - just added what I would do for PHP. I want either or, I just don't know what makes more sense Commented Jan 1, 2016 at 19:50
  • 1
    There is something that you need to be aware of, and that is; anyone visiting your page and entering/guessing a name, stands at spamming your site, and sending emails to you that may not have come from the actual users themselves. I would rethink this and possibly use a database instead, where they need to login in order to be able to use their username to send you an email. Or, an .htaccess file with a username/password .htpasswd file. Commented Jan 1, 2016 at 20:00
  • 1
    You're welcome Matthew. Actually, I did place an answer stackoverflow.com/a/32343553/1415724 in this question stackoverflow.com/q/32343310 which will basically do what you're looking to do. The line $bookArray = array('Book1','Book2','Book3'); already contains an array of allowed searches, so you just need to replace those with ones that you may already be using. You will need to do a few modifications though, since I don't know how you're getting your present information from. If you feel that answer helps, feel free to upvote it. Commented Jan 1, 2016 at 20:25

2 Answers 2

1

I think if you want to attach username + "@mymail.com" to useremail field, here is my suggestion: 1# create input user_email (just hide this field)

<input type="hidden" name="user_email" id="user_email" placeholder="User Email">

2# add js below

$('#user_name').on('input', function() {
   username = this.value+'@myemail.com';
   $('#user_email').val(username);
});

here example

Sign up to request clarification or add additional context in comments.

2 Comments

Actually this is a really smart JS work around! I'm going to try implementing it now
This ends up being less code in the end! Works for me.
1

I think this will go like this, hope this will help you. What i am doing in this code is, first I stop the form from being submitted through e.preventDefault(); and then i am taking the value of the required input and assigning it back value by attaching "@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();
    });
});

4 Comments

For JS, this is fine. However, if a user has it disabled, then the OP will need to look for a backup solution.
@Fred-ii- and that's what I'm thinking so far, I'm unsure about jQuery
I'm not sure what's happening but this isn't working?
Just updated the question with what I have including your code that doesn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.