Page 1 of 1

combining 2 input fields to make a 3rd

Posted: Wed Aug 10, 2011 1:27 am
by marjwyatt
I absolutely know this has to have been done before but, for the life of me, I cannot make it work no matter what I try.

Problem statement:
I need to combine the street address and zip inputs into a 3rd custom field for use with a Google Map plugin. The combination can occur either on the submission form or on the back end processing form but, through my many, many rounds of attempts today, I've seen better results on the input submission form than through the backend processing.

Here are some of the things that I've tried with comments on results:

Code: Select all

<td><input type="hidden" id="_mapfield" name="_mapfield" value="'.$_streetaddress.'" '.$_zip.'></td>-->
<td><input type="hidden" id="_mapfield" name="_mapfield" value="'<?php echo $_streetaddress?>'+'<?php echo $_zip?>'"></td> <!-- returned plus sign -->
<td><input type="hidden" id="_mapfield" name="_mapfield" value="'<?php echo $_streetaddress?>.<?php echo $_zip?>'"></td> <!-- returned one dot-->
<td><input type="hidden" id="_mapfield" name="_mapfield" value="<?php echo $_streetaddress?>.<?php echo $_zip?>"></td><!-- returned one dot-->
<td><input type="hidden" id="_mapfield" name="_mapfield" value=".<?php echo $_streetaddress?>.<?php echo $_zip?>."></td> <!-- returned 3 dots -->
<td><input type="hidden" id="_mapfield" name="_mapfield" value="<?php echo $_streetaddress.''.$_zip;?>"></td> <!-- returned nothing -->
<td><input type="hidden" id="_mapfield" name="_mapfield" value="'<?php echo $_streetaddress . $_zip; ?>'"></td> <!-- returned one double quote -->
<td><input type="hidden" id="_mapfield" name="_mapfield" value= echo $_streetaddress . $_zip></td> <!-- returned the word echo -->
<td><input type="hidden" id="_mapfield" name="_mapfield" value= <?php echo $_streetaddress." ".$_zip; ?>></td> <!-- returned nothing-->
<td><input type="hidden" id="_mapfield" name="_mapfield" value= '<?php echo $_streetaddress." ".$_zip; ?>'></td> <!-- returned nothing -->
<td><input type="hidden" id="_mapfield" name="_mapfield" value= <?php $combined="$_streetaddress x $_zip"; ?>></td> <!-- returned nothing -->
I would show you the results from the post submit processing iterations but, as I've mentioned before, all of those attempts have not delivered the 2 fields to the custom field on WordPress.

I am desperate. Anyone who has ANY recommendations about how to do this that works will earn my gratitude for life.

Re: combining 2 input fields to make a 3rd

Posted: Wed Aug 10, 2011 1:49 am
by Dodon
<td><input type="hidden" id="_mapfield" name="_mapfield" value="<?php echo $_streetaddress.''.$_zip;?>"></td>

That one should work, what are the values of $_streetaddress and $_zip? if they're empty then you get the results you got above.
echo the values of $_streetaddress and $_zip to see what they contain, most likely they don't contain any values.

Btw, do you want a user to fill in the form and then combine streetadress + zip, or do you have the information and want to pass that to the Google map plugin?

Re: combining 2 input fields to make a 3rd

Posted: Wed Aug 10, 2011 2:16 am
by marjwyatt
Thanks for your quick reply. I do suspect that the fields are empty because the post has not been submitted yet, which leaves me to the alternative of populating the map variable field on the other side, where I am sure that there is content because errors are properly returned when I specifically leave those fields empty on the form.

After submitting this inquiry to the forum, I went back to the submit form and added $_POST['_field1'] . $_POST['field2'] and that didn't retrieve the data from the previously entered fields either.

Since this is wordpress, I am constructing an array of essential data after the error checking is done. Custom fields are part of post_content so my options for gathering up the separate fields there are a little mind boggling, expecially at this point after hours of head-banging. :)

Rather than trying to isolate the pieces of code from the post submission script, I am including it in its entirety:

Code: Select all

<?php
require_once(ABSPATH . "wp-content" . '/recaptcha-php-1.11/recaptchalib.php');

set_time_limit(0);
if (isset($_POST['action']) && $_POST['action'] == 'post' && wp_verify_nonce($_POST['_wpnonce'],'new_post')) {
    $cat = array('14');  // assign post to Outrage Events category
    $err = "";
    $successurl     = home_url('/thank-you/');
    $current_user   = wp_set_current_user( '3', 'Guest' );
    $post_title 	= $_POST['post_title'];
    $post_content 	= $_POST['post_content'];
    $post_tags 		= $_POST['post_tags'];
    $eventDate      = $_POST['_ct_text_4e3318cbab83d'];
    $eventTime      = $_POST['_ct_text_4e3318eb1dcfb'];
    $venueName      = $_POST['_ct_text_4e33193f0534b'];
    $venueAddress   = $_POST['_ct_text_4e3319808b191'];
    $venueCity      = $_POST['_ct_text_4e3319a842272'];
    $venueState     = $_POST['_ct_selectbox_4e33203191562'];
    $venueZip       = $_POST['_ct_text_4e33216358869'];
    $eventCost      = $_POST['_ct_text_4e3321dad4b02'];
    $eventPic1      = $_FILES['image001'];
    $RealLifeName   = $_POST['_ct_text_4e332285061bb'];
    $EventRole      = $_POST['_ct_text_4e3322b1ab13d'];
    $SubmitEmail    = $_POST['_ct_text_4e3322dc62a6e'];
    /*$_ct_text_4e40d58483b14 = $_POST['_ct_text_4e40d58483b14'];*/

    if ($err == "") {
        $privatekey = "6LfNTsYSAAAAAGYtbj60FlpYSYBJggLNTHrJHXSz";
        $resp = recaptcha_check_answer ($privatekey,
        $_SERVER["REMOTE_ADDR"],
        $_POST["recaptcha_challenge_field"],
        $_POST["recaptcha_response_field"]);
        if (!$resp->is_valid) {
            die ("The reCAPTCHA wasn't entered correctly.
            Go back and try it again." .
            "(reCAPTCHA said: " . $resp->error . ")");
        }
        else {
    	if ($post_title == "") {
    		$err .= __('Oops!  We need an Event Name!') . "<br />";
    	}
    	if ($post_content == "") {
    		$err .= __('Please complete Event Details') . "<br />";
    	}
        if ($eventDate == "") {
            $err .= __('Oops!  What is the date of your event?') . "<br />";
        }
        if ($eventTime == "") {
            $err .= __('Oops!  What time does the event start?') . "<br />";
        }
        if ($venueName == "") {
            $err .= __('We can\'t get there without a Venue name!') . "<br />";
        }
        if ($venueAddress == "") {
            $err .= __('We can\'t get there if we don\'t know the address!') . "<br />";
        }
        if ($venueCity == "") {
            $err .= __('Oops!  What city is the event in?') . "<br />";
        }
        if ($venueState == "") {
            $err .= __('Well ... knowing the state would help too.') . "<br />";
        }
        if ($venueZip == "") {
            $err .= __('Oops!  You forgot to enter the zip code.') . "<br />";
        }
        if ($eventCost == "") {
            $err .= __('Oops!  We need to know how much the event costs.') . "<br />";
        }
        if ($eventPic1 == "") {
            $err .= __('Oops!  At least one picture, please.') . "<br />";
        }
        if ($RealLifeName == "My real life name is...") {
            $err .= __('Oops!  We can\'t publish your event without knowing your name.') . "<br />";
        }
        if ($EventRole == "And I am...") {
            $err .= __('Oops!  We need to know your role.') . "<br />";
        }
        if ($SubmitEmail == "My email") {
            $err .= __('Oops!  We need to know your email address.') . "<br />";
        }
    	if ( $err == "" ) {
    	        /*$_ct_text_4e40d58483b14 = array ($venueAddress+$venueZip);*/
                /*$_ct_text_4e40d58483b14 = '$venueAddress' . '$venueZip';*/
                /*$ct_text_4e40d58483b14 = $_POST ['_ct_text_4e3319808b191'.'_ct_text_4e33216358869'];*/
                /*$combined = $_POST['textfield_1'] . $_POST['textfield_2'] . $_POST['radio_button']; example code */
                /*$ct_text_4e40d58483b14 = $_POST['_ct_text_4e3319808b191'] . $_POST['_ct_text_4e33216358869'];*/
                /*$_ct_text_4e40d58483b14 = ($venueAddress . $venueZip);*/
                $new_post = array(
    			'post_author'	=> $user_id,
    			'post_title'	=> $post_title,
    			'post_content'	=> $post_content,
                'post_category'	=> $cat,
    			'post_status'	=> 'draft',
    			'tags_input'	=> $post_tags,
    		);
        // save the post
        $post_id = wp_insert_post( $new_post);
        if ($_FILES) {
            foreach ($_FILES as $file => $array) {
                $newupload = insert_attachment($file,$post_id);
                // $newupload returns the attachment id of the file that
                // was just uploaded. Do whatever you want with that now.
                }
            }
        wp_redirect( $successurl );
        exit;
	}
}}}
I prettied up the custom field names for my previous post but you will see some rather convoluted variable names here that begin with _ct. I've also left in "remarked out" failed attempts.

As for your question about the plugin, it was the only Google Maps plugin that I found which worked with Custom Fields. If you are asking whether I can populate the data with text in quotes, I cannot. The user MUST fill in the address fields as the site requisitioner did not supply a list of venues.

I am still desperate. Anything that you have to offer that would make this work would be most appreciated.

I'm even willing to discuss compensation for your time AFTER I am paid on delivery for this effort. I'm available on Skype and willing to stay up late if you want to contact me there. My handle is marj (dot) wyatt.

Re: combining 2 input fields to make a 3rd

Posted: Wed Aug 10, 2011 2:17 am
by marjwyatt
Thanks for your quick reply. I do suspect that the fields are empty because the post has not been submitted yet, which leaves me to the alternative of populating the map variable field on the other side, where I am sure that there is content because errors are properly returned when I specifically leave those fields empty on the form.

After submitting this inquiry to the forum, I went back to the submit form and added $_POST['_field1'] . $_POST['field2'] and that didn't retrieve the data from the previously entered fields either.

Since this is wordpress, I am constructing an array of essential data after the error checking is done. Custom fields are part of post_content so my options for gathering up the separate fields there are a little mind boggling, expecially at this point after hours of head-banging. :)

Rather than trying to isolate the pieces of code from the post submission script, I am including it in its entirety:

Code: Select all

<?php
require_once(ABSPATH . "wp-content" . '/recaptcha-php-1.11/recaptchalib.php');

set_time_limit(0);
if (isset($_POST['action']) && $_POST['action'] == 'post' && wp_verify_nonce($_POST['_wpnonce'],'new_post')) {
    $cat = array('14');  // assign post to Outrage Events category
    $err = "";
    $successurl     = home_url('/thank-you/');
    $current_user   = wp_set_current_user( '3', 'Guest' );
    $post_title 	= $_POST['post_title'];
    $post_content 	= $_POST['post_content'];
    $post_tags 		= $_POST['post_tags'];
    $eventDate      = $_POST['_ct_text_4e3318cbab83d'];
    $eventTime      = $_POST['_ct_text_4e3318eb1dcfb'];
    $venueName      = $_POST['_ct_text_4e33193f0534b'];
    $venueAddress   = $_POST['_ct_text_4e3319808b191'];
    $venueCity      = $_POST['_ct_text_4e3319a842272'];
    $venueState     = $_POST['_ct_selectbox_4e33203191562'];
    $venueZip       = $_POST['_ct_text_4e33216358869'];
    $eventCost      = $_POST['_ct_text_4e3321dad4b02'];
    $eventPic1      = $_FILES['image001'];
    $RealLifeName   = $_POST['_ct_text_4e332285061bb'];
    $EventRole      = $_POST['_ct_text_4e3322b1ab13d'];
    $SubmitEmail    = $_POST['_ct_text_4e3322dc62a6e'];
    /*$_ct_text_4e40d58483b14 = $_POST['_ct_text_4e40d58483b14'];*/

    if ($err == "") {
        $privatekey = "6LfNTsYSAAAAAGYtbj60FlpYSYBJggLNTHrJHXSz";
        $resp = recaptcha_check_answer ($privatekey,
        $_SERVER["REMOTE_ADDR"],
        $_POST["recaptcha_challenge_field"],
        $_POST["recaptcha_response_field"]);
        if (!$resp->is_valid) {
            die ("The reCAPTCHA wasn't entered correctly.
            Go back and try it again." .
            "(reCAPTCHA said: " . $resp->error . ")");
        }
        else {
    	if ($post_title == "") {
    		$err .= __('Oops!  We need an Event Name!') . "<br />";
    	}
    	if ($post_content == "") {
    		$err .= __('Please complete Event Details') . "<br />";
    	}
        if ($eventDate == "") {
            $err .= __('Oops!  What is the date of your event?') . "<br />";
        }
        if ($eventTime == "") {
            $err .= __('Oops!  What time does the event start?') . "<br />";
        }
        if ($venueName == "") {
            $err .= __('We can\'t get there without a Venue name!') . "<br />";
        }
        if ($venueAddress == "") {
            $err .= __('We can\'t get there if we don\'t know the address!') . "<br />";
        }
        if ($venueCity == "") {
            $err .= __('Oops!  What city is the event in?') . "<br />";
        }
        if ($venueState == "") {
            $err .= __('Well ... knowing the state would help too.') . "<br />";
        }
        if ($venueZip == "") {
            $err .= __('Oops!  You forgot to enter the zip code.') . "<br />";
        }
        if ($eventCost == "") {
            $err .= __('Oops!  We need to know how much the event costs.') . "<br />";
        }
        if ($eventPic1 == "") {
            $err .= __('Oops!  At least one picture, please.') . "<br />";
        }
        if ($RealLifeName == "My real life name is...") {
            $err .= __('Oops!  We can\'t publish your event without knowing your name.') . "<br />";
        }
        if ($EventRole == "And I am...") {
            $err .= __('Oops!  We need to know your role.') . "<br />";
        }
        if ($SubmitEmail == "My email") {
            $err .= __('Oops!  We need to know your email address.') . "<br />";
        }
    	if ( $err == "" ) {
    	        /*$_ct_text_4e40d58483b14 = array ($venueAddress+$venueZip);*/
                /*$_ct_text_4e40d58483b14 = '$venueAddress' . '$venueZip';*/
                /*$ct_text_4e40d58483b14 = $_POST ['_ct_text_4e3319808b191'.'_ct_text_4e33216358869'];*/
                /*$combined = $_POST['textfield_1'] . $_POST['textfield_2'] . $_POST['radio_button']; example code */
                /*$ct_text_4e40d58483b14 = $_POST['_ct_text_4e3319808b191'] . $_POST['_ct_text_4e33216358869'];*/
                /*$_ct_text_4e40d58483b14 = ($venueAddress . $venueZip);*/
                $new_post = array(
    			'post_author'	=> $user_id,
    			'post_title'	=> $post_title,
    			'post_content'	=> $post_content,
                'post_category'	=> $cat,
    			'post_status'	=> 'draft',
    			'tags_input'	=> $post_tags,
    		);
        // save the post
        $post_id = wp_insert_post( $new_post);
        if ($_FILES) {
            foreach ($_FILES as $file => $array) {
                $newupload = insert_attachment($file,$post_id);
                // $newupload returns the attachment id of the file that
                // was just uploaded. Do whatever you want with that now.
                }
            }
        wp_redirect( $successurl );
        exit;
	}
}}}
I prettied up the custom field names for my previous post but you will see some rather convoluted variable names here that begin with _ct. I've also left in "remarked out" failed attempts.

As for your question about the plugin, it was the only Google Maps plugin that I found which worked with Custom Fields. If you are asking whether I can populate the data with text in quotes, I cannot. The user MUST fill in the address fields as the site requisitioner did not supply a list of venues.

I am still desperate. Anything that you have to offer that would make this work would be most appreciated.

I'm even willing to discuss compensation for your time AFTER I am paid on delivery for this effort. I'm available on Skype and willing to stay up late if you want to contact me there. My handle is marj (dot) wyatt.

Re: combining 2 input fields to make a 3rd

Posted: Wed Aug 10, 2011 4:00 am
by Dodon
I never worked with Wordpress but I reckon you need to do something like this:

Code: Select all

                $venueAdressZip = $venueAddress . $venueZip;
                $new_post = array(
                         'post_author'   => $user_id,
                         'post_title'    => $post_title,
                         'post_content'  => $post_content,
                         'post_category' => $cat,
                         'post_status'   => 'draft',
                         'tags_input'    => $post_tags,
                         'venueAdressZip' => $venueAdressZip,
                 );
 
on the next page you can probably use the venueAdressZip for the Google Map thingy

Re: combining 2 input fields to make a 3rd

Posted: Wed Aug 10, 2011 12:17 pm
by marjwyatt
Thanks for the snippet but it did not work. Any other ideas?