Jump to content

Recommended Posts

I have done some research and I've noted that it is not possible to run two actions with one form.  Here's the problem...I really need too.  When users register for my site I would also like a seperate script that I have to run also (it creates an E-Mail account for them on my site).  So my question is what are some alternatives or get-arounds for this problem?

Link to comment
https://forums.phpfreaks.com/topic/75646-solved-form-help/
Share on other sites

If I'm understanding you correctly, after a form is submitted you want another process with the same data started?

You can easily do this.

 

I don't know your exact coding, so I'm running on a whim here but try:

 

if (isset($_POST['submit']))
{include("includes/emailcode.php");} else { finish form code

 

Link to comment
https://forums.phpfreaks.com/topic/75646-solved-form-help/#findComment-382786
Share on other sites

I have done some research and I've noted that it is not possible to run two actions with one form.  Here's the problem...I really need too.  When users register for my site I would also like a seperate script that I have to run also (it creates an E-Mail account for them on my site).  So my question is what are some alternatives or get-arounds for this problem?

 

Yes you are exactly right by the definitiion of a form it has a single action, however the magnitudes and abilities of this said "action" are not defined.  You can have an action go to a action to an action to an action, if so wanted, but that would be pointless when you can do it all in 1 php script.  Now in your case since your mail client propbably has a very specific script to use for creating accounts, odds are you will need to use a secondary page using a header relocate, or force your action script to curl in your email creation script.  I don't know your specifics so I can' tell you which would be easier.

Link to comment
https://forums.phpfreaks.com/topic/75646-solved-form-help/#findComment-382800
Share on other sites

I'm not too keen on PHP but I'm slowly learning as much as I can.  I have had the E-Mail code up and running for a while but someone who has not registered on my site has been taking advantage of this free service I offer and Creating accounts used for SPAM so I have decided to integrate the E-Mail script in with the user registration script to hopefully help aid this problem.  The E-Mail creation script is called cpemail.php and I had a form set up as follows:

<form name="frmEmail" action="cpemail.php" method="post">

<table width="400" border="0">

<tr><td>Desired Username:</td><td><input name="user" size="20" value="<?php echo htmlentities($euser); ?>" /></td></tr>

<tr><td>Desired Password:</td><td><input name="pass" size="20" type="password" /></td></tr>

<tr><td colspan="2" align="center"><input name="submit" type="submit" value="Create Email Account" /></td></tr>

</table>

</form>

 

And this is my Register Form:

<form name="registerform" id="registerform" action="wp-login.php?action=register" CAN I ADD ANOTHER ACTION HERE? method="post">

<p>

<label><?php _e('Username:') ?><br />

<input type="text" name="user_login" id="user_login" class="input" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" size="20" tabindex="10" /></label>

</p>

<p>

<label><?php _e('E-mail:') ?><br />

<input type="text" name="user_email" id="user_email" class="input" value="<?php echo attribute_escape(stripslashes($user_email)); ?>" size="25" tabindex="20" /></label>

</p>

<?php do_action('register_form'); ?>

<p id="reg_passmail"><?php _e('A password will be e-mailed to you.') ?></p>

<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Register »'); ?>" tabindex="100" /></p>

</form>

 

I realize that I would have to change the Variable names in my cpemail.php script to use the same ones on this form and also implement a way to do the password since the regiser form does not ask the user for one, but beyond that I don't know what to do.  Thanks for the help.

Link to comment
https://forums.phpfreaks.com/topic/75646-solved-form-help/#findComment-382824
Share on other sites

My guess would be that once you submit one form, ajax is used for the other? o_o

I'm not sure I understand what you're trying to get at.  Basically what I need is the ability to use the data the user enters on the registration form to also pass that data to my cpemail.php script?

 

Yes you are exactly right by the definitiion of a form it has a single action, however the magnitudes and abilities of this said "action" are not defined.  You can have an action go to a action to an action to an action, if so wanted...

how would I accomplish the action to an action? OR  Is it possible for me to create a file called "runtwo.php" and use that script as my action and have that script send the data to the "wp-login.php?action=register" and "cpemail.php" scripts? If so how would I do it and what would the code look like?  Thanks for all the help so far everyone it's much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/75646-solved-form-help/#findComment-383145
Share on other sites

AJAX is a javascript call to run a php file.

 

Have the javascript call your email file once the form is submitted. Once the email file has been submitted correctly, and creates the email without error, submit the actual form to create the account.

 

That sounds like a great idea the only problem is that I don't know enough about all this to do it myself if it is just a matter of adding a few lines of code could you please show me how and where I would do this?  Thanks.

Link to comment
https://forums.phpfreaks.com/topic/75646-solved-form-help/#findComment-383152
Share on other sites

you don't need ajaxs at all, in fact it would only complicate things.  make the form process to a page you can control, then send the form data forward from that using a header relocation, curl, or any version of sending data that fits your secondary script.  Or put both scripts in one if you can.

Link to comment
https://forums.phpfreaks.com/topic/75646-solved-form-help/#findComment-383157
Share on other sites

below are the two scripts if someone could please help merge them that would be great.  I need the Registration code to run first then if it's successful run the Email code.  I need to cut out the messages from the Email code and change the variable names to coincide with the ones being used with the Register Form but I'm afraid to do it because I know I'll mess it up so if you could show me or tell me how i would appreciate it.

 

Register CODE:

case 'register' :

if ( FALSE == get_option('users_can_register') ) {

wp_redirect('wp-login.php?registration=disabled');

exit();

}

 

if ( $_POST ) {

require_once( ABSPATH . WPINC . '/registration.php');

 

$user_login = sanitize_user( $_POST['user_login'] );

$user_email = apply_filters( 'user_registration_email', $_POST['user_email'] );

 

// Check the username

if ( $user_login == '' )

$errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.');

elseif ( !validate_username( $user_login ) ) {

$errors['user_login'] = __('<strong>ERROR</strong>: This username is invalid.  Please enter a valid username.');

$user_login = '';

} elseif ( username_exists( $user_login ) )

$errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');

 

// Check the e-mail address

if ($user_email == '') {

$errors['user_email'] = __('<strong>ERROR</strong>: Please type your e-mail address.');

} elseif ( !is_email( $user_email ) ) {

$errors['user_email'] = __('<strong>ERROR</strong>: The email address isn&#8217;t correct.');

$user_email = '';

} elseif ( email_exists( $user_email ) )

$errors['user_email'] = __('<strong>ERROR</strong>: This email is already registered, please choose another one.');

 

do_action('register_post');

 

$errors = apply_filters( 'registration_errors', $errors );

 

if ( empty( $errors ) ) {

$user_pass = substr( md5( uniqid( microtime() ) ), 0, 7);

 

$user_id = wp_create_user( $user_login, $user_pass, $user_email );

if ( !$user_id )

$errors['registerfail'] = sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email'));

else {

wp_new_user_notification($user_id, $user_pass);

 

wp_redirect('wp-login.php?checkemail=registered');

I'M ASSUMING THIS IS WHERE I WOULD ENTER THE EMAIL CODE?

exit();

}

}

}

 

login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>');

?>

 

 

E-Mail CODE:

<?php

###############################################################

# You can pass following parameters in calling URL. They will

# override those specified below.

# user - new email user

# pass - password

# domain - email domain

# quota - email quota, Mb

# Example: cpemail.php?user=newuser&pass=password&quota=50

###############################################################

 

// cPanel info

$cpuser = 'MYCPUSERNAME'; // cPanel username

$cppass = 'MYPASS'; // cPanel password

$cpdomain = 'MYDOMAIN.com';

$cpskin = 'rvblue'; 

 

// Default email info for new email accounts

// These will only be used if not passed via URL

$epass = ''; // email password

$edomain = 'MYDOMAIN.com'; // email domain (usually same as cPanel domain above)

$equota = 200; // amount of space in megabytes

 

###############################################################

# END OF SETTINGS

###############################################################

 

function getVar($name, $def = '') {

  if (isset($_REQUEST[$name]))

    return $_REQUEST[$name];

  else

    return $def;

}

 

// check if overrides passed

$euser = getVar('user', '');

$epass = getVar('pass', $epass);

$edomain = getVar('domain', $edomain);

$equota = getVar('quota', $equota);

 

$msg = '';

 

if (!empty($euser)) {

 

  // Create email account

  $f = fopen ("http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/doaddpop.html?email=$euser&domain=$edomain&password=$epass&quota=$equota", "r");

  if (!$f) {

    $msg = 'Cannot create email account. Possible reasons: "fopen" function allowed on your server, PHP is running in SAFE mode';

  }

  else {

    $msg = "<font color='red'><h2>Email account {$euser}@{$edomain} was successfully created!</h2><br />Once You've successfully created an Email Account you can log in by <a href='http://paradiseut.com/?page_id=26'>clicking here</a>.</font>";

 

    // Check result

    while (!feof ($f)) {

      $line = fgets ($f, 1024);

      if (ereg ("already exists", $line, $out)) {

        $msg = "<h2><font color='red'>Email account {$euser}@{$edomain} already exists.</font></h2><br><a href='http://paradiseut.com/?p=28'>TRY ANOTHER USERNAME</a>";

        break;

      }

    }

 

    fclose($f);

  }

 

}

 

?>

<?php echo $msg; ?>

Link to comment
https://forums.phpfreaks.com/topic/75646-solved-form-help/#findComment-383182
Share on other sites

Ok I have done more research and have combined the two codes together but It's not working and I don't know why.  Below is the code. I have highlighted in red the part that's not working: (things in ALL CAPS are the stuff I've taken out so I don't give you private information)

 

case 'register' :

if ( FALSE == get_option('users_can_register') ) {

wp_redirect('wp-login.php?registration=disabled');

exit();

}

 

if ( $_POST ) {

require_once( ABSPATH . WPINC . '/registration.php');

 

$user_login = sanitize_user( $_POST['user_login'] );

$user_email = apply_filters( 'user_registration_email', $_POST['user_email'] );

 

// Check the username

if ( $user_login == '' )

$errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.');

elseif ( !validate_username( $user_login ) ) {

$errors['user_login'] = __('<strong>ERROR</strong>: This username is invalid.  Please enter a valid username.');

$user_login = '';

} elseif ( username_exists( $user_login ) )

$errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');

 

// Check the e-mail address

if ($user_email == '') {

$errors['user_email'] = __('<strong>ERROR</strong>: Please type your e-mail address.');

} elseif ( !is_email( $user_email ) ) {

$errors['user_email'] = __('<strong>ERROR</strong>: The email address isn&#8217;t correct.');

$user_email = '';

} elseif ( email_exists( $user_email ) )

$errors['user_email'] = __('<strong>ERROR</strong>: This email is already registered, please choose another one.');

 

do_action('register_post');

 

$errors = apply_filters( 'registration_errors', $errors );

 

if ( empty( $errors ) ) {

$user_pass = substr( md5( uniqid( microtime() ) ), 0, 7);

 

$user_id = wp_create_user( $user_login, $user_pass, $user_email );

if ( !$user_id )

$errors['registerfail'] = sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email'));

else {

wp_new_user_notification($user_id, $user_pass);

 

wp_redirect('wp-login.php?checkemail=registered');

 

//Below is my attempt to do the Cpanel Email thingy

$f = fopen ("http://CPUSERNAME:CPPASSWORD@MYDOMAIN:2082/frontend/rvblue/mail/doaddpop.html?email=$user_login&domain=MYDOMAIN&password=PASSWORD&quota=200", "r");

fclose($f);

exit();

}

}

}

 

login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>');

?>

 

<form name="registerform" id="registerform" action="wp-login.php?action=register" method="post">

<p>

<label><?php _e('Username:') ?><br />

<input type="text" name="user_login" id="user_login" class="input" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" size="20" tabindex="10" /></label>

</p>

<p>

<label><?php _e('E-mail:') ?><br />

<input type="text" name="user_email" id="user_email" class="input" value="<?php echo attribute_escape(stripslashes($user_email)); ?>" size="25" tabindex="20" /></label>

</p>

<?php do_action('register_form'); ?>

<p id="reg_passmail"><?php _e('A password will be e-mailed to you.') ?></p>

<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Register »'); ?>" tabindex="100" /></p>

</form>

Link to comment
https://forums.phpfreaks.com/topic/75646-solved-form-help/#findComment-383749
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.