Jump to content
tipthenoob

"Custom Form" - Form to Email Error

Recommended Posts

Hello!

 

I am currently trying my best to customize a form component to add fields so i can gather more data from users.

I have no experience coding; and the only time i needed something similar to a script is when i needed some CSS code injected to remove some module from an existing theme.

 

I have been able to add fields by duplicating the forms and tweaking the ids and its appearing on the front end (see form example 1.png below). unfortunately, during all test submission, i would either 1) receive the forms without my added fields (see form example 2.png below) or 2) encounter a '500' error. 

 

I basically duplicated a form field by copying and editing this line on the inquiry form file:

<p class="form-row" id="rqa_message_row">

To this

<p class="form-row" id="rqa_message_row2">


   then in a futile attempt i also replicated this line on the email form file:

<h2><?php _e( 'Customer message', 'yith-woocommerce-request-a-quote' ); ?></h2>
    <p><?php echo $raq_data['user_message'] ?></p>

To this

<h2><?php _e( 'Customer message', 'yith-woocommerce-request-a-quote' ); ?></h2>
    <p><?php echo $raq_data['$user_message2'] ?></p>

 

I know im missing something here; i googled it but i get information on how to create a similar system but not edit a exsiting one.  i have tried looking into other wordpress websites for insight but i can only see the details from their forms php, no their "email php".

 

I have attached the 2 scripts from the plug-in itself. 

 

Thank you very much for your assistance! and god speed! 

INQUIRY FORM PHP

<?php
/**
 * Form to Request a quote
 *
 * @package YITH Woocommerce Request A Quote
 * @since   1.0.0
 * @version 1.0.0
 * @author  Yithemes
 */
$current_user = array();
if ( is_user_logged_in() ) {
    $current_user = get_user_by( 'id', get_current_user_id() );
}

$user_name = ( ! empty( $current_user ) ) ?  $current_user->display_name : '';
$user_email = ( ! empty( $current_user ) ) ?  $current_user->user_email : '';
?>
<div class="yith-ywraq-mail-form-wrapper">
    <h3><?php _e( 'Send the request', 'yith-woocommerce-request-a-quote' ) ?></h3>

    <form id="yith-ywraq-mail-form" name="yith-ywraq-mail-form" action="<?php echo esc_url( YITH_Request_Quote()->get_raq_page_url() ) ?>" method="post">

            <p class="form-row form-row-wide validate-required" id="rqa_name_row">
                <label for="rqa-name" class=""><?php _e( 'Name', 'yith-woocommerce-request-a-quote' ) ?>
                    <abbr class="required" title="required">*</abbr></label>
                <input type="text" class="input-text " name="rqa_name" id="rqa-name" placeholder="" value="<?php echo $user_name ?>" required>
            </p>

            <p class="form-row form-row-wide validate-required" id="rqa_email_row">
                <label for="rqa-email" class=""><?php _e( 'Email', 'yith-woocommerce-request-a-quote' ) ?>
                    <abbr class="required" title="required">*</abbr></label>
                <input type="email" class="input-text " name="rqa_email" id="rqa-email" placeholder="" value="<?php echo $user_email ?>" required>
            </p>

        <p class="form-row" id="rqa_message_row">
            <label for="rqa-message" class=""><?php _e( 'Message', 'yith-woocommerce-request-a-quote' ) ?></label>
            <textarea name="rqa_message" class="input-text " id="rqa-message" placeholder="<?php _e( 'Notes on your request...', 'yith-woocommerce-request-a-quote' ) ?>" rows="5" cols="5"></textarea>
        </p>

        <p class="form-row" id="rqa_message_row2">
            <label for="rqa-message2" class=""><?php _e( 'Message2', 'yith-woocommerce-request-a-quote' ) ?></label>
            <textarea name="rqa_message2" class="input-text " id="rqa-message2" placeholder="<?php _e( 'Notes on your request...', 'yith-woocommerce-request-a-quote' ) ?>" rows="5" cols="5"></textarea>
        </p>/
		
        
        <?php if( 'yes' == get_option('ywraq_add_privacy_checkbox', 'no') ): ?>
            <div class="ywraq-privacy-wrapper">
                <p class="form-row"
                   id="rqa_privacy_description_row"><?php echo ywraq_replace_policy_page_link_placeholders( get_option( 'ywraq_privacy_description' ) ) ?></p>
                <p class="form-row" id="rqa_privacy_row">
                    <input type="checkbox" name="rqa_privacy" id="rqa_privacy" required>
                    <label for="rqa_privacy"
                           class=""><?php echo ywraq_replace_policy_page_link_placeholders(get_option('ywraq_privacy_label') ) ?>
                        <abbr class="required" title="required">*</abbr></label>

                </p>
            </div>
        <?php endif ?>

        <p class="form-row">
            <input type="hidden" id="raq-mail-wpnonce" name="raq_mail_wpnonce" value="<?php echo wp_create_nonce( 'send-request-quote' ) ?>">
            <input class="button raq-send-request" type="submit" value="<?php _e( 'Send Your Request', 'yith-woocommerce-request-a-quote' ) ?>">
        </p>

    </form>
</div>

 

 

 

EMAIL FORM  PHP

<?php
/**
 * HTML Template Email
 *
 * @package YITH Woocommerce Request A Quote
 * @since   1.0.0
 * @author  Yithemes
 */
?>

<?php do_action( 'woocommerce_email_header', $email_heading ); ?>

<p><?php printf( __( 'You received a quote request from %s. The request is the following:', 'yith-woocommerce-request-a-quote' ), $raq_data['user_name'] ); ?></p>

<?php do_action( 'yith_ywraq_email_before_raq_table', $raq_data ); ?>

<h2><?php _e('Request Quote', 'yith-woocommerce-request-a-quote') ?></h2>

<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
    <thead>
    <tr>
        <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Product', 'yith-woocommerce-request-a-quote' ); ?></th>
        <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Quantity', 'yith-woocommerce-request-a-quote' ); ?></th>
        <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Subtotal', 'yith-woocommerce-request-a-quote' ); ?></th>
    </tr>
    </thead>
    <tbody>
    <?php
    if( ! empty( $raq_data['raq_content'] ) ):
        foreach( $raq_data['raq_content'] as $item ):
            if( isset( $item['variation_id']) ){
                $_product = wc_get_product( $item['variation_id'] );
            }else{
                $_product = wc_get_product( $item['product_id'] );
            }
            ?>
            <tr>
                <td scope="col" style="text-align:left;"><a href="<?php echo get_edit_post_link( $_product->get_id() )?>"><?php echo $_product->get_title() ?></a>
                 <?php  if( isset($item['variations'])): ?><small><?php echo yith_ywraq_get_product_meta($item); ?></small><?php endif ?></td>
                <td scope="col" style="text-align:left;"><?php echo $item['quantity'] ?></td>
                <td scope="col" style="text-align:left;"><?php  echo WC()->cart->get_product_subtotal( $_product, $item['quantity'] ); ?></td>
            </tr>
        <?php
        endforeach;
    endif;
    ?>
    </tbody>
</table>

<?php do_action( 'yith_ywraq_email_after_raq_table', $raq_data ); ?>
<?php if( ! empty( $raq_data['user_message']) ): ?>
<h2><?php _e( 'Customer message', 'yith-woocommerce-request-a-quote' ); ?></h2>
    <p><?php echo $raq_data['user_message'] ?></p>

<h2><?php _e( 'Customer message', 'yith-woocommerce-request-a-quote' ); ?></h2>
    <p><?php echo $raq_data['$user_message2'] ?></p>


<?php endif ?>
<h2><?php _e( 'Customer details', 'yith-woocommerce-request-a-quote' ); ?></h2>

<p><strong><?php _e( 'Name:', 'yith-woocommerce-request-a-quote' ); ?></strong> <?php echo $raq_data['user_name'] ?></p>
<p><strong><?php _e( 'Email:', 'yith-woocommerce-request-a-quote' ); ?></strong> <a href="mailto:<?php echo $raq_data['user_email']; ?>"><?php echo $raq_data['user_email']; ?></a></p>

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

form example 1.png

form example 2.png

Share this post


Link to post
Share on other sites

Just guessing. Try removing the dollar sign before "user_message2" here:

<p><?php echo $raq_data['$user_message2'] ?></p>

 

Share this post


Link to post
Share on other sites
20 hours ago, cyberRobot said:

Just guessing. Try removing the dollar sign before "user_message2" here:


<p><?php echo $raq_data['$user_message2'] ?></p>

 

Thank you very much for trying to help. unfortunately, i did what you told me and its still not working, :(

Share this post


Link to post
Share on other sites

What does this show?

echo '<pre>', print_r($raq_data, 1), '</pre>';

 

Share this post


Link to post
Share on other sites

Hi Barand!

 

Im not sure with what you mean by your question: "what does this show?"

so i just tried and inputed your code 

<?php echo '<pre>', print_r($raq_data, 1), '</pre>'; ?>

on  EMAIL FORM  PHP

this is what appeared on the email forwarded from the form:

 

Array
(
    [user_name] => primary01
    [user_email] => admin@jwjgifthouse.com
    [user_message] => test 1
    [raq_content] => Array
        (
            [2290a7385ed77cc5592dc2153229f082] => Array
                (
                    [product_id] => 1064
                    [quantity] => 1

I hope this helps! thank you very much guys!.

Share this post


Link to post
Share on other sites
Posted (edited)

It shows that

$raq_data['user_message2']

does not exist, so whatever is supposed to provide it, isn't.

Edited by Barand

Share this post


Link to post
Share on other sites

Looks like there's work happening in the background that's not being shown right now. The data entry form uses 'raq_*' for it's field names, but the email script uses 'user_*' for it's array indexes. Somewhere there's a function that takes the $_POST data, manipulates it, and returns an array using a different set of indexes. Follow the program flow until you find it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

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.