Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Creating a contact form>from old forum #1232

Open
freddytwonotes opened this issue Nov 25, 2017 · 4 comments
Open

Creating a contact form>from old forum #1232

freddytwonotes opened this issue Nov 25, 2017 · 4 comments

Comments

@freddytwonotes
Copy link

freddytwonotes commented Nov 25, 2017

Summary

Bringing this issue from the old forum link: https://forums.anchorcms.com/d/799-making-a-contact-form

From the old thread, I set this up but was having a logging problem. the anchor dir had to be chown'd from 12345:12345 to 12345:web. That problem is resolved.

the script is still not working.

Expected Behaviour

The "contact" form filled out and submitted. The script in: anchor/routes/site.php executes, sends the mail then returns to the form page.

Actual Behaviour

After submission an error is thrown:

No routes matched
The error has been logged in /anchor/errors.log
  
Uncaught Exception

No routes matched

Origin

system/router.php on line 148 

Trace
#0 /home/public/anchor/system/router.php(158): System\router->match()
#1 /home/public/anchor/system/start.php(46): System\router->dispatch()
#2 /home/public/anchor/index.php(35): require('/home/public/an...')
#3 {main}

The log file error:

{"date":"2017-11-24 16:18:22","message":"No routes matched","trace":[{"file":"\/home\/public\/anchor\/system\/router.php","line":158,"function":"match","class":"System\\router","type":"->","args":[]},{"file":"\/home\/public\/anchor\/system\/start.php","line":46,"function":"dispatch","class":"System\\router","type":"->","args":[]},{"file":"\/home\/public\/anchor\/index.php","line":35,"args":["\/home\/public\/anchor\/system\/start.php"],"function":"require"}],"line":148,"file":"\/home\/public\/anchor\/system\/router.php"}

The generated URL:

http://freddytwonotes.nfshost.com/anchor/index.php/myhome/myhome/contact

Context details (if applicable)

@CraigChilds94
Copy link
Member

@freddytwonotes Can you please show me the routes you've added? It looks like you've not got one for the submission :)

@freddytwonotes
Copy link
Author

freddytwonotes commented Nov 27, 2017

I had this script in the routes/sites.php file. I have since moved it to the themes/default/functions.php file (no change in the exception). Since this is custom for this theme it seemed more appropriate to put it there so now the routes folder is back to unchanged. Are there docs for Anchor conventions (just starting on this). Here is the script followed by the form. No change save the email return and minor formatting on the form.

/**
 * Contact page
 */
Route::post('contact', function() {

    $input = Input::get(array('contact-subject', 'contact-name', 'contact-email', 'contact-message'));

    // Validator check...
    $validator = new Validator($input);

    $validator->check('contact-subject')
        ->is_max(1, "Subject is required!");

    $validator->check('contact-name')
        ->is_max(2, "Name is required!");

    $validator->check('contact-email')
        ->is_email("Email is required!");

    $validator->check('contact-message')
        ->is_max(5, "Message is empty or too short!");

    if($errors = $validator->errors()) {
        Input::flash();
        Notify::error($errors);
        return Response::redirect('contact#error');
    }

    $me = "myemail@gmail.com"; // Your email address
    $subject = $input['contact-subject'];
    $message = $input['contact-message'];

    $header  = "From: " . $input['contact-email'] . " \r\n";
    $header .= "Reply-To: " . $input['contact-email'] . " \r\n";
    $header .= "Return-Path: " . $input['contact-email'] . "\r\n";
    $header .= "X-Mailer: PHP \r\n";

    if(mail($me, $subject, $message, $header)) {
        Notify::success("Email sent!");
        return Response::redirect(base_url, 'contact#sent');
    } else {
        Notify::error("Failed to send email!");
        return Response::redirect(base_url, 'contact#failed');
    }

});

here is the form:

<?php theme_include('header'); ?>

	<section class="content wrap">
			<h1><?php echo page_title(); ?></h1>

    <!-- Your page content -->
    <div><?php echo page_content(); ?></div>

    <!-- Notification message -->
    <div><?php echo Notify::read(); ?></div>
	<div>
    <!-- The contact form -->
			<form id="comment" class="commentform" method="post" action="<?php echo current_url(); ?>">
				<p class="name">
					<label for="name">Your name:</label>
					<input name="contact-name" id="name" type="text" placeholder="Your name" value="">
				</p>

				<p class="email">
					<label for="email">Your email address:</label>
					<input name="contact-email" id="email" type="email" placeholder="Your email (won’t be published)" value="">
				</p>

				<p class="textarea">
					<label for="text">Your message:</label>
					<textarea name="contact-message" id="text" placeholder="Your message"></textarea>
				</p>
				<input type="hidden" name="contact-subject" value="FTNcontact">
				<p class="submit">
					<button type="submit" >Send to Freddy</button>
				</p>
			</form>
	</div>
	</section>

<?php theme_include('footer'); ?>

@komputer-man
Copy link

Dont want to open a new issue to just ask this:
@CraigChilds94 do you still active develop anchorcms?

@CraigChilds94
Copy link
Member

@AEEH

Currently we're not developing the CMS, just popping in every now and then to make bugfixes and releases. We got pretty far with the 1.0 release, but there were a few things we needed to finish off and tidy up.

When I get some free time I tend to do a large amount, but things have been busy for me this year.

Is there anything you need help with?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants