• <form id=”main-contact-form” class=”contact-form” name=”contact-form” method=”post” action=”<?php echo get_bloginfo(‘template_directory’);?>/php/submitform.php”>

    I’ve tried different method to execute the form action but I failed to make my form working. I don’t know what’s wrong. Is it my hosting (godaddy)? Conflict in wordpress coding? Hope you could help me with this. Thanks!

    Here’s my php code

    <?php
    if(isset($_POST['submit'])) {
    header('Content-type: application/json');
    $status = array(
    	'type'=>'success',
    	'message'=>'Thank you for contacting us. We will reply as early as possible.  '
    );
    
    $name = @trim(stripslashes($_POST['name']));
    $email = @trim(stripslashes($_POST['email']));
    $subject = @trim(stripslashes($_POST['subject']));
    $message = @trim(stripslashes($_POST['message'])); 
    
    $email_from = $email;
    $email_to = '[email protected]';//replace with your email
    
    $body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
    
    $success = mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
    
    echo json_encode($status);
    die;
    }
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • but I failed to make my form working.

    You didn’t say what you problem is.

    Is it a Javascript problem?
    Ajax problem?
    HTML problem?
    Email problem?

    You could just use plugins to do it for you.

    Thread Starter rubyannrsls

    (@rubyannrsls)

    My problem is executing the php in the form action=”” stated in my Topic title. Sorry for not stating the problem in my message.
    I think the problem is I am calling the php in the wrong way. I’ve searched for ways to do that but I couldn’t find answers. Isn’t it possible to just call the php in action as if it is in html?

    Something like:
    <form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="submitform.php">
    *where submitform.php is found in the same path of index.html

    Hope you could help me. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to execute form action in wordpress?’ is closed to new replies.